Created
December 24, 2019 21:02
-
-
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
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
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