隐藏百度搜索结果中 CSDN&百度经验&百度知道 的垃圾内容

try to take over the world!

// ==UserScript==
// @name         隐藏百度搜索结果中 CSDN&百度经验&百度知道 的垃圾内容
// @namespace    http://tampermonkey.net/
// @version      0.4.4
// @description  try to take over the world!
// @author       pozhu
// @include      http*://www.baidu.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    "use strict";

    // Your code here...
    function cleanTheResult() {
        var list = Array.from(document.getElementsByClassName("source_1Vdff")).map((item) => item.firstChild);
        var rex = /CSDN|csdn|百度知道|百度经验|mamicode|bubuko|codercto|javascriptcn|程序员软件开发技术分享社区|编程字典|编程圈|thinbug|voidcc|慕课网|码客|编程之家/;
        var num = 0;

        function findParent(item) {
            // console.log(item);
            if (item.classList.contains("c-container")) {
                item.style.display = "none";
                num++;
            } else {
                findParent(item.parentElement);
            }
        }
        list.map((item) => {
            if (rex.test(item.innerText)) {
                findParent(item);
            }
        });
        console.log("已屏蔽" + num + "条搜索结果");
    }

    document.addEventListener("click", () => {
        cleanTheResult();
    });

    window.addEventListener("DOMContentLoaded", function () {
        cleanTheResult();
    });
})();