adblockblockblock

Remove anti-adblock

当前为 2023-03-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @author       @shitchell
// @license      wtfpl
// @namespace    https://github.com/shitchell
// @name         adblockblockblock
// @version      0.0.1
// @description  Remove anti-adblock
// @include      *://*
// @grant        none
// @run-at       document-start
// ==/UserScript==

// This script is under active development. I will update this with more class names
// used by modals I come across used to block the page. Warning: this script MIGHT
// break some pages. It basically searches for any elements which contain a certain
// string in their class names and then follows their parent tree up to see if that
// matching element or any of its parents have a z-index > 50. I might increase that
// z-index if 50 is too low and accidentally removes intentional, desired elements,
// and I might have to implement more sophisticated logic than the above if it ends
// up destroying many elements we'd rather keep. Please drop a comment with the link
// to any page this breaks (although hopefully that number is tiny to nil)!

var DEBUG = false;
var VERIFIED_ELEMENTS = [];

function debug(...message) {
    if (DEBUG) {
        let timestamp = new Date().toISOString().replace(/T/, ' ').replace(/\..+/, '');
        let prefix = `[adblockblockblock] ${timestamp} --`;
        console.log(prefix, ...message);
    }
}

function removeAdblockblock() {
    'use strict';
    debug("Removing adblockblock...");

    //
    /// Search for the following common classes used by modals that block the page
    ////
    let pageBlockerClasses = [
        'overlay' // this definitely needs to be updated as I use it more........
    ];
    debug("Searching for page blockers...", pageBlockerClasses);
    for (const pageBlockerClass of pageBlockerClasses) {
        // Get all elements that contain the class name
        let blockerCandidateElements = document.querySelectorAll(`*[class*="${pageBlockerClass}"]`);
        debug(`Found ${blockerCandidateElements.length} elements with class name containing "${pageBlockerClass}"`, blockerCandidateElements);

        // Loop through the elements and their parents to see if they are blocking the page
        for (let blockerCandidateElement of blockerCandidateElements) {
            debug(`Checking element "${blockerCandidateElement.tagName}" with class "${blockerCandidateElement.className}"`, blockerCandidateElement);

            // Store the original element so that we can cache/skip it if we've already verified it
            const originalBlockerCandidateElement = blockerCandidateElement;
            let blockerCandidateVerified = true;
            
            // Check if we've already verified this element
            if (VERIFIED_ELEMENTS.includes(originalBlockerCandidateElement)) {
                debug(`Element "${blockerCandidateElement.tagName}" with class "${blockerCandidateElement.className}" has already been verified`, blockerCandidateElement);
                continue;
            }

            // Check the z-index and position of the element
            while (blockerCandidateElement) {
                if (
                    blockerCandidateElement.tagName === 'BODY'
                    || blockerCandidateElement.tagName === 'HTML') {
                    // If we get to the top, the element is not blocking the page
                    break;
                }

                // Check the z-index and position of the parent
                let computedStyle = window.getComputedStyle(blockerCandidateElement);
                let position = computedStyle.getPropertyValue('position');
                let zIndex = computedStyle.getPropertyValue('z-index');
                if (
                    (position === 'fixed' || position === 'absolute' || position === 'sticky')
                    && zIndex !== 'auto' && zIndex > 50
                ) {
                    // If the parent has a position and z-index that would block the page, remove it
                    debug(`Removing element "${blockerCandidateElement.tagName}" with class "${blockerCandidateElement.className}"`, blockerCandidateElement);
                    blockerCandidateElement.remove();
                    blockerCandidateVerified = false;
                    break;
                }

                // Move up the DOM tree
                blockerCandidateElement = blockerCandidateElement.parentElement;
            }

            // Cache the element if it was verified
            if (blockerCandidateVerified) {
                debug(`Element "${originalBlockerCandidateElement.tagName}" with class "${originalBlockerCandidateElement.className}" has been verified`, originalBlockerCandidateElement);
                VERIFIED_ELEMENTS.push(originalBlockerCandidateElement);
            }
        }
    }

    //
    /// Double check the html, body, and content divs to ensure overflow is not hidden
    ////
    let overflowHiddenElements = document.querySelectorAll('html, body, #content, #main, main, section');
    for (const overflowHiddenElement of overflowHiddenElements) {
        let computedStyle = window.getComputedStyle(overflowHiddenElement);
        let overflow = computedStyle.getPropertyValue('overflow');
        debug(`Overflow of element "${overflowHiddenElement.tagName}" with class "${overflowHiddenElement.className}" is "${overflow}"`, overflowHiddenElement);
        if (overflow.indexOf('hidden') !== -1) {
            debug("Setting overflow to 'initial !important'...", overflowHiddenElement);
            overflowHiddenElement.style.overflow = 'initial !important';
        }
    }
}

(function() {
    'use strict';

    // Remove the adblockblock
    removeAdblockblock();

    // Remove the adblockblock if the page changes
    let observer = new MutationObserver(removeAdblockblock);
    observer.observe(document, { childList: true, subtree: true });
})();