去除b站首页推广

去除b站首页的推广,侧栏广告

目前为 2024-11-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         去除b站首页推广
// @version      1.1.1
// @namespace    https://github.com/odarkblade
// @description  去除b站首页的推广,侧栏广告
// @author       https://github.com/odarkblade
// @match        https://www.bilibili.com/
// @match        https://www.bilibili.com/?*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// @license MIT
// ==/UserScript==

function runCode() {
    try {
        const ads = [
            ...document.getElementsByClassName("bili-video-card__info--ad"),
            ...document.getElementsByClassName("bili-video-card__info--creative-ad"),
            ...document.getElementsByClassName("btn-ad")
        ];
        ads.forEach(ad => {
            handleAdContainer(ad);
        });

        if (ads.length === 0) {
            console.log("No ads found");
        }
    } catch (error) {
        console.error("An error occurred:", error);
    }
}

function handleAdContainer(adContainer) {



            const AdContainer = adContainer.closest('.feed-card');
            if (AdContainer && AdContainer.parentNode) {
            AdContainer.style.display = 'none';
            AdContainer.parentNode.removeChild(AdContainer);
            }
            if (adContainer.textContent.trim() === '')
            {
                adContainer.style.display = 'none';
                adContainer.parentNode.removeChild(adContainer);
            }

}

window.addEventListener('load', function() {

    setTimeout(console.log("first"), 500);
    runCode();
    try {
        const ref_btn = document.getElementsByClassName("primary-btn roll-btn")[0];
        if (ref_btn) {
            ref_btn.addEventListener('click', function() {
                setTimeout(runCode, 500);
            });
        }
    } catch(error) {
        console.log("refresh error:", error);
    }
});

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址