Last active
August 29, 2015 14:23
-
-
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.
This file contains 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
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