Skip to content

Instantly share code, notes, and snippets.

@Jotin32
Last active April 3, 2024 02:05
Show Gist options
  • Save Jotin32/ce620efccd503a4a13f895d319756893 to your computer and use it in GitHub Desktop.
Save Jotin32/ce620efccd503a4a13f895d319756893 to your computer and use it in GitHub Desktop.
Youtube userscript popup remover tampermonkey
// ==UserScript==
// @name Remove YouTube Popup
// @namespace http://tampermonkey.net/
// @version 2024-04-03
// @description Remove the YouTube popup that says "Some Google services are not associated. Choose to share or not your data with YouTube and other Google services."
// @author JulienB
// @match https://www.youtube.com/
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @grant none
// ==/UserScript==
function removePopup() {
var ironOverlayBackdrops = document.querySelectorAll('tp-yt-iron-overlay-backdrop');
ironOverlayBackdrops.forEach(function(element) {
element.parentNode.removeChild(element);
});
var upsellDialogRenderers = document.querySelectorAll('yt-upsell-dialog-renderer');
upsellDialogRenderers.forEach(function(element) {
element.parentNode.removeChild(element);
});
}
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function(node) {
if (node.tagName === 'TP-YT-IRON-OVERLAY-BACKDROP' || node.tagName === 'YT-UPSELL-DIALOG-RENDERER') {
removePopup();
}
});
}
});
});
observer.observe(document.body, { childList: true, subtree: true });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment