Skip to content

Instantly share code, notes, and snippets.

@yuvilio
Last active August 29, 2015 14:23
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 yuvilio/1d6bf530b721a5ffed92 to your computer and use it in GitHub Desktop.
Save yuvilio/1d6bf530b721a5ffed92 to your computer and use it in GitHub Desktop.
Triggering an event, confirming it happened with mutationobserver, triggering it again when ready.
var i = 3; //number of times you'll want to run task (three clicks, in this example)
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
//Was this an event that made the list grow?
if (mutation.type === 'childList') {
i--; //then count it as an iteration
}
//Got more iterations to go? On to the next one! click again!
if (i > 0){
document.querySelector('.load-more-text').click();
}
});
});
//what we'll be observing, in this case, seeing a list (that has class 'channels-browse-content-grid') of DOM nodes grow
var config = { attributes: false,
childList: true,
characterData: false,
subtree: false };
observer.observe(document.querySelector('.channels-browse-content-grid'), config);
//start it off. do the action that will trigger the list growing (click on a button which ajax fetches something and populates the list you specified)
document.querySelector('.load-more-text').click();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment