跳到正文

科技·工程

洛谷内容净化器——为您的犇犇使用体验保驾护航!

WJRAK约 58 分钟
原文

这是 2026年2月19日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年2月19日
收录
2026年2月23日
更新
2026年11月14日
篇幅
约 58 分钟

版本

  1. v7当前
  2. v6
  3. v5
  4. v4
更早的 3 个版本
  1. v3
  2. v2
  3. v1

如今,洛谷犇犇惊现一群猫粮与南梁,让人观犇体验骤降且有同化趋势。

为预防此类现象,维护洛谷犇犇观看安全,本人使用DeepSeek编写了一个油猴脚本,专门预防此类现象。

脚本代码(更新请关注@ WJRAK’s Article)
JavaScript
// ==UserScript==
// @name         洛谷内容净化器
// @namespace    http://tampermonkey.net/
// @version      5.1
// @description  专门屏蔽洛谷一些让人不适的词汇(支持替换和删除)
// @author       WJRAK&DeepSeek
// @match        *://*/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @run-at       document-end
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // ========== 核心词库 ==========
    const CORE_REPLACE_WORDS = [
        '南梁', '蓝梁', '香香软软', '肉文', '小黄文','猫娘','猫粮'
    ];

    const CORE_DELETE_WORDS = [
        '喵'
    ];

    // ========== 字符映射表(用于生成所有可能的变体)==========

    // 1. 拼音映射(包括带数字的变体)
    const PINYIN_MAP = {
        '南': ['nan', 'na', 'nán', 'nàn', 'na2', 'na4'],
        '蓝': ['lan', 'la', 'lán', 'làn', 'la2', 'la4'],
        '梁': ['liang', 'lia', 'lía', 'liàng', 'lia2', 'lia4', 'lian'],
        '香': ['xiang', 'xia', 'xiāng', 'xiàng', 'xia1', 'xia4'],
        '软': ['ruan', 'rua', 'ruǎn', 'ruàn', 'rua3', 'rua4'],
        '肉': ['rou', 'ro', 'ròu', 'ro4'],
        '文': ['wen', 'we', 'wén', 'wèn', 'we2', 'we4'],
        '小': ['xiao', 'xia', 'xiǎo', 'xiào', 'xiao3', 'xia3'],
        '黄': ['huang', 'hua', 'huáng', 'huàng', 'hua2', 'hua4'],
        '喵': ['miao', 'mia', 'miāo', 'miào', 'miao1', 'miao4'],
        '猫': ['mao', 'ma', 'māo', 'mào', 'mao1', 'mao4'],
        '娘': ['niang', 'nia', 'niáng', 'niàng', 'nia2', 'nia4'],
        '粮': ['liang', 'lia', 'liáng', 'liàng', 'lia2', 'lia4']
    };

    // 2. 数字替换字母 (Leet)
    const LEET_MAP = {
        'a': '[a4@]',
        'b': '[b8]',
        'c': '[c(]',
        'e': '[e3]',
        'g': '[g9]',
        'i': '[i1!]',
        'l': '[l1|]',
        'o': '[o0]',
        's': '[s5$]',
        't': '[t7]',
        'z': '[z2]',
        'n': '[n]',
        'm': '[m]'
    };

    // 3. 同音字映射
    const HOMOPHONE_MAP = {
        '南': '[南男难喃楠]',
        '蓝': '[蓝篮兰拦栏]',
        '梁': '[梁粮凉粱量]',
        '香': '[香湘乡箱镶]',
        '软': '[软阮蠕]',
        '肉': '[肉褥]',
        '文': '[文纹闻蚊]',
        '小': '[小晓筱]',
        '黄': '[黄皇煌簧]',
        '喵': '[喵]',
        '猫': '[猫锚]',
        '娘': '[娘酿]',
        '粮': '[粮凉梁粱量]'
    };

    // 4. 形近字映射
    const SIMILAR_MAP = {
        '南': '[南茼]',
        '蓝': '[蓝监]',
        '梁': '[梁染]',
        '香': '[杳杏]',
        '喵': '[喵]',
        '猫': '[猫]',
        '娘': '[娘]',
        '粮': '[粮]'
    };

    // ========== 存储键名 ==========
    const STORAGE_REPLACE_WORDS = 'shield_replace_words';
    const STORAGE_DELETE_WORDS = 'shield_delete_words';
    const STORAGE_SETTINGS = 'shield_settings';

    // ========== 默认设置 ==========
    const DEFAULT_SETTINGS = {
        modePinyin: true,           // 拼音匹配
        modeLeet: true,             // 数字替换匹配
        modeHomophone: true,        // 同音字匹配
        modeSimilar: true,          // 形近字匹配
        modeFuzzy: true,            // 模糊匹配(中间插字符)
        modeSplit: true,            // 拆分匹配(如"南 梁")
        maxFuzzyDistance: 3,        // 模糊距离
        logToConsole: false         // 输出日志
    };

    // ========== 初始化 ==========
    function initStorage() {
        if (GM_getValue(STORAGE_REPLACE_WORDS, null) === null) {
            GM_setValue(STORAGE_REPLACE_WORDS, CORE_REPLACE_WORDS);
        }
        if (GM_getValue(STORAGE_DELETE_WORDS, null) === null) {
            GM_setValue(STORAGE_DELETE_WORDS, CORE_DELETE_WORDS);
        }
        if (GM_getValue(STORAGE_SETTINGS, null) === null) {
            GM_setValue(STORAGE_SETTINGS, DEFAULT_SETTINGS);
        }
    }
    initStorage();

    // ========== 获取数据 ==========
    function getReplaceWords() {
        return GM_getValue(STORAGE_REPLACE_WORDS, []);
    }
    function getDeleteWords() {
        return GM_getValue(STORAGE_DELETE_WORDS, []);
    }
    function getSettings() {
        return GM_getValue(STORAGE_SETTINGS, DEFAULT_SETTINGS);
    }

    // ========== 更新 ==========
    function updateAll(newReplaceWords, newDeleteWords, newSettings) {
        GM_setValue(STORAGE_REPLACE_WORDS, newReplaceWords);
        GM_setValue(STORAGE_DELETE_WORDS, newDeleteWords);
        GM_setValue(STORAGE_SETTINGS, newSettings);
        processDocument();
    }

    // ========== 转义正则 ==========
    function escapeRegExp(string) {
        return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    }

    // ========== 生成拼音变体 ==========
    function generatePinyinVariants(word) {
        let variants = [];

        for (let i = 0; i < word.length; i++) {
            const char = word[i];
            const pinyins = PINYIN_MAP[char] || [char];

            if (variants.length === 0) {
                variants = [...pinyins];
            } else {
                const newVariants = [];
                variants.forEach(v => {
                    pinyins.forEach(p => {
                        newVariants.push(v + p);
                    });
                });
                variants = newVariants;
            }
        }

        return variants;
    }

    // ========== 生成Leet模式 ==========
    function createLeetPattern(text) {
        let pattern = '';
        for (let char of text.toLowerCase()) {
            if (LEET_MAP[char]) {
                pattern += LEET_MAP[char];
            } else {
                pattern += char;
            }
        }
        return pattern;
    }

    // ========== 生成单个词的所有模式 ==========
    function generatePatternsForWord(word, settings) {
        const patterns = new Set();

        // 1. 原词
        patterns.add(escapeRegExp(word));

        // 2. 拆分匹配
        if (settings.modeSplit) {
            patterns.add(word.split('').join('\\s*'));
        }

        // 3. 模糊匹配
        if (settings.modeFuzzy) {
            const chars = word.split('');
            patterns.add(chars.join(`[^<>]{0,${settings.maxFuzzyDistance}}`));
        }

        // 4. 同音字匹配
        if (settings.modeHomophone) {
            let homoPattern = '';
            for (let char of word) {
                if (HOMOPHONE_MAP[char]) {
                    homoPattern += HOMOPHONE_MAP[char];
                } else {
                    homoPattern += char;
                }
            }
            patterns.add(homoPattern);
        }

        // 5. 形近字匹配
        if (settings.modeSimilar) {
            let similarPattern = '';
            for (let char of word) {
                if (SIMILAR_MAP[char]) {
                    similarPattern += SIMILAR_MAP[char];
                } else {
                    similarPattern += char;
                }
            }
            patterns.add(similarPattern);
        }

        // 6. 拼音变体
        if (settings.modePinyin || settings.modeLeet) {
            const pinyinVariants = generatePinyinVariants(word);
            pinyinVariants.forEach(py => {
                patterns.add(py);

                if (settings.modeLeet) {
                    patterns.add(createLeetPattern(py));
                }

                if (settings.modeSplit) {
                    patterns.add(py.split('').join('\\s*'));
                }

                if (settings.modeFuzzy) {
                    const chars = py.split('');
                    patterns.add(chars.join(`[^<>]{0,${settings.maxFuzzyDistance}}`));
                }
            });
        }

        return Array.from(patterns);
    }

    // ========== 构建正则 ==========
    function buildPatterns(settings) {
        const replaceWords = getReplaceWords();
        const deleteWords = getDeleteWords();

        let replacePatterns = [];
        let deletePatterns = [];

        // 生成替换词模式
        replaceWords.forEach(word => {
            const patterns = generatePatternsForWord(word, settings);
            replacePatterns = replacePatterns.concat(patterns);
        });

        // 生成删除词模式
        deleteWords.forEach(word => {
            const patterns = generatePatternsForWord(word, settings);
            deletePatterns = deletePatterns.concat(patterns);
        });

        // 去重排序
        replacePatterns = [...new Set(replacePatterns)].sort((a, b) => b.length - a.length);
        deletePatterns = [...new Set(deletePatterns)].sort((a, b) => b.length - a.length);

        return {
            replacePattern: replacePatterns.length > 0 ? new RegExp(replacePatterns.join('|'), 'gi') : null,
            deletePattern: deletePatterns.length > 0 ? new RegExp(deletePatterns.join('|'), 'gi') : null
        };
    }

    // ========== 测试函数 ==========
    function testMatching() {
        const settings = getSettings();
        const { replacePattern, deletePattern } = buildPatterns(settings);

        const testCases = [
            // 替换词测试
            '南梁', '南[梁', '南-梁', '南 梁', 'nanliang', 'na4nliang', '男梁',
            '蓝梁', '香香软软', '香 香 软 软', 'xiangxiangruanruan',
            '肉文', 'rouwen', 'ro4we2',
            '小黄文', 'xiaohuangwen', 'xiao2huang2wen2',
            // 删除词测试
            '喵', '喵喵', 'miaomiao', 'miao', 'mi4o', '喵喵喵', '猫'
        ];

        console.log('【测试】替换模式:', replacePattern);
        console.log('【测试】删除模式:', deletePattern);
        console.log('【测试】匹配结果:');

        testCases.forEach(test => {
            let result = '❌';
            if (replacePattern) {
                replacePattern.lastIndex = 0;
                if (replacePattern.test(test)) result = '✅ 替换';
            }
            if (deletePattern && result === '❌') {
                deletePattern.lastIndex = 0;
                if (deletePattern.test(test)) result = '✅ 删除';
            }
            console.log(`  "${test}" → ${result}`);
        });
    }

    // ========== 核心处理函数 ==========
    function processDocument() {
        const settings = getSettings();
        const { replacePattern, deletePattern } = buildPatterns(settings);

        if (!replacePattern && !deletePattern) return;

        if (settings.logToConsole) {
            console.log('【内容净化器】启动');
        }

        function walk(node) {
            if (node.nodeType === Node.TEXT_NODE) {
                if (!node.nodeValue.trim()) return;

                let text = node.nodeValue;
                let originalText = text;

                // 先执行删除(优先级高)
                if (deletePattern) {
                    text = text.replace(deletePattern, (match) => {
                        if (settings.logToConsole) {
                            console.log('【删除】', match);
                        }
                        return '';
                    });
                }

                // 再执行替换
                if (replacePattern) {
                    text = text.replace(replacePattern, (match) => {
                        if (settings.logToConsole) {
                            console.log('【替换】', match, '→ (已屏蔽)');
                        }
                        return '(已屏蔽)';
                    });
                }

                if (text !== originalText) {
                    node.nodeValue = text;
                }
            }
            else if (node.nodeType === Node.ELEMENT_NODE) {
                if (/^(script|style|textarea|input)$/i.test(node.tagName)) {
                    return;
                }
                for (let child of node.childNodes) {
                    walk(child);
                }
            }
        }

        if (document.body) {
            walk(document.body);
        }
    }

    // ========== 监听动态内容 ==========
    function observeMutations() {
        const observer = new MutationObserver((mutations) => {
            if (observer.timeout) clearTimeout(observer.timeout);
            observer.timeout = setTimeout(processDocument, 300);
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
            characterData: true
        });
    }

    // ========== 创建设置面板 ==========
    function createSettingsPanel() {
        if (document.getElementById('gm-settings-panel')) return;

        let currentReplaceWords = getReplaceWords();
        let currentDeleteWords = getDeleteWords();
        let currentSettings = getSettings();

        // 创建遮罩层
        const overlay = document.createElement('div');
        overlay.id = 'gm-settings-overlay';
        overlay.style.cssText = `
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
            z-index: 999998;
            display: none;
            justify-content: center;
            align-items: center;
        `;

        // 创建面板
        const panel = document.createElement('div');
        panel.id = 'gm-settings-panel';
        panel.style.cssText = `
            background: white;
            width: 650px;
            max-width: 90%;
            max-height: 85vh;
            border-radius: 12px;
            box-shadow: 0 10px 40px rgba(0,0,0,0.3);
            padding: 24px;
            font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
            color: #333;
            overflow-y: auto;
            position: relative;
        `;

        // ========== 标题 ==========
        const title = document.createElement('h2');
        title.textContent = '🛡️ 洛谷内容净化器';
        title.style.cssText = `
            margin: 0 0 16px 0;
            font-size: 1.5rem;
            border-bottom: 2px solid #eaeef2;
            padding-bottom: 8px;
        `;
        panel.appendChild(title);

        // ========== 说明文字 ==========
        const desc = document.createElement('p');
        desc.innerHTML = '替换词:南梁、蓝梁、香香软软、肉文、小黄文 → (已屏蔽)<br>删除词:喵 → 直接消失';
        desc.style.cssText = `
            font-size: 0.95rem;
            color: #666;
            margin-bottom: 20px;
            padding: 12px;
            background: #f0f3f5;
            border-radius: 8px;
            border-left: 4px solid #c44536;
        `;
        panel.appendChild(desc);

        // ========== 匹配模式设置 ==========
        const modeContainer = document.createElement('div');
        modeContainer.style.cssText = `
            background: #f8f9fa;
            border-radius: 10px;
            padding: 18px;
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
        `;

        const modeTitle = document.createElement('div');
        modeTitle.innerHTML = '🔍 <strong>匹配模式</strong>';
        modeTitle.style.cssText = `
            margin-bottom: 16px;
            font-size: 1.1rem;
        `;
        modeContainer.appendChild(modeTitle);

        // 模式列表
        const modes = [
            { id: 'modePinyin', label: '拼音匹配', desc: 'nanliang → 南梁', color: '#2c3e50' },
            { id: 'modeLeet', label: '数字替换', desc: 'na4nliang → 南梁', color: '#c44536' },
            { id: 'modeHomophone', label: '同音字', desc: '男梁 → 南梁', color: '#27ae60' },
            { id: 'modeSimilar', label: '形近字', desc: '蓝监 → 蓝梁', color: '#f39c12' },
            { id: 'modeFuzzy', label: '模糊匹配', desc: '南[梁 → 南梁', color: '#8e44ad' },
            { id: 'modeSplit', label: '拆分匹配', desc: '南 梁 → 南梁', color: '#16a085' }
        ];

        const modeGrid = document.createElement('div');
        modeGrid.style.cssText = `
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 12px;
            margin-bottom: 15px;
        `;

        modes.forEach(mode => {
            const card = document.createElement('div');
            card.style.cssText = `
                background: white;
                border-radius: 8px;
                padding: 12px;
                border: 1px solid #e0e0e0;
            `;

            const row = document.createElement('div');
            row.style.cssText = `display: flex; align-items: flex-start; gap: 10px;`;

            const checkbox = document.createElement('input');
            checkbox.type = 'checkbox';
            checkbox.id = `mode-${mode.id}`;
            checkbox.checked = currentSettings[mode.id];
            checkbox.style.cssText = `
                width: 18px;
                height: 18px;
                margin-top: 2px;
                cursor: pointer;
                accent-color: ${mode.color};
            `;

            const labelDiv = document.createElement('div');
            labelDiv.style.flex = '1';

            const label = document.createElement('label');
            label.htmlFor = `mode-${mode.id}`;
            label.innerHTML = `<strong style="color:${mode.color}">${mode.label}</strong>`;
            label.style.cssText = `display: block; cursor: pointer; font-size: 1rem; margin-bottom: 4px;`;

            const descSmall = document.createElement('small');
            descSmall.textContent = mode.desc;
            descSmall.style.cssText = `color: #666; font-size: 0.8rem; display: block;`;

            labelDiv.appendChild(label);
            labelDiv.appendChild(descSmall);

            row.appendChild(checkbox);
            row.appendChild(labelDiv);
            card.appendChild(row);
            modeGrid.appendChild(card);
        });

        modeContainer.appendChild(modeGrid);

        // 模糊距离设置
        const distanceRow = document.createElement('div');
        distanceRow.style.cssText = `
            margin-top: 15px;
            padding: 15px;
            background: white;
            border-radius: 8px;
            border: 1px solid #e0e0e0;
        `;

        const sliderContainer = document.createElement('div');
        sliderContainer.style.cssText = `display: flex; align-items: center; gap: 15px;`;

        const distanceLabel = document.createElement('label');
        distanceLabel.htmlFor = 'fuzzy-distance';
        distanceLabel.textContent = '模糊距离:';
        distanceLabel.style.minWidth = '60px';

        const distanceInput = document.createElement('input');
        distanceInput.type = 'range';
        distanceInput.id = 'fuzzy-distance';
        distanceInput.min = '1';
        distanceInput.max = '5';
        distanceInput.value = currentSettings.maxFuzzyDistance;
        distanceInput.style.cssText = `flex: 1; height: 6px;`;

        const distanceValue = document.createElement('span');
        distanceValue.id = 'fuzzy-distance-value';
        distanceValue.textContent = currentSettings.maxFuzzyDistance;
        distanceValue.style.cssText = `
            min-width: 30px;
            text-align: center;
            font-weight: bold;
            color: #c44536;
            background: #f0f0f0;
            padding: 4px 8px;
            border-radius: 4px;
        `;

        distanceInput.oninput = function() {
            distanceValue.textContent = this.value;
        };

        sliderContainer.appendChild(distanceLabel);
        sliderContainer.appendChild(distanceInput);
        sliderContainer.appendChild(distanceValue);
        distanceRow.appendChild(sliderContainer);
        modeContainer.appendChild(distanceRow);

        panel.appendChild(modeContainer);

        // ========== 日志选项 ==========
        const logContainer = document.createElement('div');
        logContainer.style.cssText = `
            background: #f8f9fa;
            border-radius: 10px;
            padding: 12px 18px;
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
            display: flex;
            align-items: center;
        `;

        const logCheckbox = document.createElement('input');
        logCheckbox.type = 'checkbox';
        logCheckbox.id = 'log-console';
        logCheckbox.checked = currentSettings.logToConsole;
        logCheckbox.style.cssText = `width: 18px; height: 18px; margin-right: 10px; cursor: pointer;`;

        const logLabel = document.createElement('label');
        logLabel.htmlFor = 'log-console';
        logLabel.innerHTML = '<strong>控制台日志</strong> (在F12控制台显示屏蔽记录)';
        logLabel.style.cursor = 'pointer';

        logContainer.appendChild(logCheckbox);
        logContainer.appendChild(logLabel);
        panel.appendChild(logContainer);

        // ========== 替换词编辑 ==========
        const replaceContainer = document.createElement('div');
        replaceContainer.style.cssText = `
            background: #f8f9fa;
            border-radius: 10px;
            padding: 18px;
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
        `;

        const replaceTitle = document.createElement('div');
        replaceTitle.innerHTML = '<strong>🔴 替换词 (变为"已屏蔽")</strong>';
        replaceTitle.style.marginBottom = '10px';
        replaceContainer.appendChild(replaceTitle);

        const replaceTextarea = document.createElement('textarea');
        replaceTextarea.value = currentReplaceWords.join('\n');
        replaceTextarea.placeholder = '每行一个词';
        replaceTextarea.style.cssText = `
            width: 100%;
            box-sizing: border-box;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 6px;
            font-size: 0.95rem;
            min-height: 100px;
            resize: vertical;
            font-family: monospace;
        `;
        replaceContainer.appendChild(replaceTextarea);
        panel.appendChild(replaceContainer);

        // ========== 删除词编辑 ==========
        const deleteContainer = document.createElement('div');
        deleteContainer.style.cssText = `
            background: #f8f9fa;
            border-radius: 10px;
            padding: 18px;
            margin-bottom: 20px;
            border: 1px solid #e0e0e0;
        `;

        const deleteTitle = document.createElement('div');
        deleteTitle.innerHTML = '<strong>🗑️ 删除词 (直接消失)</strong>';
        deleteTitle.style.marginBottom = '10px';
        deleteContainer.appendChild(deleteTitle);

        const deleteTextarea = document.createElement('textarea');
        deleteTextarea.value = currentDeleteWords.join('\n');
        deleteTextarea.placeholder = '例如:喵';
        deleteTextarea.style.cssText = `
            width: 100%;
            box-sizing: border-box;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 6px;
            font-size: 0.95rem;
            min-height: 80px;
            resize: vertical;
            font-family: monospace;
        `;
        deleteContainer.appendChild(deleteTextarea);
        panel.appendChild(deleteContainer);

        // ========== 按钮区域 ==========
        const btnContainer = document.createElement('div');
        btnContainer.style.cssText = `
            display: flex;
            justify-content: flex-end;
            gap: 12px;
            margin-top: 10px;
            padding-top: 10px;
            border-top: 1px solid #e0e0e0;
        `;

        // 测试按钮
        const testBtn = document.createElement('button');
        testBtn.innerHTML = '🔍 测试';
        testBtn.style.cssText = `
            padding: 8px 16px;
            border: 1px solid #2c3e50;
            background: white;
            color: #2c3e50;
            border-radius: 6px;
            cursor: pointer;
        `;
        testBtn.onclick = () => {
            testMatching();
            alert('测试结果已输出到控制台');
        };

        // 取消按钮
        const cancelBtn = document.createElement('button');
        cancelBtn.innerHTML = '取消';
        cancelBtn.style.cssText = `
            padding: 8px 16px;
            border: 1px solid #ccc;
            background: white;
            border-radius: 6px;
            cursor: pointer;
        `;
        cancelBtn.onclick = () => {
            overlay.style.display = 'none';
        };

        // 保存按钮
        const saveBtn = document.createElement('button');
        saveBtn.innerHTML = '保存';
        saveBtn.style.cssText = `
            padding: 8px 16px;
            border: none;
            background: #2c3e50;
            color: white;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 500;
        `;
        saveBtn.onclick = () => {
            const newReplaceWords = replaceTextarea.value.split('\n')
                .map(l => l.trim())
                .filter(l => l);

            const newDeleteWords = deleteTextarea.value.split('\n')
                .map(l => l.trim())
                .filter(l => l);

            const newSettings = {
                modePinyin: document.getElementById('mode-modePinyin').checked,
                modeLeet: document.getElementById('mode-modeLeet').checked,
                modeHomophone: document.getElementById('mode-modeHomophone').checked,
                modeSimilar: document.getElementById('mode-modeSimilar').checked,
                modeFuzzy: document.getElementById('mode-modeFuzzy').checked,
                modeSplit: document.getElementById('mode-modeSplit').checked,
                maxFuzzyDistance: parseInt(document.getElementById('fuzzy-distance').value),
                logToConsole: document.getElementById('log-console').checked
            };

            updateAll(newReplaceWords, newDeleteWords, newSettings);
            overlay.style.display = 'none';
        };

        btnContainer.appendChild(testBtn);
        btnContainer.appendChild(cancelBtn);
        btnContainer.appendChild(saveBtn);
        panel.appendChild(btnContainer);

        // 关闭按钮
        const closeIcon = document.createElement('span');
        closeIcon.innerHTML = '✕';
        closeIcon.style.cssText = `
            position: absolute;
            top: 18px;
            right: 24px;
            font-size: 1.6rem;
            cursor: pointer;
            color: #999;
        `;
        closeIcon.onclick = () => {
            overlay.style.display = 'none';
        };
        panel.appendChild(closeIcon);

        overlay.appendChild(panel);
        document.body.appendChild(overlay);

        // 触发按钮
        let triggerBtn = document.getElementById('gm-settings-trigger');
        if (!triggerBtn) {
            triggerBtn = document.createElement('div');
            triggerBtn.id = 'gm-settings-trigger';
            triggerBtn.innerHTML = '🛡️';
            triggerBtn.style.cssText = `
                position: fixed;
                bottom: 20px;
                right: 20px;
                width: 52px;
                height: 52px;
                background: #c44536;
                color: white;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                font-size: 26px;
                cursor: pointer;
                box-shadow: 0 4px 15px rgba(0,0,0,0.3);
                z-index: 999999;
                opacity: 0.85;
                border: 2px solid white;
            `;

            triggerBtn.onclick = () => {
                const curReplace = getReplaceWords();
                const curDelete = getDeleteWords();
                const curSettings = getSettings();

                replaceTextarea.value = curReplace.join('\n');
                deleteTextarea.value = curDelete.join('\n');

                document.getElementById('mode-modePinyin').checked = curSettings.modePinyin;
                document.getElementById('mode-modeLeet').checked = curSettings.modeLeet;
                document.getElementById('mode-modeHomophone').checked = curSettings.modeHomophone;
                document.getElementById('mode-modeSimilar').checked = curSettings.modeSimilar;
                document.getElementById('mode-modeFuzzy').checked = curSettings.modeFuzzy;
                document.getElementById('mode-modeSplit').checked = curSettings.modeSplit;
                document.getElementById('fuzzy-distance').value = curSettings.maxFuzzyDistance;
                document.getElementById('fuzzy-distance-value').textContent = curSettings.maxFuzzyDistance;
                document.getElementById('log-console').checked = curSettings.logToConsole;

                overlay.style.display = 'flex';
            };

            document.body.appendChild(triggerBtn);
        }
    }

    // ========== 初始化 ==========
    function init() {
        processDocument();
        createSettingsPanel();
        observeMutations();
        console.log('【内容净化器】已启动');
    }

    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // ========== 菜单命令 ==========
    GM_registerMenuCommand('测试匹配', testMatching);
    GM_registerMenuCommand('打开设置', () => {
        document.getElementById('gm-settings-overlay').style.display = 'flex';
    });

})();
效果

原图1:
屏幕截图 2026-02-19 145030.png 效果1:
屏幕截图 2026-02-19 145158.png 原图2:
屏幕截图 2026-02-19 145312.png 效果2:
屏幕截图 2026-02-19 145325.png 原图3:
屏幕截图 2026-02-19 145553.png 效果3:
屏幕截图 2026-02-19 145541.png

注意

更新脚本时,请关闭插件,否则可能会引发失效等不应出现的错误