Last active
February 10, 2024 02:42
-
-
Save alopatindev/e0e2acecc9fd78048f2c5f9057151a50 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Installation: | |
// 1. https://violentmonkey.github.io/ | |
// 2. ⚙️ Open Dashboard | |
// 3. Install from URL => https://gist.githubusercontent.com/alopatindev/e0e2acecc9fd78048f2c5f9057151a50/raw | |
// ==UserScript== | |
// @name Remove Youtube Popups | |
// @namespace https://violentmonkey.github.io/ | |
// @version 0.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); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment