Created
May 25, 2017 23:25
-
-
Save rquast/175339caad0252d63bc0c2d3b588ecbc to your computer and use it in GitHub Desktop.
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
/** | |
* Observe the DOM for changes to find new Cavy topics. | |
*/ | |
var observeDOM = (function() { | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, | |
eventListenerSupported = window.addEventListener; | |
return function(obj, callback) { | |
if (MutationObserver) { | |
var obs = new MutationObserver(function(mutations, observer) { | |
if (mutations[0].addedNodes.length || mutations[0].removedNodes.length) { | |
callback(); | |
} | |
}); | |
obs.observe( obj, {childList: true, subtree: true}); | |
} else if (eventListenerSupported) { | |
obj.addEventListener('DOMNodeInserted', callback, false); | |
obj.addEventListener('DOMNodeRemoved', callback, false); | |
} | |
} | |
})(); | |
observeDOM(document.getElementsByTagName('body')[0], function() { | |
parseTopicElements(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where parseTopicElements is a fuction that runs a query selector to find all [data-cavy-topic..