Last active
January 9, 2023 15:25
-
-
Save kiki67100/65e32488f80c8450d45b07329ba452b2 to your computer and use it in GitHub Desktop.
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
/*kiki67100 github 09/01/2023*/ | |
/*Waiting in javascript a html element perfect for scrapping and more easy to use than MutationObserver */ | |
let check_available_el = function (querySelector, debug = false, fn_on_not_found = null, max_tries = 1000, test_interval = 500) { | |
return new Promise(function (resolve, reject) { | |
let iterator_count = 0; | |
let __interval = setInterval(function () { | |
iterator_count++; | |
if (iterator_count > max_tries) { | |
clearInterval(__interval); | |
reject("maximum tries reached"); | |
} | |
var check_el = document.querySelector(querySelector); | |
if (check_el) { | |
if (debug) console.info('[check_available_el] ' + querySelector + ' is found'); | |
clearInterval(__interval); | |
resolve(); | |
} else { | |
if (debug) console.info('[check_available_el] ' + querySelector + ' NOT found'); | |
if (fn_on_not_found !== null) { | |
if (debug) console.log('[check_available_el] fn_on_not_found() ') | |
if (typeof fn_on_not_found === "function") { | |
fn_on_not_found(); | |
} else { | |
if (debug) console.warn('fn_on_not_found must be a function'); | |
} | |
} | |
} | |
}, test_interval) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment