Skip to content

Instantly share code, notes, and snippets.

@ernestlv
Last active February 19, 2018 20:14
Show Gist options
  • Save ernestlv/afd76f8fb79b733e2bf6c3433bf8e30d to your computer and use it in GitHub Desktop.
Save ernestlv/afd76f8fb79b733e2bf6c3433bf8e30d to your computer and use it in GitHub Desktop.
Check for specific content and fire when ready.
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