Remove YouTube Popups

Stop attention stealing

// ==UserScript==
// @name         Remove YouTube Popups
// @namespace    https://violentmonkey.github.io/
// @version      0.1
// @description  Stop attention stealing
// @author       alopatindev
// @license      MIT
// @match        https://www.youtube.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant        none
// ==/UserScript==

(function() {
    "use strict";
    function randomPause() {
        const min = 3000;
        const max = 5000;
        return Math.floor(Math.random() * (max - min + 1)) + min;
    }

    const closeBanner = setInterval(function() {
        if (document.getElementsByClassName("yt-spec-button-shape-next").length > 0) {
            setTimeout(function() {
                const items = [...document.getElementsByClassName("yt-spec-button-shape-next")];
                for (const i of items) {
                    const label = i.getAttribute("aria-label");
                    if (label != null && label.includes("No thanks")) {
                        i.click();
                    }
                }
                console.log("banner closed");
                clearInterval(closeBanner);
            }, randomPause());
        } else if ([...document.querySelectorAll("div")].filter((i) => i.textContent.trim() === "My Ad Center").length > 0) {
            setTimeout(function() {
                let items = document.querySelectorAll("button");
                for (const i of items) {
                    const label = i.getAttribute("aria-label");
                    if (label != null && label.includes("Close")) {
                        console.log(i);
                        i.click();
                    }
                }
                console.log("banner closed");
                clearInterval(closeBanner);
            }, randomPause());
        } else if (document.getElementsByClassName("ytd-single-option-survey-renderer").length > 0) {
            setTimeout(function() {
                const items = [...document.getElementsByClassName("ytd-single-option-survey-renderer")];
                for (const i of items) {
                    const label = i.getAttribute("icon");
                    if (label != null && label.includes("yt-icons:close")) {
                        i.click();
                    }
                }
                console.log("banner closed");
                clearInterval(closeBanner);
            }, randomPause());
        }
    }, 300);
})();