Greasy Fork

Greasy Fork is available in English.

应对去广告检测

针对哔哩轻小说检测屏蔽广告的脚本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         应对去广告检测
// @version      0.0.3
// @description  针对哔哩轻小说检测屏蔽广告的脚本
// @author       Y_C_Z
// @match        https://www.linovelib.com/*
// @match        https://www.bilinovel.com/*
// @grant    unsafeWindow
// @run-at       document-start
// @license MIT
// @namespace http://greasyfork.icu/users/1335970
// ==/UserScript==
(function() {
    // 拦截目标脚本的 URL
    const targetScriptURL = 'tip_chapter.js';

    // 重写 fetch
    const originalFetch = window.fetch;
    window.fetch = function(input, init) {
        if (typeof input === 'string' && input.includes(targetScriptURL)) {
            console.log('拦截 fetch 请求:', input);
            return Promise.reject(new Error('请求被拦截'));
        }
        return originalFetch.call(this, input, init);
    };

    // 重写 XMLHttpRequest
    const originalXHROpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
        if (url.includes(targetScriptURL)) {
            console.log('拦截 XMLHttpRequest 请求:', url);
            this.abort(); // 中止请求
            return;
        }
        originalXHROpen.apply(this, arguments);
    };

    // 监控动态加载的脚本
    const observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                if (node.tagName === 'SCRIPT' && node.src.includes(targetScriptURL)) {
                    node.remove(); // 移除匹配的脚本
                    console.log('拦截动态加载的脚本:', node.src);
                }
            });
        });
    });

    // 开始监控 document 的子节点变化
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();