rt,支持隐藏帖子列表包含特定关键词的帖子(仅支持hostloc,默认屏蔽“瓦工”关键词) 支持过滤页面里面所有的aff链接,逻辑为将所有aff链接的id设置为0,支持帖子内部aff和签名的aff链接,支持不限于hostloc的所有网页 食用方法:安装tampermonkey,新建脚本,复制下方代码并保存即可。可自由修改需屏蔽的关键词。 // ==UserScript== // @name AFF清理大师 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 屏蔽包含指定关键词的网页元素,并在控制台输出删除的帖子标题和URL,修改aff参数 // @author You // @match *://*/* // @grant none // ==/UserScript== (function() { ‘use strict’; // 指定需要屏蔽的关键词 const keywords = [“瓦工”, “关键词2”, “关键词3”]; function containsKeyword(text) { return keywords.some(keyword => text.includes(keyword)); } function removeMatchingElements() { // 查找所有包含帖子内容的
元素 const threads = document.querySelectorAll(‘tbody[id^=”normalthread_”]’); threads.forEach(thread => { const titleElement = thread.querySelector(‘a.s.xst’); if (titleElement && containsKeyword(titleElement.textContent)) { console.log(`【删除的帖子】 ${titleElement.textContent}\n【URL】${titleElement.href}`); // console.log(`帖子URL: ${titleElement.href}`); thread.remove(); } }); } function modifyAffParameters() { // 查找所有包含链接的 元素 const links = document.querySelectorAll(‘a[href*=”?”]’); links.forEach(link => { let url = new URL(link.href); if (url.searchParams.has(‘aff’)) { url.searchParams.set(‘aff’, ‘0’); link.href = url.toString(); console.log(`修改后的URL: ${link.href}`); } }); // 查找所有包含纯文本URL的文本节点 const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false); let node; const urlRegex = /https?:\/\/[^\s]+/g; while (node = walker.nextNode()) { const matches = node.nodeValue.match(urlRegex); if (matches) { matches.forEach(match => { try { let url = new URL(match); if (url.searchParams.has(‘aff’)) { url.searchParams.set(‘aff’, ‘0’); const modifiedUrl = url.toString(); node.nodeValue = node.nodeValue.replace(match, modifiedUrl); console.log(`修改后的文本URL: ${modifiedUrl}`); } } catch (e) { // Ignore invalid URLs } }); } } } // 监听DOM变化并屏蔽包含关键词的元素 const observer = new MutationObserver(() => { removeMatchingElements(); modifyAffParameters(); }); observer.observe(document.body, { childList: true, subtree: true }); // 初始调用以立即屏蔽当前页面中包含关键词的元素并修改aff参数 removeMatchingElements(); modifyAffParameters(); })(); 复制代码
没有回复内容