Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save benfoxall/4218050 to your computer and use it in GitHub Desktop.

Select an option

Save benfoxall/4218050 to your computer and use it in GitHub Desktop.

Revisions

  1. benfoxall revised this gist Dec 5, 2012. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions MutationObserverLogger.js
    Original file line number Diff line number Diff line change
    @@ -4,13 +4,16 @@
    // select the target node
    var target = document.querySelector('body');
    var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
    var i=0;
    var i={};

    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
    console.log(++i + ': ' + mutation.type);
    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:
    @@ -27,4 +30,4 @@
    // pass in the target node, as well as the observer options
    observer.observe(target, config);
    })();
    </script>
    </script>
  2. Pete created this gist Dec 5, 2012.
    30 changes: 30 additions & 0 deletions MutationObserverLogger.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    <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=0;

    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
    console.log(++i + ': ' + mutation.type);
    });
    });

    // configuration of the observer:
    var config = {
    childList: true,
    attributes: true,
    characterData: true,
    subtree: true,
    attributeOldValue: true,
    characterDataOldValue: true,
    attributeFilter: true
    };

    // pass in the target node, as well as the observer options
    observer.observe(target, config);
    })();
    </script>