YouTube "Interruptions" Popup Remover

Automatically removes the "Experiencing interruptions?" popup on YouTube.

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         YouTube "Interruptions" Popup Remover
// @license      MIT
// @version      1.3
// @namespace    https://github.com/tukarsdev
// @description  Automatically removes the "Experiencing interruptions?" popup on YouTube.
// @author       tukars
// @icon         https://www.youtube.com/favicon.ico
// @match        https://www.youtube.com/*
// @require      https://update.greasyfork.org/scripts/552301/1676024/Observe.js
// @run-at       document-end
// @grant        none
// ==/UserScript==

const { contextPrint, waitForElement, observeAndHandle } = window.userscript.com.tukars.Observe;

const ENABLE_DEBUG_LOGGING = false;

const { log, warn, error, info, debug } = contextPrint(
  "YT Interruptions Remover", ENABLE_DEBUG_LOGGING
);

function destroyNotification(notification) {
  if (!notification) {
    error("Notification element does not exist! Cannot delete it!");
    return;
  }
  if (!notification.parentNode) {
    warn("Notification element already removed from the DOM.");
    return;
  }
  debug("Destroying 'Interruptions' notification element.", notification);
  notification.remove(); // .remove() is cleaner than parentNode.removeChild
  log("Successfully removed 'Interruptions' notification.");
}

function handleInterruptionNotification(notification) {
  debug("Detected a potential notification element:", notification);

  // UPDATED SELECTOR:
  // We removed 'tp-yt-paper-toast' and the strict '>' combinators. 
  // We just look for the text container ID inside the notification renderer.
  const textElement = notification.querySelector("#text-container #text");

  if (!textElement) {
    debug("This notification does not have the expected text element. Ignoring.");
    return;
  }

  const textContent = textElement.textContent.trim();
  
  // UPDATED CHECK:
  // Using includes() is safer than === in case of hidden characters or newlines
  if (textContent.includes("Experiencing interruptions?")) {
    log("Found 'Experiencing interruptions?' notification. Removing it.");
    destroyNotification(notification);
  } else {
    debug(`Notification text did not match. Text was: "${textContent}"`);
  }
}

(async function () {
  "use strict";
  log("Interruptions remover is active.");
  
  // Wait for the popup container which holds these notifications
  const popupContainer = await waitForElement("ytd-popup-container.style-scope.ytd-app");
  
  // Observe the container specifically looking for the notification renderer tag
  observeAndHandle(popupContainer, "yt-notification-action-renderer", handleInterruptionNotification);
})();