移除B站热搜框

zh-cn

当前为 2021-08-22 提交的版本,查看 最新版本

// ==UserScript==
// @name         移除B站热搜框
// @namespace    http://tampermonkey.net/
// @version      0.1
// @match        *://www.bilibili.com/
// @match        *://*.bilibili.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @description  zh-cn
// ==/UserScript==

(function () {
    let app = document.getElementById("app");
    if (app == null){
        return
    }
    //设置监听dom改变类型
    let config = {
        //子节点
        "childList":true,
        //后代节点
        "subtree":true
    };

    let mutationObserver = new MutationObserver(function (records,mutationObserver){
        records.forEach(function (record) {
            for (let i = 0;i<record.addedNodes.length;i++){
                let node = record.addedNodes[i];
                //判断是否是HTML节点
                if (node.nodeType == 1) {
                    //找到热搜所在的节点
                    if (node.getAttribute("class") == "trending") {
                        //设为隐藏
                        node.style.display = "none"
                        mutationObserver.takeRecords();
                    }
                }
            }
        });
    });
    //监听dom节点变化
    mutationObserver.observe(app,config);

})();