Last active
September 20, 2023 14:00
-
-
Save livingflore/734d0f6f14d2b4bf653c403f5194b25d to your computer and use it in GitHub Desktop.
remove youtube redirects
This file contains hidden or 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
var callback = function(mutationsList, observer) { | |
for(let mutation of mutationsList) { | |
if (mutation.type === 'childList') { | |
mutation.addedNodes.forEach((node) => { | |
if(node instanceof Element && node.hasAttribute('href')) { | |
var href = node.getAttribute('href'); | |
if(href.match(/https\:\/\/www\.youtube\.com\/redirect\?.+/gm)) { | |
const urlParams = new URLSearchParams(href); | |
node.setAttribute('href', urlParams.get('q')); | |
} | |
} | |
}); | |
} | |
} | |
}; | |
var observer = new MutationObserver(callback); | |
observer.observe(document.body, { attributes: false, childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment