【中羽在线】新闻过滤

过滤中羽在线7×24羽坛资讯中,评论数<20 或 无评论图标的新闻

当前为 2025-09-01 提交的版本,查看 最新版本

// ==UserScript==
// @name         【中羽在线】新闻过滤
// @namespace    https://github.com/realSilasYang
// @version      2025-9-01
// @description  过滤中羽在线7×24羽坛资讯中,评论数<20 或 无评论图标的新闻
// @author       阳熙来
// @match        https://www.badmintoncn.com/*
// @icon         https://is1-ssl.mzstatic.com/image/thumb/Purple211/v4/e0/30/96/e03096b4-6098-9b40-c3b8-4a974af132d8/AppIcon-0-0-1x_U007emarketing-0-5-0-0-sRGB-85-220.png/246x0w.webp
// @license      GNU GPLv3
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    // 判断是否符合条件
    function shouldKeep(box) {
        const pjImg = box.querySelector('img.news_pj');
        if (!pjImg) return false; // 没有评论图标直接丢掉

        const nextNode = pjImg.nextSibling;
        if (!nextNode || !nextNode.nodeValue) return false;

        const commentNum = parseInt(nextNode.nodeValue.trim(), 10);
        return !isNaN(commentNum) && commentNum >= 20;
    }

    // 检查并移除
    function filterSingle(box) {
        if (!shouldKeep(box)) {
            box.remove(); // 直接从 DOM 树里删掉
        }
    }

    // 批量处理
    function filterAll(root = document) {
        root.querySelectorAll('.news_list').forEach(filterSingle);
    }

    // 初始已有的也要过滤
    document.addEventListener('DOMContentLoaded', () => {
        filterAll();
    });

    // 监听后续新增
    const observer = new MutationObserver(mutations => {
        for (const m of mutations) {
            for (const node of m.addedNodes) {
                if (node.nodeType !== 1) continue; // 只处理元素节点
                if (node.classList && node.classList.contains('news_list')) {
                    filterSingle(node);
                } else {
                    filterAll(node);
                }
            }
        }
    });

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址