YouTube Anti-Anti-Adblock 2024

Simple YouTube Adblock popup bypass

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

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

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

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

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