anti-twitter-breadvirus

anti #breadvirus

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         anti-twitter-breadvirus
// @namespace    https://greasyfork.org/en/scripts/407479-anti-twitter-breadvirus
// @version      0.1.1
// @description  anti #breadvirus
// @author       YeXiaoRain
// @match        https://twitter.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const debounce = function(fn, timeout) {
        let timer;
        return function() {
            if (timer) {
                clearTimeout(timer);
            }
            timer = setTimeout(function(){
                fn(arguments);
            }, timeout);
        }
    }
    const dfs = (item,d = 10000) => {
        let anticount = 0;
        if(item.nodeType === 3){ // #Text
            const reg = /扩散性百万(?!甜)(.+)面包/;
            while(reg.test(item.textContent)){
                anticount ++;
                // 为了计数 没有使用 /g
                item.textContent = item.textContent.replace(reg,'$1');
            }
        }else if(d > 0){
            for (let i = 0; i < item.childNodes.length; i++) {
                anticount += dfs(item.childNodes[i],d-1);
            }
        }
        return anticount;
    }
    const work = debounce(()=>{
        console.log('Anti #breadvirus ',dfs(window.document.body));
    },1000);
    const observer = new MutationObserver(()=>{
        setTimeout(work,0);
    });
    const options = {
        childList: true,
        subtree: true
    } ;
    observer.observe(document.body,options);
})();