Last active
February 19, 2018 20:14
-
-
Save ernestlv/afd76f8fb79b733e2bf6c3433bf8e30d to your computer and use it in GitHub Desktop.
Check for specific content and fire when ready.
This file contains hidden or 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 callWhenReady(testCB, readyCB) { | |
console.log('checking for page ready'); | |
var i = setInterval(function(){ // after 1/4 of a sec | |
var res = testCB(); | |
if (res === true){ // wait X sec if node count does not change, page likely finished loading. | |
clearInterval(i); | |
readyCB(); | |
} | |
}, 250); | |
} | |
callWhenReady( | |
() => { //test queries | |
return !!document.querySelector('#sxm-header ~ .program-schedule #canadian.channel-genre') || //www.siriusxm.com/programschedules | |
!!document.querySelector('body[data-shorten-url="//www.foodnetwork.com"] #dfp_bigbox iframe'); | |
}, | |
() => { //when any query above is true do this | |
alert("DOM is ready !!! "); | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment