YouTube Anti-Anti-Adblock 2024

Simple YouTube Adblock popup bypass

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube Anti-Anti-Adblock 2024
// @version      1.0
// @description  Simple YouTube Adblock popup bypass
// @author       daijro
// @license      MIT
// @match        *://*.youtube.com/watch*
// @grant        none
// @run-at       document-end
// @namespace https://greasyfork.org/users/795282
// ==/UserScript==

(function() {
    'use strict';

    const video = document.querySelector('video');
    var oldPaused = video.paused;
    var pausedRecently = false;

    // Remove elements by selector and check if video is paused
    function handleElements(selector) {
        const elements = document.querySelectorAll(selector);
        if (elements.length > 0) {
            elements.forEach(el => el.remove());
            console.log('Removed elements');

            // Play the video
            if (video.paused && pausedRecently) {
                video.play();
                console.log('Unpausing video');
            }
        }
    }

    // Monitor DOM changes for popup
    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            if (!oldPaused && video.paused) {
                pausedRecently = true;
                setTimeout(() => {
                    pausedRecently = false;
                }, 300); // reset after period
            }
            if (mutation.addedNodes.length) {
                handleElements('iron-a11y-announcer');
                handleElements('tp-yt-paper-dialog');
            }
            oldPaused = video.paused;
        });
    });

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