Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rich-Harris/6077780 to your computer and use it in GitHub Desktop.
Save Rich-Harris/6077780 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
// See MDN: https://developer.mozilla.org/en-US/docs/DOM/MutationObserver?redirectlocale=en-US&redirectslug=DOM%2FDOM_Mutation_Observers
(function(){
// select the target node
var target = document.querySelector('body');
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var i={};
// create an observer instance
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
i[mutation.type] = (i[mutation.type] || 0) + 1;
});
console.log(Object.keys(i).map(function(k){
return k + '=' + i[k]
}).join(', '))
});
// configuration of the observer:
var config = {
childList: true,
attributes: true,
characterData: true,
subtree: true,
attributeOldValue: true,
characterDataOldValue: true
};
// pass in the target node, as well as the observer options
observer.observe(target, config);
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment