Skip to content

Instantly share code, notes, and snippets.

@rquast
Created May 25, 2017 23:25
Show Gist options
  • Save rquast/175339caad0252d63bc0c2d3b588ecbc to your computer and use it in GitHub Desktop.
Save rquast/175339caad0252d63bc0c2d3b588ecbc to your computer and use it in GitHub Desktop.
/**
* 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();
});
@rquast
Copy link
Author

rquast commented May 26, 2017

where parseTopicElements is a fuction that runs a query selector to find all [data-cavy-topic..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment