Greasy Fork

屏蔽 DBD-Raws

a simple script to block the display of DBD-Raws

当前为 2023-04-15 提交的版本,查看 最新版本

// ==UserScript==
// @name        屏蔽 DBD-Raws
// @namespace   anti-DBD-Raws
// @version     0.9
// @description a simple script to block the display of DBD-Raws
// @author      CropCircle
// @match       *
// @grant       none
// @run-at      document-idle
// @exclude     *google*
// @exclude     *bing*
// @exclude     *baidu*
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    // Define the keywords to filter and replace
    const keywords = [
        '黑暗路基艾尔',
        'DBD-Raws',
        'DBD分流Q群',
        'DBD',
        'https://afdian.net/@112127luji',
        '746546998',
        '560823326',
        '1158412873',
        'https://space.bilibili.com/97177229',
        'https://space.bilibili.com/476857955',
        '神圣之路基艾尔'
    ];
    const replacement = '██视力保护██';
    //const replacenum = '██视力保护██';
    // Loop through all the text nodes on the page
    function traverse(node) {
        let child, next;
        switch (node.nodeType) {
            case 1: // Element
            case 9: // Document
            case 11: // Document fragment
                child = node.firstChild;
                while (child) {
                    next = child.nextSibling;
                    traverse(child);
                    child = next;
                }
                break;
            case 3: // Text node
                if (keywords.some((keyword) => node.nodeValue.match(keyword))) {
                    node.nodeValue = node.nodeValue.replace(new RegExp(keywords.join('|'), 'g'), replacement);
                }
                break;
        }
    }
    traverse(document.body);
})();