B站(防AdGuard)弹窗拦截

自动移除B站"检测到您的页面展示可能受到浏览器插件影响"的弹窗

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         B站(防AdGuard)弹窗拦截
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @description  自动移除B站"检测到您的页面展示可能受到浏览器插件影响"的弹窗
// @author       PPPotatooo
// @match        *://*.bilibili.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    // 移除弹窗的函数
    function removeAdblockPopup() {
        const popups = document.querySelectorAll('.adblock-tips');
        popups.forEach(popup => {
            popup.style.display = 'none';
        });
    }

    // 页面加载完成后立即执行一次
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', removeAdblockPopup);
    } else {
        removeAdblockPopup();
    }

    // 设置MutationObserver来处理动态添加的弹窗
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.addedNodes && mutation.addedNodes.length > 0) {
                // 检查新添加的节点中是否有弹窗
                const hasPopup = Array.from(mutation.addedNodes).some(node => {
                    if (node.nodeType === 1) { // 元素节点
                        if (node.classList && node.classList.contains('adblock-tips')) {
                            return true;
                        }
                        // 检查子节点
                        return node.querySelector('.adblock-tips') !== null;
                    }
                    return false;
                });

                if (hasPopup) {
                    removeAdblockPopup();
                }
            }
        });
    });

    // 开始观察文档变化
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();