Universal AdBlock Bypass (Beta) (Optimized)

Advanced bypass for ad-blocker detection with filter list optimization

// ==UserScript==
// @name         Universal AdBlock Bypass (Beta) (Optimized)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Advanced bypass for ad-blocker detection with filter list optimization
// @author       Snow2122
// @license      MIT
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Counter common ad-blocker detection variables
    const spoofedVars = {
        'ai_adb_active': true,
        'ai_adb_action': 0,
        'adblock': false,
        'adsBlocked': false,
        'canRunAds': true,
        'showAds': true
    };

    Object.keys(spoofedVars).forEach(key => {
        Object.defineProperty(window, key, {
            value: spoofedVars[key],
            writable: false,
            configurable: false
        });
    });

    // Mock ad-blocker detection functions
    window.ai_adb_undetected = function() {
        document.body?.setAttribute('data-data-mask', 'clear');
        if (typeof window.ai_adb_undetected_actions === 'function') {
            window.ai_adb_undetected_actions(0);
        }
    };

    // Spoof bait content visibility
    function spoofBaitElements() {
        const baitSelectors = [
            '.ads-ad', '.ad-banner', '.ad-block', '[class*="ad-"]', '[id*="ad-"]',
            '.banner-ad', '.adsbygoogle', '.detectadblock', '[class*="banner"]',
            // From Fanboy Annoyance and Social lists
            '.cookie-notice', '.gdpr-consent', '.social-share', '[class*="cookie-"]',
            '[id*="social-"]', '.popup-overlay', '.newsletter-popup'
        ];
        baitSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => {
                el.style.display = 'block';
                el.style.visibility = 'visible';
                el.style.height = 'auto';
                el.style.width = 'auto';
                el.style.opacity = '1';
                el.removeAttribute('hidden');
            });
        });
    }

    // Intercept and spoof fetch requests for ad-related resources
    const adDomains = [
        'pagead', 'ads.', 'doubleclick', 'adsbygoogle', 'ad-', 'banner',
        // From EasyList
        'googlesyndication', 'adnxs', 'pubmatic', 'openx', 'rubiconproject',
        'criteo', 'adform', 'yieldmanager', 'smartadserver', 'adtech'
    ];
    const adDomainRegex = new RegExp(`(${adDomains.join('|')})`, 'i');

    const originalFetch = window.fetch;
    window.fetch = function(url, options) {
        if (adDomainRegex.test(url)) {
            return Promise.resolve(new Response('OK', { status: 200, statusText: 'OK' }));
        }
        return originalFetch.apply(this, arguments);
    };

    // Intercept XMLHttpRequest for ad-related resources
    const originalOpen = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(method, url) {
        if (adDomainRegex.test(url)) {
            this._isAdRequest = true;
            return;
        }
        return originalOpen.apply(this, arguments);
    };

    const originalSend = XMLHttpRequest.prototype.send;
    XMLHttpRequest.prototype.send = function() {
        if (this._isAdRequest) {
            this.dispatchEvent(new Event('load'));
            return;
        }
        return originalSend.apply(this, arguments);
    };

    // Remove ad-blocker overlays and messages
    function removeAdBlockElements() {
        const selectors = [
            'ins > div', '.ad-block-message', '#adblock-overlay', '.ai-adb-overlay',
            '.adblock-notice', '.ai-adb-message-window', '[class*="adblock-"]',
            '[id*="adblock-"]', '.ads-blocker-warning', '.disable-adblock',
            // From EasyList and Fanboy Annoyance
            '.popup-ad', '.interstitial-ad', '.video-ad', '[class*="sponsored-"]',
            '.cookie-consent', '.privacy-notice', '[id*="gdpr-"]', '.social-widget'
        ].join(', ');
        document.querySelectorAll(selectors).forEach(el => el.remove());
    }

    // Clear ad-blocker and tracking-related cookies
    function clearCookies() {
        const cookies = [
            'aiADB', 'aiADB_PV', 'aiADB_PR', 'adblock_detected',
            'adblock', 'ads_blocked', 'adb_detected',
            // From Fanboy CookieMonster and EasyPrivacy
            '__utma', '__utmb', '__utmz', '_ga', '_gid', '_gat',
            'CONSENT', 'cookie_notice_accepted', 'eu_cookie'
        ];
        cookies.forEach(cookie => {
            document.cookie = `${cookie}=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;`;
        });
    }

    // Restore hidden content and counter anti-adblock classes
    function restoreContent() {
        const hiddenSelectors = [
            '.ai-adb-hide', '.adblock-hidden', '[class*="hidden-by-adblock"]',
            // From EasyList
            '[class*="blocked-ad"]', '[style*="display: none"]'
        ];
        const showSelectors = [
            '.ai-adb-show', '.adblock-show', '[class*="show-if-adblock"]',
            // From Fanboy Annoyance
            '[class*="consent-"]', '[class*="popup-"]'
        ];

        hiddenSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => {
                el.style.display = 'block';
                el.style.visibility = 'visible';
                el.style.opacity = '1';
                el.classList.remove(...el.classList.values());
            });
        });

        showSelectors.forEach(selector => {
            document.querySelectorAll(selector).forEach(el => {
                el.style.display = 'none';
                el.classList.remove(...el.classList.values());
            });
        });
    }

    // Neutralize IAB detection scripts
    function neutralizeIABDetection() {
        const iabBait = document.querySelectorAll('[id*="iab-"], [class*="iab-"]');
        iabBait.forEach(el => {
            el.style.display = 'block';
            el.style.visibility = 'visible';
            el.style.height = 'auto';
            el.style.width = 'auto';
        });
    }

    // Initialize bypass
    function init() {
        clearCookies();
        removeAdBlockElements();
        restoreContent();
        spoofBaitElements();
        neutralizeIABDetection();
        if (typeof window.ai_adb_undetected === 'function') {
            window.ai_adb_undetected(0);
        }
    }

    // Run when DOM is loaded
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', init);
    } else {
        init();
    }

    // Observe for dynamically added elements
    const observer = new MutationObserver(() => {
        removeAdBlockElements();
        restoreContent();
        spoofBaitElements();
        neutralizeIABDetection();
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Periodically check for new bait elements
    setInterval(() => {
        spoofBaitElements();
        neutralizeIABDetection();
    }, 1000);
})();