Remove Adblock Notifications

Kills YouTube's new Anti-Adblock Popups

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Remove Adblock Notifications
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Kills YouTube's new Anti-Adblock Popups
// @author       PoppingXanax
// @license MIT
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {

    // Configuration
    const DEBUG_MODE = true;
    const DOMAINS_TO_CHECK = ['*.youtube-nocookie.com/*'];
    const JSON_PATHS_TO_REMOVE = [
        'playerResponse.adPlacements',
        'playerResponse.playerAds',
        'adPlacements',
        'playerAds',
        'playerConfig',
        'auxiliaryUi.messageRenderers.enforcementMessageViewModel'
    ];

    let unpauseCounter = 0;

    // Disable YouTube's adblock detection flag
    window.__ytplayer_adblockDetected = false;

    // Helper Functions
    function debugLog(message) {
        if (DEBUG_MODE) console.log(`Remove Adblock Notifications: ${message}`);
    }

    function triggerUnpause() {
        const keyEvent = new KeyboardEvent("keydown", {
            key: "k",
            code: "KeyK",
            keyCode: 75,
            which: 75,
            bubbles: true,
            cancelable: true,
            view: window
        });
        document.dispatchEvent(keyEvent);
        unpauseCounter = 0;
        debugLog("Unpaused video using 'k' key");
    }
    
    function processAdblockPopup() {
        const adblockPopup = document.querySelector("body > ytd-app > ytd-popup-container > tp-yt-paper-dialog");
        const videoMain = document.querySelector("#movie_player > video.html5-main-video");
        const videoAlt = document.querySelector("#movie_player > .html5-video-container > video");
    
        if (adblockPopup) {
            debugLog("Adblock popup detected, removing...");
            adblockPopup.remove();
            unpauseCounter = 2;
            console.log("Removed Adblock popup.");
        } else {
            console.log("No Adblock popup detected.");
        }
    
        if (unpauseCounter > 0) {
            if (videoMain && videoMain.paused) triggerUnpause();
            else if (videoAlt && videoAlt.paused) triggerUnpause();
            else unpauseCounter--;
        }
    }

    function cleanJsonPaths(domains, paths) {
        if (!domains.includes(window.location.hostname)) return;

        paths.forEach(path => {
            let targetObject = window;
            path.split('.').forEach(part => {
                if (targetObject.hasOwnProperty(part)) {
                    targetObject = targetObject[part];
                } else {
                    return;
                }
            });
            targetObject = undefined;
        });
    }

    // Initialization
    debugLog("Script initialized");

    setInterval(processAdblockPopup, 1000);

    cleanJsonPaths(DOMAINS_TO_CHECK, JSON_PATHS_TO_REMOVE);

    const domObserver = new MutationObserver(() => {
        cleanJsonPaths(DOMAINS_TO_CHECK, JSON_PATHS_TO_REMOVE);
    });

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

})();