Skip to content

Instantly share code, notes, and snippets.

@livingflore
Last active September 20, 2023 14:00
Show Gist options
  • Save livingflore/734d0f6f14d2b4bf653c403f5194b25d to your computer and use it in GitHub Desktop.
Save livingflore/734d0f6f14d2b4bf653c403f5194b25d to your computer and use it in GitHub Desktop.
remove youtube redirects
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