-
-
Save elbywan/2967eb39e10ad219e95b166bb77fa2df 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
const observer = new MutationObserver(mutations => { | |
mutations.forEach(({ addedNodes }) => { | |
addedNodes.forEach(node => { | |
// For each added script tag | |
if(node.nodeType === 1 && node.tagName === 'SCRIPT') { | |
const src = node.src || '' | |
const type = node.type | |
// If the src is inside your blacklist | |
if(needsToBeBlacklisted(src, type)) { | |
// Do some stuff that will prevent the script tag loading ;) | |
// (See below…) | |
} | |
} | |
}) | |
}) | |
}) | |
// Starts the monitoring | |
observer.observe(document.documentElement, { | |
childList: true, | |
subtree: true | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment