Created
September 9, 2012 15:19
-
-
Save krukid/3685004 to your computer and use it in GitHub Desktop.
Chrome mutation observer for dynamic element handling (removing popups by id and such)
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
(function (window, checkNode){ | |
var p = {}; | |
var m = { | |
registerObserver: function() { | |
if (typeof(window.WebKitMutationObserver) == "undefined") return; | |
p.observer = new window.WebKitMutationObserver(function(mutationRecords) { | |
mutationRecords.forEach(function(mutationRecord) { | |
for (var i = 0; i < mutationRecord.addedNodes.length; ++i) | |
m.safeCheckNode(mutationRecord.addedNodes[i]); | |
}); | |
}); | |
p.observer.observe(window.document, { | |
subtree: true, // observe the subtree rooted at myNode | |
childList: true, // include information childNode insertion/removals | |
attribute: false // include information about changes to attributes within the subtree | |
}); | |
}, | |
safeCheckNode: function(node) { | |
try { checkNode(node); } | |
catch (e) { } | |
} | |
}; | |
m.registerObserver(); | |
})(window, function(node) { | |
if (node.id == 'gritter-notice-wrapper') | |
node.parentNode.removeChild(node); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Goes great with Personalized Web plugin:
https://chrome.google.com/webstore/detail/plcnnpdmhobdfbponjpedobekiogmbco