Created
July 14, 2021 05:12
-
-
Save tsmd/e5bba7dd90c18730abac23258a5eb26c 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
export function waitForGlobalVariable(objPath, interval, timeout, callback) { | |
function find(objPath) { | |
var found = window; | |
objPath = objPath.split("."); | |
while (objPath.length > 0) { | |
var objPart = objPath.shift(); | |
if (objPart in found) { | |
found = found[objPart]; | |
} else { | |
return null; | |
} | |
} | |
return found; | |
} | |
function findAndCallback(objPath, callback) { | |
var found = find(objPath); | |
if (found) { | |
callback(); | |
return true; | |
} | |
return false; | |
} | |
var timer = 0; | |
timer = setInterval(function () { | |
var found = findAndCallback(objPath, callback); | |
if (found) { | |
clearInterval(timer); | |
} | |
}, interval); | |
setTimeout(function () { | |
clearInterval(timer); | |
}, timeout); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment