Created
August 26, 2016 13:59
-
-
Save dutchcelt/fd510c2d2662aa6c31e4df869542ed98 to your computer and use it in GitHub Desktop.
Remove Stylesheet with MutationObserver
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
export default function(reg) { | |
// select the target node | |
const HEAD = document.querySelector('head'); | |
// configuration of the observer: | |
const CONFIG = { attributes: false, childList: true, characterData: false }; | |
// create an observer instance | |
const observer = new MutationObserver(mutations => { | |
mutations.forEach(mutation => { | |
const node = mutation.addedNodes[0]; | |
if (node && reg.test(node.href)) { | |
node.parentNode.removeChild(node); | |
// stop observing | |
observer.disconnect(); | |
} | |
}); | |
}); | |
// pass in the target node, as well as the observer options | |
observer.observe(HEAD, CONFIG); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment