adblockblockblock

Remove anti-adblock

目前為 2023-03-04 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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 and its parents
            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
                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 element 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 on 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 });
})();