Greasy Fork is available in English.

feishu viewing

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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);
})();