YouTube "Interruptions" Popup Remover

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

// ==UserScript==
// @name         YouTube "Interruptions" Popup Remover
// @license      MIT
// @version      1.1
// @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.parentNode.removeChild(notification);
  log("Successfully removed 'Interruptions' notification.");
}

function handleInterruptionNotification(notification) {
  debug("Detected a potential notification element:", notification);
  const textElement = notification.querySelector("tp-yt-paper-toast > div#text-container > yt-formatted-string#text");
  if (!textElement) {
    debug("This notification does not have the expected text element. Ignoring.");
    return;
  }
  if (textElement.textContent.trim() === "Experiencing interruptions?") {
    log("Found 'Experiencing interruptions?' notification. Removing it.");
    destroyNotification(notification);
  } else {
    debug(`Notification text did not match. Text was: "${textElement.textContent.trim()}"`);
  }
}

(async function () {
  "use strict";
  log("Interruptions remover is active.");
  const popupContainer = await waitForElement("ytd-popup-container.style-scope.ytd-app");
  observeAndHandle(popupContainer, "yt-notification-action-renderer", handleInterruptionNotification);
})();