Skip to content

Instantly share code, notes, and snippets.

@stamat
Created December 24, 2019 21:02
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 stamat/f67bfe175a336ae6c40583d4c6822ae3 to your computer and use it in GitHub Desktop.
Save stamat/f67bfe175a336ae6c40583d4c6822ae3 to your computer and use it in GitHub Desktop.
Simple recursive function that waits for DOM changes, used to wait for embedded-JS generated third party code, when no hook apparent or available
function waiter(selector, callback, timeout) {
var elem = document.querySelectorAll(selector);
if (!elem.length) {
if (timeout === undefined) {
timeout = 100;
}
setTimeout(function(){
waiter(selector, callback, timeout);
}, timeout);
} else {
if (callback) {
callback(elem);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment