吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1345|回复: 16
收起左侧

[其他原创] IT之家资讯过滤油猴(篡改猴、暴力猴、脚本猫)脚本,按标题内容过滤,祝五一节日快乐

  [复制链接]
0772boy 发表于 2026-5-1 16:35
本帖最后由 0772boy 于 2026-5-1 16:41 编辑

前两天节前上班摸鱼,浏览IT之家被铺天盖地的财报恶心到了,遂有此脚本,直接上代码:

食用方法:根据需求修改自定义屏蔽词即可。

[JavaScript] 纯文本查看 复制代码
// ==UserScript==
// @name         IT之家资讯屏蔽器
// @namespace    [url]http://tampermonkey.net/[/url]
// @version      1.2
// @description  IT之家资讯过滤
// @author       0772Boy
// @match        [url]https://it.ithome.com/[/url]
// @match        [url]https://ithome.com/[/url]
// @match        [url]https://www.ithome.com/[/url]
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // ====================== 【自定义屏蔽词】 ======================
    const blockRules = [
        /20[0-9]{2}Q[1-4]/i,             // 匹配 2000~2099年 + Q1~Q4
        /营业收入|营收|净利润|亏损|同比/i,
        /亿新台币|亿元|万亿韩元|亿美元/i,
        /财年第一财季|财季净利润/i
    ];

    // 屏蔽目标 class
    const targetClass = 'title';

    function isBlockedTitle(title) {
        if (!title) return false;
        return blockRules.some(rule => rule.test(title));
    }

    function blockNews() {
        const titleElements = document.querySelectorAll(`.${targetClass}`);

        titleElements.forEach(element => {
            const titleText = element.textContent.trim();
            if (isBlockedTitle(titleText)) {
                let newsCard = element.closest('li, div.article, div.item');
                if (newsCard) {
                    newsCard.style.display = 'none';
                    newsCard.style.height = '0';
                    newsCard.style.margin = '0';
                    newsCard.style.padding = '0';
                }
            }
        });
    }

    function listenMoreButton() {
        const checkButton = setInterval(() => {
            const moreButton = document.querySelector('a.more');
            if (moreButton) {
                clearInterval(checkButton);
                moreButton.addEventListener('click', () => {
                    // 延迟 666ms 确保新内容加载完成再过滤
                    setTimeout(blockNews, 666);
                });
            }
        }, 300);
    }

    window.addEventListener('load', () => {
        setTimeout(blockNews, 500);
        listenMoreButton();
    });

    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (mutation.addedNodes.length) {
                blockNews();
            }
        });
    });

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

})();


免费评分

参与人数 2吾爱币 +8 热心值 +2 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
b98 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 0772boy 发表于 2026-5-1 16:49
本帖最后由 0772boy 于 2026-5-1 16:50 编辑

0011.png

这里的超链接标记我怎么编辑帖子都没法去掉,各位复制代码的时候请自行去掉{:301_999:}
GoingUp 发表于 2026-5-1 16:43
Z564493690 发表于 2026-5-1 17:09
地球守护者 发表于 2026-5-1 17:15

就是屏蔽IT之家毫无关系网页元素
地球守护者 发表于 2026-5-1 17:16

软媒魔方网站
zhaojiehu123 发表于 2026-5-1 17:59
感谢分享,为无私分享的老哥点赞
kingbackgo 发表于 2026-5-1 19:05
这个挺有用的
TimePhrase 发表于 2026-5-1 19:22
没用过,国内网站都比较流氓
ZsirQAQ 发表于 2026-5-1 20:22
这个好用感谢分享
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-5-20 02:32

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

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