搜书小组(404吧)-刘备小说版块 “绿文”标签过滤器

自动隐藏带[绿文]标签(而不是标题内容)的帖子

// ==UserScript==
// @name         搜书小组(404吧)-刘备小说版块 “绿文”标签过滤器
// @namespace    https://greasyfork.org/zh-CN/users/1441970-%E5%8D%97%E7%AB%B9
// @version      1.1
// @description  自动隐藏带[绿文]标签(而不是标题内容)的帖子
// @author       南竹
// @match        https://404ku.com/forum-*-*
// @match        https://404ku.com/forum-*-*.html
// @match        https://404ku.com/forum.php?mod=forumdisplay&fid=*
// @match        https://404zu.org/forum-*-*
// @match        https://404zu.org/forum-*-*.html
// @match        https://404zu.org/forum.php?mod=forumdisplay&fid=*
// @match        https://404zu.net/forum-*-*
// @match        https://404zu.net/forum-*-*.html
// @match        https://404zu.net/forum.php?mod=forumdisplay&fid=*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 核心过滤逻辑
    function filterGreenPosts() {
        // 遍历所有帖子行(根据实际结构调整选择器)
        document.querySelectorAll('tbody[id^="normalthread_"] tr').forEach(row => {
            // 定位到包含标签的 <em> 元素
            const tagElem = row.querySelector('th.common em');
            if (tagElem) {
                const tagText = tagElem.textContent.trim();
                // 判断是否包含"绿文"标签
                if (tagText.includes('[绿文]')) {
                    row.style.display = 'none'; // 隐藏整行
                }
            }
        });
    }

    // 动态加载监听(优化性能)
    const observer = new MutationObserver(mutations => {
        mutations.forEach(m => {
            if (m.addedNodes.length) {
                setTimeout(filterGreenPosts, 300); // 防抖处理
            }
        });
    });

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

    // 初始执行
    window.addEventListener('load', () => {
        setTimeout(filterGreenPosts, 1000); // 等待页面加载
    });
})();