写了两个油猴脚本用于将特定颜色用作隐藏文本

分享 W65056037 • 查看227

这里用的是第二个颜色

相应的将五彩中预览的列表(暂时只支持文章视图)里也可以设置隐藏,但是这个要通过指定颜色代码处理。

效果如下


// ==UserScript==

// @name         高级 Marker.doTalk 内容高亮隐藏器

// @namespace    http://tampermonkey.net/

// @version      2.0

// @description  在 marker.dotalk.cn 网站上,根据左侧边框颜色隐藏指定的高亮笔记。支持多颜色、全局开关和单个颜色开关。

// @author       YourName

// @icon         https://wucaiimg.dotalk.cn/webfe202508/20250821195500/logo.png

// @match        https://marker.dotalk.cn/*

// @grant        GM_registerMenuCommand

// @grant        GM_getValue

// @grant        GM_setValue

// @grant        GM_notification

// ==/UserScript==

(function() {

    'use strict';

    // --- 配置键 ---

    const COLORS_LIST_KEY = 'hidden_highlight_colors_list_v2';

    const GLOBAL_ENABLE_KEY = 'hidden_highlight_global_enable_v2';

    // --- 默认数据 ---

    const DEFAULT_COLORS = [

        { color: 'rgb(112, 211, 130)', enabled: true } // 默认隐藏绿色

    ];

    // --- 状态变量 (从存储中加载) ---

    let colorList = GM_getValue(COLORS_LIST_KEY, DEFAULT_COLORS);

    let isGloballyEnabled = GM_getValue(GLOBAL_ENABLE_KEY, true);

    // --- 辅助函数:标准化颜色 ---

    function normalizeColor(colorStr) {

        if (!colorStr || typeof colorStr !== 'string') return '';

        const tempDiv = document.createElement('div');

        tempDiv.style.color = colorStr.trim();

        document.body.appendChild(tempDiv);

        const computedColor = window.getComputedStyle(tempDiv).color;

        document.body.removeChild(tempDiv);

        return computedColor;

    }

    // --- 核心处理函数 ---

    function processNode(containerNode) {

        if (containerNode.nodeType !== Node.ELEMENT_NODE) return;

        const highlights = containerNode.querySelectorAll('.highlight_core');

        const activeRules = isGloballyEnabled ? colorList.filter(rule => rule.enabled) : [];

        highlights.forEach(el => {

            const groupToProcess = el.closest('.note_highlight_group');

            if (!groupToProcess) return;

            if (!isGloballyEnabled) {

                groupToProcess.style.display = ''; // 如果全局禁用,确保所有项都可见

                return;

            }

            const currentColor = window.getComputedStyle(el).borderLeftColor;

            const shouldHide = activeRules.some(rule => rule.color === currentColor);

            groupToProcess.style.display = shouldHide ? 'none' : '';

        });

    }

    // --- 页面刷新函数 ---

    // 在设置更改后,重新应用所有规则

    function refreshPageVisibility() {

        console.log('[Hider] Refreshing page visibility...');

        // 1. 先将所有可能被隐藏的元素恢复显示

        document.querySelectorAll('.note_highlight_group').forEach(el => {

            el.style.display = '';

        });

        // 2. 重新应用隐藏逻辑

        processNode(document.body);

    }

    // --- MutationObserver 监控动态内容 ---

    const observer = new MutationObserver((mutationsList) => {

        if (!isGloballyEnabled) return;

        for (const mutation of mutationsList) {

            if (mutation.type === 'childList') {

                mutation.addedNodes.forEach(node => {

                    processNode(node);

                });

            }

        }

    });

    // --- 油猴菜单 ---

    function registerMenus() {

        // 1. 全局启用/禁用开关

        GM_registerMenuCommand(`${isGloballyEnabled ? '✅' : '❌'} 禁用/启用 隐藏功能`, () => {

            isGloballyEnabled = !isGloballyEnabled;

            GM_setValue(GLOBAL_ENABLE_KEY, isGloballyEnabled);

            GM_notification({

                text: `隐藏功能已 ${isGloballyEnabled ? '启用' : '禁用'}`,

                title: '设置更新',

                timeout: 2000

            });

            refreshPageVisibility();

            // 重新注册菜单以更新显示文本 (一个常见技巧)

            // 需要页面刷新才能看到菜单文本更新,但功能是即时的。

            // 或者通过更复杂的菜单管理库来动态更新。

        });

        // 2. 添加一个新的隐藏颜色

        GM_registerMenuCommand('➕ 添加要隐藏的颜色', () => {

            const newColorInput = prompt('请输入要添加的颜色 (例如: rgb(112, 211, 130), #70d382, green):');

            if (!newColorInput) return;

            const normalized = normalizeColor(newColorInput);

            if (!normalized) {

                alert('无效的颜色格式!');

                return;

            }

            if (colorList.some(rule => rule.color === normalized)) {

                alert('这个颜色已经存在于列表中了。');

                return;

            }

            colorList.push({ color: normalized, enabled: true });

            GM_setValue(COLORS_LIST_KEY, colorList);

            GM_notification({ text: `已添加颜色: ${normalized}`, title: '成功', timeout: 2000 });

            refreshPageVisibility();

        });

        // 3. 管理现有颜色 (启用/禁用/删除)

        GM_registerMenuCommand('⚙️ 管理隐藏颜色列表', () => {

            if (colorList.length === 0) {

                alert('当前没有已配置的隐藏颜色。请先添加一个。');

                return;

            }

            let menuText = '当前隐藏颜色列表:\n\n';

            colorList.forEach((rule, index) => {

                menuText += `${index + 1}: ${rule.enabled ? '✅' : '❌'} ${rule.color}\n`;

            });

            menuText += '\n请输入操作:\n- 数字 (如 "1") 来切换启用/禁用\n- "d" + 数字 (如 "d1") 来删除\n- 其他任意键取消';

            const choice = prompt(menuText);

            if (!choice) return;

            const choiceLower = choice.toLowerCase().trim();

            if (choiceLower.startsWith('d')) {

                // 删除操作

                const index = parseInt(choiceLower.substring(1), 10) - 1;

                if (!isNaN(index) && index >= 0 && index < colorList.length) {

                    const removed = colorList.splice(index, 1);

                    GM_setValue(COLORS_LIST_KEY, colorList);

                    GM_notification({ text: `已删除: ${removed[0].color}`, title: '成功', timeout: 2000 });

                    refreshPageVisibility();

                } else {

                    alert('无效的数字,无法删除。');

                }

            } else {

                // 切换操作

                const index = parseInt(choiceLower, 10) - 1;

                if (!isNaN(index) && index >= 0 && index < colorList.length) {

                    colorList[index].enabled = !colorList[index].enabled;

                    GM_setValue(COLORS_LIST_KEY, colorList);

                    GM_notification({

                        text: `${colorList[index].color} 已被 ${colorList[index].enabled ? '启用' : '禁用'}`,

                        title: '状态切换',

                        timeout: 2000

                    });

                    refreshPageVisibility();

                } else {

                     alert('无效的输入。');

                }

            }

        });

    }

    // --- 脚本启动 ---

    console.log(`[高级Hider] 脚本已启动。全局状态: ${isGloballyEnabled ? '启用' : '禁用'}.`);

    console.log('[高级Hider] 当前规则:', colorList);

    // 注册菜单

    registerMenus();

    // 立即处理页面上已有的内容

    processNode(document.body);

    // 开始监听DOM变化

    observer.observe(document.body, {

        childList: true,

        subtree: true

    });

})();

