Skip to content

Instantly share code, notes, and snippets.

@H3mul
Last active October 26, 2023 08:25
Show Gist options
  • Save H3mul/54145fbfafe89a03c2ce24fdcb66a868 to your computer and use it in GitHub Desktop.
Save H3mul/54145fbfafe89a03c2ce24fdcb66a868 to your computer and use it in GitHub Desktop.
Fix youtube adblock popups
// ==UserScript==
// @name youtube popup killer
// @namespace https://gist.github.com/H3mul/
// @version 1.0
// @updateURL https://gist.github.com/H3mul/54145fbfafe89a03c2ce24fdcb66a868/raw/youtube-adblock-popup-killer.js
// @downloadURL https://gist.github.com/H3mul/54145fbfafe89a03c2ce24fdcb66a868/raw/youtube-adblock-popup-killer.js
// @description Closes youtube popups complaining about adblocker and resumes playback
// @author h3mul
// @match https://*.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
(function() {
const debug = true;
window.addEventListener("yt-navigate-finish", () => {
const popupContainer = document.querySelector("body > ytd-app > ytd-popup-container");
const pauseButton = document.querySelector("#movie_player > div.ytp-chrome-bottom > div.ytp-chrome-controls > div.ytp-left-controls > button");
const observer = new MutationObserver((mutations) => {
const popup = popupContainer.querySelector("tp-yt-paper-dialog")
if (popup) {
popupContainer.removeChild(popup)
pauseButton && pauseButton.getAttribute("data-title-no-tooltip") == "Play" && pauseButton.click();
console.log("Caught and removed yt adblock popup")
}
});
observer.observe(popupContainer, { childList: true, subtree: true });
log("Starting to listen to DOM changes in popup container");
}, true);
function log(message) {
if (debug) console.log(message);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment