Skip to content

Instantly share code, notes, and snippets.

@dutchcelt
Created August 26, 2016 13:59
Show Gist options
  • Save dutchcelt/fd510c2d2662aa6c31e4df869542ed98 to your computer and use it in GitHub Desktop.
Save dutchcelt/fd510c2d2662aa6c31e4df869542ed98 to your computer and use it in GitHub Desktop.
Remove Stylesheet with MutationObserver
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