// ==UserScript==

// @name         五彩划线聚焦隐藏

// @namespace    http://tampermonkey.net/

// @version      0.1

// @icon         https://wucaiimg.dotalk.cn/webfe202508/20250821195500/logo.png

// @description  修改.wucaiclrx2元素的透明度样式

// @author       You

// @match        *://*/*

// @grant        none

// ==/UserScript==

(function() {

    'use strict';

    // 目标元素的类名

    const targetClass = 'wucaiclrx2';

    // 设置元素的样式

    function setElementStyles(element) {

        // 移除行内样式

        element.removeAttribute('style');

        // 设置默认透明度

        element.style.opacity = '0.12';

        element.style.transition = 'opacity 0.3s ease';

        // 添加鼠标悬停效果

        element.addEventListener('mouseenter', function() {

            this.style.opacity = '1';

        });

        element.addEventListener('mouseleave', function() {

            this.style.opacity = '0.12';

        });

    }

    // 使用MutationObserver监听DOM变化

    const observer = new MutationObserver(function(mutations) {

        mutations.forEach(function(mutation) {

            if (mutation.addedNodes) {

                mutation.addedNodes.forEach(function(node) {

                    if (node.nodeType === 1) { // 元素节点

                        // 检查当前节点是否匹配

                        if (node.classList && node.classList.contains(targetClass)) {

                            setElementStyles(node);

                        }

                        // 检查子节点

                        const elements = node.getElementsByClassName(targetClass);

                        for (let element of elements) {

                            setElementStyles(element);

                        }

                    }

                });

            }

        });

    });

    // 开始观察文档变化

    observer.observe(document.body, {

        childList: true,

        subtree: true

    });

    // 检查初始已存在的元素

    document.querySelectorAll('.' + targetClass).forEach(function(element) {

        setElementStyles(element);

    });

})();
共收到1条回复
写了两个油猴脚本用于将特定颜色用作隐藏文本 肥肥猫xyz
肥肥猫xyz ⚡⚡ #1 回复
👍, 感谢你的分享
登录后即可参与回复