YouTube Remove Adblock detection

Removes YouTube adblock detection popups and disables itself when user clicks video, reactivates on page navigation

// ==UserScript==
// @name         YouTube Remove Adblock detection 
// @namespace    http://tampermonkey.net/
// @version      1.4
// @description  Removes YouTube adblock detection popups and disables itself when user clicks video, reactivates on page navigation
// @match        https://www.youtube.com/watch*
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  let scriptDisabled = false;

  function waitForVideoElement(callback) {
    const checkInterval = setInterval(() => {
      const video = document.querySelector('video');
      if (video) {
        clearInterval(checkInterval);
        callback(video);
      }
    }, 500);
  }

  function setupOverlayObserver(video) {
    const removeElementsAndPlay = () => {
      if (scriptDisabled) return;

      let removed = false;
      const overlayBackdrops = document.querySelectorAll('tp-yt-iron-overlay-backdrop');

      if (overlayBackdrops.length > 0) {
        overlayBackdrops.forEach((e) => e.remove());
        const popupContainers = document.querySelectorAll('ytd-popup-container');
        popupContainers.forEach((e) => e.remove());
        console.log('[Tampermonkey] Removed overlay backdrop');
        removed = true;
      }

      if (video.paused) {
        console.log('[Tampermonkey] Overlay removed, resuming video...');
        video.play();
      }
    };

    // Initial cleanup
    removeElementsAndPlay();

    // DOM observer
    const observer = new MutationObserver(removeElementsAndPlay);
    observer.observe(document.body, {
      childList: true,
      subtree: true
    });

    // Disable script on user click
    video.addEventListener('click', () => {
      scriptDisabled = true;
      console.log('[Tampermonkey] Script disabled after user clicked the video.');
    });

    window.addEventListener('yt-navigate-finish', () => {
      scriptDisabled = false; // Give the new page time to load
    });
  }

  waitForVideoElement((video) => {
    setupOverlayObserver(video);
  });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址