版本比较
洛谷内容净化器——为您的洛谷使用体验保驾护航,不仅限于洛谷!
标题
增加 1 行删除 1 行
11洛谷内容净化器——为您的犇犇使用体验保驾护航!洛谷内容净化器——为您的洛谷使用体验保驾护航,不仅限于洛谷!正文
增加 9 行删除 732 行
112335457891011121314151617181920672223892510112728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272312725726727728729730731732733734735736737738131474015161718192021如今,洛谷犇犇惊现一群猫粮与南梁,让人观犇体验骤降且有同化趋势。 **由AI辅助完成**
为预防此类现象,维护洛谷犇犇观看安全,本人使用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==为保(kan)证(qi)犇(lai)犇(bu)观(e)感(xin),本人特意编写了这个脚本以解决相关问题。
(function() { 'use strict';::::info[脚本代码]
// ========== 静态词库(开发者手动维护,专注中文变体)==========[最新版](https://www.luogu.me/paste/nz6vxc03)
// 平衡级别词库(基础防护)- 只保留常见中文变体 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[注意]::::warning[注意]{open}1. 更新脚本时,请**关闭插件**,否则可能会引发失效等**不应出现**的错误2. 可能会出现误杀等情况,可联系@[WJRAK](https://www.luogu.com.cn/user/1695884)以解决3. 与[洛谷驱猫助手](https://www.luogu.com.cn/article/ora3c5va)同时使用体验更佳。4. 开启高级模式体验更佳!5. 本脚本全浏览器通用哦!::::