全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

IP归属甄别会员请立即修改密码
查看: 520|回复: 8
打印 上一主题 下一主题

发一个aff清理大师脚本,支持屏蔽所有aff帖子及过滤aff链接

[复制链接]
跳转到指定楼层
1#
发表于 4 天前 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 Planck 于 2024-6-25 16:39 编辑

rt,支持隐藏帖子列表包含特定关键词的帖子(仅支持hostloc,默认屏蔽“瓦工”关键词)

支持过滤页面里面所有的aff链接,逻辑为将所有aff链接的id设置为0,支持帖子内部aff和签名的aff链接,支持不限于hostloc的所有网页

食用方法:安装tampermonkey,新建脚本,复制下方代码并保存即可。可自由修改需屏蔽的关键词。

  1. // ==UserScript==
  2. // @name         AFF清理大师
  3. // @namespace    http://tampermonkey.net/
  4. // @version      1.0
  5. // @description  屏蔽包含指定关键词的网页元素,并在控制台输出删除的帖子标题和URL,修改aff参数
  6. // @author       You
  7. // @match        *://*/*
  8. // @grant        none
  9. // ==/UserScript==

  10. (function() {
  11.     'use strict';

  12.     // 指定需要屏蔽的关键词
  13.     const keywords = ["瓦工", "关键词2", "关键词3"];


  14.     function containsKeyword(text) {
  15.         return keywords.some(keyword => text.includes(keyword));
  16.     }

  17.     function removeMatchingElements() {
  18.         // 查找所有包含帖子内容的 <tbody> 元素
  19.         const threads = document.querySelectorAll('tbody[id^="normalthread_"]');

  20.         threads.forEach(thread => {
  21.             const titleElement = thread.querySelector('a.s.xst');
  22.             if (titleElement && containsKeyword(titleElement.textContent)) {
  23.                 console.log(`【删除的帖子】 ${titleElement.textContent}\n【URL】${titleElement.href}`);
  24.                 // console.log(`帖子URL: ${titleElement.href}`);
  25.                 thread.remove();
  26.             }
  27.         });
  28.     }

  29.     function modifyAffParameters() {
  30.         // 查找所有包含链接的 <a> 元素
  31.         const links = document.querySelectorAll('a[href*="?"]');

  32.         links.forEach(link => {
  33.             let url = new URL(link.href);
  34.             if (url.searchParams.has('aff')) {
  35.                 url.searchParams.set('aff', '0');
  36.                 link.href = url.toString();
  37.                 console.log(`修改后的URL: ${link.href}`);
  38.             }
  39.         });

  40.         // 查找所有包含纯文本URL的文本节点
  41.         const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
  42.         let node;
  43.         const urlRegex = /https?:\/\/[^\s]+/g;
  44.         while (node = walker.nextNode()) {
  45.             const matches = node.nodeValue.match(urlRegex);
  46.             if (matches) {
  47.                 matches.forEach(match => {
  48.                     try {
  49.                         let url = new URL(match);
  50.                         if (url.searchParams.has('aff')) {
  51.                             url.searchParams.set('aff', '0');
  52.                             const modifiedUrl = url.toString();
  53.                             node.nodeValue = node.nodeValue.replace(match, modifiedUrl);
  54.                             console.log(`修改后的文本URL: ${modifiedUrl}`);
  55.                         }
  56.                     } catch (e) {
  57.                         // Ignore invalid URLs
  58.                     }
  59.                 });
  60.             }
  61.         }
  62.     }

  63.     // 监听DOM变化并屏蔽包含关键词的元素
  64.     const observer = new MutationObserver(() => {
  65.         removeMatchingElements();
  66.         modifyAffParameters();
  67.     });
  68.     observer.observe(document.body, { childList: true, subtree: true });

  69.     // 初始调用以立即屏蔽当前页面中包含关键词的元素并修改aff参数
  70.     removeMatchingElements();
  71.     modifyAffParameters();
  72. })();
复制代码
3#
发表于 4 天前 | 只看该作者
可以,能否再发一个头像出处
4#
发表于 4 天前 | 只看该作者
从此丐帮何去何从
5#
发表于 4 天前 来自手机 | 只看该作者
不错,顶一个,试一试
6#
发表于 4 天前 | 只看该作者
感觉是gpt写的

小尾巴~~~~~
7#
发表于 4 天前 | 只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
9#
发表于 3 天前 | 只看该作者
让商家少赚的不行?这么反感aff?对自己又没影响
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2024-6-29 05:16 , Processed in 0.062378 second(s), 9 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表