feishu viewing

进入飞书文档时自动切换到阅读模式, Lark Viewing mode

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         feishu viewing
// @namespace    http://tampermonkey.net/
// @license MIT 
// @version      2.5
// @description  进入飞书文档时自动切换到阅读模式, Lark Viewing mode
// @author       You
// @match        *://*.feishu.cn/*
// @match        *://*.larkoffice.com/*
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    let hasSwitched = false;

    function switchToReadMode() {
        if (hasSwitched) return;

        try {
            const switchBtn = Array.from(document.querySelectorAll('[data-selector="docs-mode-switch"]'))
                .find(btn => btn.classList.contains('ud__button--filled'));

            if (!switchBtn) return;

            const text = switchBtn.querySelector('.content_text')?.innerText.trim();

            if (text === '阅读' || text === 'Viewing') {
                hasSwitched = true;
                return;
            }

            console.log('[Feishu View Mode] 点击模式按钮...');
            switchBtn.click();

            setTimeout(() => {
                const menuItems = [...document.querySelectorAll('li.docs_mode_switch_menu_item')];

                for (const item of menuItems) {
                    const labelSpan = item.querySelector('.item_text span');
                    const itemText = labelSpan?.innerText.trim();

                    if (labelSpan && (itemText === '阅读' || itemText === 'Viewing')) {
                        item.click();
                        hasSwitched = true;
                        return;
                    }
                }
            }, 1000);

        } catch (e) {
            console.warn('[Feishu View Mode] ', e);
        }
    }

    const interval = setInterval(() => {
        if (hasSwitched) {
            clearInterval(interval);
            return;
        }
        switchToReadMode();
    }, 500);

    setTimeout(() => {
        clearInterval(interval);
    }, 30000);
})();