Anti ad blocker madurird.com for https://watch.ug

anti ad blocker:

working bypass (tampermonkey)

(function() {
    'use strict';

    const SCRIPT_SIGNATURES = [
        'Ly9tYWR1cmlyZC5jb20v', // Part of a base64 encoded string seen ("//madurird.com/")
        '_kkbdi', // A global function name it tries to set up
        '_znjuyd'  // Another global function name
    ];

    const PROTECTED_GLOBALS = [
        'String', 'atob', 'btoa', 'eval', 'JSON', 'Date', 'Math', 'Array',
        'RegExp', 'Promise', 'parseInt', 'navigator', 'encodeURI', 'Uint8Array',
        'setTimeout', 'setInterval', 'ArrayBuffer', 'clearTimeout', 'clearInterval',
        'MessageChannel', 'BroadcastChannel', 'decodeURIComponent', 'encodeURIComponent',
        'Object', 'TypeError', 'Event', 'Error', 'Image', 'localStorage', 'sessionStorage',
        'fetch', 'XMLHttpRequest', 'document', 'window', 'appendChild', 'createElement',
        'createTextNode', 'postMessage', 'addEventListener', 'removeEventListener'
    ];

    let scriptBlocked = false;

    // Store original methods safely
    const originalCreateElement = document.createElement;
    const originalAppendChild = Node.prototype.appendChild;
    const originalWindow = unsafeWindow || window; // Use unsafeWindow for direct access to page's window

    // Make critical globals non-configurable and non-writable on the main window
    // This might be too aggressive and break some legitimate sites.
    PROTECTED_GLOBALS.forEach(prop => {
        try {
            const descriptor = Object.getOwnPropertyDescriptor(originalWindow, prop);
            if (descriptor && (descriptor.writable || descriptor.configurable)) {
                Object.defineProperty(originalWindow, prop, {
                    value: originalWindow[prop],
                    writable: false,
                    configurable: false
                });
            } else if (!descriptor && originalWindow[prop] !== undefined) {
                 Object.defineProperty(originalWindow, prop, {
                    value: originalWindow[prop],
                    writable: false,
                    configurable: false
                });
            }
        } catch (e) {
            // console.warn(`[Disabler] Could not protect global: ${prop}`, e);
        }
    });


    // --- Monkey-patch createElement ---
    document.createElement = function(tagName) {
        const element = originalCreateElement.apply(document, arguments);
        if (tagName.toLowerCase() === 'iframe') {
            console.log('[Disabler] Intercepted iframe creation:', element);
            // Try to make its contentWindow's important properties non-configurable
            // This is a race condition; the ad script might get there first.
            try {
                // We can't access contentWindow immediately if src is not about:blank or not yet loaded.
                // For "about:blank" iframes, we can try to act quickly.
                if (!element.src || element.src.toLowerCase() === 'about:blank' || element.src.toLowerCase().startsWith('javascript:')) {
                    // Attempt to neutralize its window object if possible
                    // This is highly experimental and might not work reliably due to timing.
                    Object.defineProperty(element, 'contentWindow', {
                        get: function() {
                            console.log('[Disabler] Access to iframe.contentWindow intercepted.');
                            // Return a neutered window or throw an error
                            // Option 1: Return a very minimal object
                            // return { document: { body: null, head: null, createElement: ()=>{}} };
                            // Option 2: Throw to disrupt the script
                            // throw new Error("Iframe contentWindow access blocked by disabler");
                            // Option 3: Try to get the real one and make it read-only (difficult)
                            const realContentWindow = Object.getOwnPropertyDescriptor(HTMLIFrameElement.prototype, 'contentWindow').get.call(this);
                            if (realContentWindow) {
                                PROTECTED_GLOBALS.forEach(prop => {
                                    try {
                                        Object.defineProperty(realContentWindow, prop, {
                                            value: realContentWindow[prop],
                                            writable: false,
                                            configurable: false
                                        });
                                    } catch(e) {/*ignore*/}
                                });
                                // Specifically target the script's attempt to redefine 'window'
                                Object.defineProperty(realContentWindow, 'window', {
                                    value: realContentWindow,
                                    writable: false,
                                    configurable: false
                                });
                            }
                            return realContentWindow;
                        },
                        configurable: true // Allow it to be re-defined by the browser but we log
                    });
                }
            } catch (e) {
                // console.warn('[Disabler] Error trying to neutralize iframe contentWindow:', e);
            }
        }
        return element;
    };

    // --- Monkey-patch appendChild ---
    Node.prototype.appendChild = function(node) {
        if (node && node.tagName) {
            const tagName = node.tagName.toLowerCase();
            if (tagName === 'script') {
                // Check script content or src for signatures
                let scriptContent = node.textContent || node.innerHTML || '';
                if (node.src) {
                    scriptContent += ' ' + node.src; // Include src in checks
                }

                for (const sig of SCRIPT_SIGNATURES) {
                    if (scriptContent.includes(sig)) {
                        console.log(`[Disabler] Blocking script append due to signature: ${sig}`, node);
                        scriptBlocked = true;
                        // Option 1: Prevent appending
                        // return node; // Or throw an error
                        // Option 2: Neuter the script
                        node.type = 'text/plain';
                        node.textContent = '// Script blocked by Disabler';
                        node.src = '';
                        // Send it to the original appendChild so the DOM structure isn't too broken
                        return originalAppendChild.apply(this, [node]);
                    }
                }
            } else if (tagName === 'iframe') {
                console.log('[Disabler] Intercepted iframe append:', node);
                // Further checks or neutralization could happen here if needed
                // e.g., if the createElement patch wasn't sufficient.
                // Be careful, node.contentWindow might not be available yet.
            }
        }
        return originalAppendChild.apply(this, arguments);
    };

    // --- Override Object.defineProperty for 'window' ---
    // This is very aggressive and might break sites.
    const originalDefineProperty = Object.defineProperty;
    Object.defineProperty = function(obj, prop, descriptor) {
        // Attempt to prevent redefining 'window' on any object, especially the iframe's window
        if (prop === 'window' && obj !== originalWindow) { // Don't block for the main window's own setup
            console.warn(`[Disabler] Attempt to define 'window' property on an object blocked. Object:`, obj, `Descriptor:`, descriptor);
            // Potentially throw an error or return the original object to disrupt the script
            // throw new Error("Redefinition of 'window' property blocked by disabler.");
            return obj;
        }
        // Prevent making key globals configurable from within an iframe
        if (obj && obj.constructor && obj.constructor.name === 'Window' && obj !== originalWindow) {
            if (PROTECTED_GLOBALS.includes(prop) && descriptor && descriptor.configurable === true) {
                console.warn(`[Disabler] Attempt to make '${prop}' configurable in an iframe window blocked.`);
                descriptor.configurable = false;
                if ('writable' in descriptor) descriptor.writable = false; // Also make it non-writable
            }
        }

        return originalDefineProperty.apply(this, arguments);
    };
    // Restore it for the global Object if we are in a different scope, though Tampermonkey usually handles this.
    if (Object.defineProperty !== originalDefineProperty) {
        Object.defineProperty(Object, 'defineProperty', { value: originalDefineProperty, writable: false, configurable: false });
    }


    console.log('[Disabler] Advanced Ad Script Disabler active.');

    // You might also want to look for and neutralize specific global variables
    // the script tries to set up, but this is harder due to randomization.
    // e.g., after a short delay:
    /*
    setTimeout(() => {
        if (originalWindow._kkbdi || originalWindow._znjuyd) {
            console.log('[Disabler] Neutralizing known ad script functions.');
            try { originalWindow._kkbdi = () => console.log('[Disabler] _kkbdi called but disabled.'); } catch(e){}
            try { originalWindow._znjuyd = () => console.log('[Disabler] _znjuyd called but disabled.'); } catch(e){}
        }
    }, 500);
    */

})();

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.