标题
增加 1 行删除 1 行
1洛谷内容净化器——为您的犇犇使用体验保驾护航!1洛谷内容净化器——为您的洛谷使用体验保驾护航,不仅限于洛谷!
正文
增加 9 行删除 732 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744如今,洛谷犇犇惊现一群猫粮与南梁,让人观犇体验骤降且有同化趋势。为预防此类现象,维护洛谷犇犇观看安全,本人使用DeepSeek编写了一个油猴脚本,专门预防此类现象。::::info[脚本代码(更新请关注@ [WJRAK's Article](https://www.luogu.com.cn/user/1695884/article))]```javascript// ==UserScript==// @name 全站内容净化器(评论区毁灭版6.5)// @namespace http://tampermonkey.net/// @version 6.5// @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 BALANCE_WORDS = [// 南梁变体'南梁',// 香香软软变体'香香软软',// 猫娘变体'猫娘',// 猫粮变体'猫粮','男娘'];// 删除词库(直接消失,不替换为任何文字)const DELETE_WORDS = ['喵','喵!'];// 高级别词库(更强防护)- 包含更多中文变体和组合const HIGH_WORDS = [// 南梁变体'南梁',// 香香软软变体'香香软软',// 猫娘变体'猫娘',// 猫粮变体'猫粮','小蛋糕','蓝梁','腿照','春','男娘','/se'];// 高级删除词库const HIGH_DELETE_WORDS = ['喵','喵!'];// 排序后的词库(用于二分查找)let sortedBalanceWords = null;let sortedHighWords = null;let sortedDeleteWords = null;let sortedHighDeleteWords = null;// ========== 存储键名 ==========const STORAGE_LEVEL = 'shield_level'; // 'balance' 或 'high'const STORAGE_LOG = 'shield_log';// ========== 默认设置 ==========const DEFAULT_LEVEL = 'balance';const DEFAULT_LOG = false;// ========== 初始化存储 ==========function initStorage() {if (GM_getValue(STORAGE_LEVEL, null) === null) {GM_setValue(STORAGE_LEVEL, DEFAULT_LEVEL);}if (GM_getValue(STORAGE_LOG, null) === null) {GM_setValue(STORAGE_LOG, DEFAULT_LOG);}// 初始化排序词库if (!sortedBalanceWords) {sortedBalanceWords = [...BALANCE_WORDS].sort();}if (!sortedHighWords) {sortedHighWords = [...HIGH_WORDS].sort();}if (!sortedDeleteWords) {sortedDeleteWords = [...DELETE_WORDS].sort();}if (!sortedHighDeleteWords) {sortedHighDeleteWords = [...HIGH_DELETE_WORDS].sort();}}initStorage();// ========== 获取设置 ==========function getLevel() {return GM_getValue(STORAGE_LEVEL, DEFAULT_LEVEL);}function getLogEnabled() {return GM_getValue(STORAGE_LOG, DEFAULT_LOG);}// ========== 更新设置 ==========function updateSettings(newLevel, newLog) {GM_setValue(STORAGE_LEVEL, newLevel);GM_setValue(STORAGE_LOG, newLog);processDocument();}// ========== 二分查找 ==========function binarySearch(sortedArray, target) {let left = 0;let right = sortedArray.length - 1;while (left <= right) {const mid = Math.floor((left + right) / 2);const midVal = sortedArray[mid];if (midVal === target) {return true;}if (midVal < target) {left = mid + 1;} else {right = mid - 1;}}return false;}// ========== 提取中文词 ==========function extractChineseWords(text) {if (!text) return [];const words = new Set();// 1. 原文本words.add(text);// 2. 按中文标点分割const parts = text.split(/[,,。.!!??;;::"'""()\(\)\[\]【】\s\-_*~·]+/);parts.forEach(part => {if (part && /[\u4e00-\u9fa5]/.test(part)) {words.add(part);}});// 3. 提取连续中文字符const chineseChars = text.match(/[\u4e00-\u9fa5]+/g);if (chineseChars) {chineseChars.forEach(chunk => {words.add(chunk);// 2-4字词for (let i = 0; i < chunk.length; i++) {for (let j = i + 2; j <= i + 4 && j <= chunk.length; j++) {const sub = chunk.substring(i, j);if (sub.length >= 2) {words.add(sub);}}}});}// 4. 处理带分隔符的中文组合const separatorPattern = /([\u4e00-\u9fa5])[,,。.!!??;;::"'""()\(\)\[\]【】\s\-_*~·]+([\u4e00-\u9fa5])/g;let match;while ((match = separatorPattern.exec(text)) !== null) {words.add(match[1] + match[2]);}return Array.from(words).filter(w => w.length >= 2 && /[\u4e00-\u9fa5]/.test(w));}// ========== 检查文本是否包含屏蔽词 ==========function containsBlockedWord(text, level) {if (!text) return false;const wordList = level === 'high' ? sortedHighWords : sortedBalanceWords;if (!wordList) return false;const possibleWords = extractChineseWords(text);for (const word of possibleWords) {if (binarySearch(wordList, word)) {return true;}}return false;}// ========== 检查文本是否包含删除词 ==========function containsDeleteWord(text, level) {if (!text) return false;const wordList = level === 'high' ? sortedHighDeleteWords : sortedDeleteWords;if (!wordList) return false;const possibleWords = extractChineseWords(text);for (const word of possibleWords) {if (binarySearch(wordList, word)) {return true;}}return false;}// ========== 处理图片元素(高级模式专用)==========function processImageElement(img) {const level = getLevel();// 只在高级模式下破坏图片if (level !== 'high') return;// 检查图片的alt属性和周边文本const altText = img.alt || '';const titleText = img.title || '';if (!containsBlockedWord(altText, level) && !containsBlockedWord(titleText, level)) {return;}const logEnabled = getLogEnabled();// 创建新的div元素替换图片,显示【图片已屏蔽】const placeholder = document.createElement('div');placeholder.textContent = '【图片已屏蔽】';placeholder.style.cssText = `display: inline-block;padding: 8px 12px;background: #f0f0f0;color: #666;border: 1px solid #ddd;border-radius: 4px;font-size: 14px;min-width: 100px;text-align: center;`;// 如果有被屏蔽的文字,显示提示if (altText) {placeholder.setAttribute('title', `原图片描述: ${altText}`);}// 替换图片if (img.parentNode) {if (logEnabled) {console.log(`【破坏图片】alt:"${altText}" 原图:${img.src || '无'}`);}img.parentNode.replaceChild(placeholder, img);}}// ========== 处理链接元素(高级模式专用)==========function processLinkElement(link) {const level = getLevel();// 只在高级模式下破坏链接if (level !== 'high') return;// 检查链接文本是否包含屏蔽词const linkText = link.textContent || '';if (!containsBlockedWord(linkText, level)) return;const logEnabled = getLogEnabled();// 创建新的span元素替换链接,显示【已屏蔽】const span = document.createElement('span');span.textContent = '(已屏蔽)';span.style.cssText = `color: #999;cursor: default;text-decoration: none;background: none;font-style: italic;`;// 复制原有样式类(可选)if (link.className) {span.className = link.className;}// 替换链接if (link.parentNode) {if (logEnabled) {console.log(`【破坏链接】原文字:"${linkText}" URL:${link.href || '无'} → 已屏蔽`);}link.parentNode.replaceChild(span, link);}}// ========== 处理文本节点 ==========function processTextNode(node) {const level = getLevel();const logEnabled = getLogEnabled();// 先检查删除词(优先级高)if (containsDeleteWord(node.nodeValue, level)) {if (logEnabled) {console.log(`【删除】原文:${node.nodeValue.trim()}`);}node.nodeValue = '';return;}// 再检查屏蔽词if (!containsBlockedWord(node.nodeValue, level)) {return;}const wordList = level === 'high' ? sortedHighWords : sortedBalanceWords;const possibleWords = extractChineseWords(node.nodeValue);let matchedWord = '';for (const word of possibleWords) {if (binarySearch(wordList, word)) {matchedWord = word;break;}}if (logEnabled) {console.log(`【屏蔽】级别:${level === 'high' ? '高' : '平衡'} 词:${matchedWord} 原文:${node.nodeValue.trim()}`);}node.nodeValue = '(已屏蔽)';}// ========== 遍历DOM树(增强版)==========function walkDOM(node) {// 如果是元素节点if (node.nodeType === Node.ELEMENT_NODE) {const level = getLevel();// 高级模式下先处理链接和图片if (level === 'high') {// 处理链接(会替换整个元素,所以之后不用遍历子节点)if (node.tagName === 'A') {processLinkElement(node);return;}// 处理图片(会替换整个元素,所以之后不用遍历子节点)if (node.tagName === 'IMG') {processImageElement(node);return;}}// 跳过脚本、样式等标签if (/^(script|style|textarea|input)$/i.test(node.tagName)) {return;}// 继续遍历子节点for (let child of node.childNodes) {walkDOM(child);}}// 如果是文本节点,处理文本else if (node.nodeType === Node.TEXT_NODE) {if (node.nodeValue.trim()) {processTextNode(node);}}}// ========== 核心处理函数 ==========function processDocument() {if (!document.body) return;const level = getLevel();const logEnabled = getLogEnabled();if (logEnabled) {console.log(`【净化器】级别:${level === 'high' ? '高' : '平衡'} 词库大小:${level === 'high' ? sortedHighWords.length : sortedBalanceWords.length}`);if (level === 'high') {console.log('【净化器】高级模式:将破坏含屏蔽词的链接和图片');}}walkDOM(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 testMatching() {const level = getLevel();const wordList = level === 'high' ? sortedHighWords : sortedBalanceWords;const deleteList = level === 'high' ? sortedHighDeleteWords : sortedDeleteWords;const testCases = ['南梁', '南[梁', '南-梁', '南 梁', '男梁', '难梁','蓝梁', '篮梁', '兰梁','香香软软', '香 香 软 软', '湘湘软软','猫娘', '猫 娘', '猫-娘', '毛娘', '猫酿','猫粮', '猫 粮', '毛粮', '猫凉','男娘', '/se', '小蛋糕', '腿照', '春','喵', '喵!'];console.log(`【测试】当前级别: ${level === 'high' ? '高' : '平衡'}`);console.log('【测试】词库大小:', wordList.length + deleteList.length);console.log('【测试】匹配结果:');testCases.forEach(test => {let result = '❌ 不匹配';if (containsDeleteWord(test, level)) {result = '✅ 删除';} else if (containsBlockedWord(test, level)) {result = '✅ 屏蔽';}console.log(` "${test}" → ${result}`);});if (level === 'high') {console.log('【测试】高级模式下:');console.log(' - 包含上述词的链接 → 替换为"(已屏蔽)"');console.log(' - 包含上述词的图片 → 替换为"【图片已屏蔽】"');console.log(' - 包含"喵"/"喵!"的文本 → 直接消失');}}// ========== 创建设置面板 ==========function createSettingsPanel() {if (document.getElementById('gm-settings-panel')) return;const currentLevel = getLevel();const currentLog = getLogEnabled();// 创建遮罩层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: 450px;max-width: 90%;border-radius: 12px;box-shadow: 0 10px 40px rgba(0,0,0,0.3);padding: 24px;font-family: system-ui, -apple-system, sans-serif;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 = '选择防护级别,词库由开发者维护,用户无需手动添加';desc.style.cssText = `font-size: 0.9rem;color: #666;margin-bottom: 20px;padding: 10px;background: #f0f3f5;border-radius: 6px;`;panel.appendChild(desc);// 级别选择const levelLabel = document.createElement('div');levelLabel.style.marginBottom = '10px';levelLabel.style.fontWeight = 'bold';levelLabel.textContent = '防护级别:';panel.appendChild(levelLabel);const balanceDiv = document.createElement('div');balanceDiv.style.marginBottom = '8px';const balanceRadio = document.createElement('input');balanceRadio.type = 'radio';balanceRadio.id = 'level-balance';balanceRadio.name = 'shield-level';balanceRadio.value = 'balance';balanceRadio.checked = currentLevel === 'balance';balanceRadio.style.marginRight = '8px';const balanceLabel = document.createElement('label');balanceLabel.htmlFor = 'level-balance';balanceLabel.innerHTML = '<strong>平衡模式</strong> <span style="color:#666;font-size:0.85rem">(基础防护,"喵"直接消失)</span>';balanceDiv.appendChild(balanceRadio);balanceDiv.appendChild(balanceLabel);panel.appendChild(balanceDiv);const highDiv = document.createElement('div');highDiv.style.marginBottom = '20px';const highRadio = document.createElement('input');highRadio.type = 'radio';highRadio.id = 'level-high';highRadio.name = 'shield-level';highRadio.value = 'high';highRadio.checked = currentLevel === 'high';highRadio.style.marginRight = '8px';const highLabel = document.createElement('label');highLabel.htmlFor = 'level-high';highLabel.innerHTML = '<strong>高级模式</strong> <span style="color:#666;font-size:0.85rem">(破坏含屏蔽词的链接/图片,"喵"直接消失)</span>';highDiv.appendChild(highRadio);highDiv.appendChild(highLabel);panel.appendChild(highDiv);// 统计信息const statsDiv = document.createElement('div');statsDiv.style.cssText = `background: #f8f9fa;border-radius: 6px;padding: 12px;margin-bottom: 20px;font-size: 0.9rem;`;statsDiv.innerHTML = `<div>平衡词库: ${BALANCE_WORDS.length} 个屏蔽词 + ${DELETE_WORDS.length} 个删除词</div><div>高级词库: ${HIGH_WORDS.length} 个屏蔽词 + ${HIGH_DELETE_WORDS.length} 个删除词</div><div style="margin-top:8px;color:#c44536;">⚡ 高级模式会:</div><div style="margin-left:12px;color:#c44536;font-size:0.85rem;">• 链接 → 替换为"(已屏蔽)"</div><div style="margin-left:12px;color:#c44536;font-size:0.85rem;">• 图片 → 替换为"【图片已屏蔽】"</div><div style="margin-left:12px;color:#c44536;font-size:0.85rem;">• 删除词 → 直接消失</div>`;panel.appendChild(statsDiv);// 日志选项const logDiv = document.createElement('div');logDiv.style.marginBottom = '20px';const logCheckbox = document.createElement('input');logCheckbox.type = 'checkbox';logCheckbox.id = 'log-console';logCheckbox.checked = currentLog;logCheckbox.style.marginRight = '8px';const logLabel = document.createElement('label');logLabel.htmlFor = 'log-console';logLabel.innerHTML = '控制台输出屏蔽日志 (F12查看)';logDiv.appendChild(logCheckbox);logDiv.appendChild(logLabel);panel.appendChild(logDiv);// 按钮区域const btnDiv = document.createElement('div');btnDiv.style.cssText = `display: flex;justify-content: flex-end;gap: 10px;margin-top: 20px;`;const testBtn = document.createElement('button');testBtn.textContent = '测试匹配';testBtn.style.cssText = `padding: 8px 16px;border: 1px solid #2c3e50;background: white;color: #2c3e50;border-radius: 6px;cursor: pointer;`;testBtn.onclick = () => {testMatching();alert('测试结果已输出到控制台 (F12查看)');};const cancelBtn = document.createElement('button');cancelBtn.textContent = '取消';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.textContent = '保存';saveBtn.style.cssText = `padding: 8px 16px;border: none;background: #2c3e50;color: white;border-radius: 6px;cursor: pointer;font-weight: 500;`;saveBtn.onclick = () => {const newLevel = document.querySelector('input[name="shield-level"]:checked').value;const newLog = document.getElementById('log-console').checked;updateSettings(newLevel, newLog);overlay.style.display = 'none';};btnDiv.appendChild(testBtn);btnDiv.appendChild(cancelBtn);btnDiv.appendChild(saveBtn);panel.appendChild(btnDiv);// 关闭按钮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: 48px;height: 48px;background: #c44536;color: white;border-radius: 50%;display: flex;align-items: center;justify-content: center;font-size: 24px;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 = () => {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';});})();```::::::::info[效果(已过时,实际上你南梁链接都进不去)]{open}原图1:效果1:原图2:效果2:原图3:效果3:::::::::warning[注意]1. 更新脚本时,请**关闭插件**,否则可能会引发失效等**不应出现**的错误2. 可能会出现误杀等情况,可联系@[WJRAK](https://www.luogu.com.cn/user/1695884)以解决3. 与[洛谷驱猫助手](https://www.luogu.com.cn/article/ora3c5va)同时使用体验更佳。::::123456789101112131415161718192021**由AI辅助完成**如今,洛谷犇犇惊现一群猫粮与南梁,让人观犇体验骤降且有同化趋势。为保(kan)证(qi)犇(lai)犇(bu)观(e)感(xin),本人特意编写了这个脚本以解决相关问题。::::info[脚本代码][最新版](https://www.luogu.me/paste/nz6vxc03)::::::::warning[注意]{open}1. 更新脚本时,请**关闭插件**,否则可能会引发失效等**不应出现**的错误2. 可能会出现误杀等情况,可联系@[WJRAK](https://www.luogu.com.cn/user/1695884)以解决3. 与[洛谷驱猫助手](https://www.luogu.com.cn/article/ora3c5va)同时使用体验更佳。4. 开启高级模式体验更佳!5. 本脚本全浏览器通用哦!::::