linux.do屏蔽指定版块帖子

屏蔽linux.do论坛中指定版块的帖子,支持多个版块的自定义配置

目前为 2024-08-13 提交的版本。查看 最新版本

// ==UserScript==
// @name         linux.do屏蔽指定版块帖子
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  屏蔽linux.do论坛中指定版块的帖子,支持多个版块的自定义配置
// @author       linux.do
// @match        https://linux.do/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_registerMenuCommand
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 默认屏蔽的版块列表
    let blockedCategories = GM_getValue('blockedCategories', ['搞七捻三', '病友']);

    // 添加配置菜单选项
    GM_registerMenuCommand('配置屏蔽的版块', configureBlockedCategories);

    // 配置屏蔽的版块
    function configureBlockedCategories() {
        const categories = prompt('请输入要屏蔽的版块名称,用逗号分隔:', blockedCategories.join(', '));
        if (categories !== null) {
            blockedCategories = categories.split(',').map(category => category.trim());
            GM_setValue('blockedCategories', blockedCategories);
            alert('屏蔽的版块已更新。请刷新页面以应用更改。');
        }
    }

    // 如果没有设置任何版块,则不执行屏蔽操作
    if (!blockedCategories.length) return;

    // 查找所有帖子
    const posts = document.querySelectorAll('td.topic-list-data');

    // 遍历所有帖子,检查是否属于被屏蔽的版块
    posts.forEach(post => {
        const categoryElement = post.querySelector('div.link-bottom-line a.badge-category__wrapper span.badge-category__name');
        if (categoryElement && blockedCategories.includes(categoryElement.textContent.trim())) {
            // 如果帖子属于被屏蔽的版块,则隐藏整个帖子项
            post.closest('tr').style.display = 'none';
        }
    });

    // 监听新帖子的加载(适用于动态加载内容的页面)
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1 && node.matches('tr')) {
                    const categoryElement = node.querySelector('div.link-bottom-line a.badge-category__wrapper span.badge-category__name');
                    if (categoryElement && blockedCategories.includes(categoryElement.textContent.trim())) {
                        node.style.display = 'none';
                    }
                }
            });
        });
    });

    // 监控整个帖子列表的变化
    const topicList = document.querySelector('table.topic-list');
    if (topicList) {
        observer.observe(topicList, { childList: true, subtree: true });
    }

})();

QingJ © 2025

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