Greasy Fork

Greasy Fork is available in English.

B站新版首页去除推广栏和游戏广告

去除新版B站首页的推广栏

当前为 2021-11-28 提交的版本,查看 最新版本

// ==UserScript==
// @name         B站新版首页去除推广栏和游戏广告
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  去除新版B站首页的推广栏
// @author       Yesionio
// @include        /https:\/\/www.bilibili.com\/\??/
// @icon         https://www.google.com/s2/favicons?domain=bilibili.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let a = window.onload;
    window.onload = (e)=> {
        if (a instanceof Function) {
            a(e);
        }
        document.querySelector('.eva-extension-area').remove();
        //document.querySelector('section.bili-grid:nth-child(3)').remove();
        document.querySelector('.eva-banner').remove();
    };

    const blockAD = (mutationsList, observer) => {
        for (const mutation of mutationsList) {
            for (const target of mutation.addedNodes) {
                if (target.nodeType != 1) return
                if (target.className === 'eva-banner') {
                    target.hidden = true;
                }
                if (target.className === 'eva-extension-area') {
                    target.hidden = true;
                }
                let tnod = document.querySelector('.eva-extension-area');
                let unod = document.querySelector('.eva-banner');
                if (!!tnod && !tnod.hidden) {
                    tnod.hidden = true;
                }
                if (!!unod && !unod.hidden) {
                    tnod.hidden = true;
                }
            }
        }
    };
    const observer = new MutationObserver(blockAD);
    observer.observe(document, { childList: true, subtree: true })
})();