【中羽在线】新闻过滤

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

// ==UserScript==
// @name         【中羽在线】新闻过滤
// @namespace   https://github.com/realSilasYang
// @version         2025-7-27
// @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
// ==/UserScript==

(function () {
    'use strict';

    // 过滤一条 news_list
    function filterSingle(box) {
        const pjImg = box.querySelector('img.news_pj');
        if (!pjImg) return;

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

        const commentNum = parseInt(nextNode.nodeValue.trim(), 10);
        if (isNaN(commentNum) || commentNum < 20) {
            box.style.display = 'none';
        }
    }

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

    // 先处理当前已有
    filterAll();

    // 监听后续新增
    const observer = new MutationObserver(mutations => {
        mutations.forEach(m => {
            m.addedNodes.forEach(node => {
                if (node.nodeType !== 1) return;          // 只处理元素节点
                if (node.classList && node.classList.contains('news_list')) {
                    filterSingle(node);                   // 直接就是一条
                } else {
                    filterAll(node);                      // 可能是容器,递归过滤
                }
            });
        });
    });

    // 监听整个 body 的子孙节点
    observer.observe(document.body, { childList: true, subtree: true });
})();