Created
December 28, 2021 09:30
-
-
Save lexeeech/6c2f51d2543f52f3b7719f8f8795241d 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
var waitForDOM = function (callback) { | |
document.addEventListener("DOMContentLoaded", function () { | |
setTimeout(function () { | |
callback(); | |
}, 5000); | |
}); | |
}; | |
var waitFor = function (callbackValue, callback) { | |
if (callbackValue()) { | |
callback(); | |
} else { | |
setTimeout(function () { | |
waitFor(function () { | |
return callbackValue(); | |
}, callback); | |
}, 100); | |
} | |
}; | |
var waitForGlobal = function (key, callback) { | |
waitFor(function () { | |
return window[key]; | |
}, callback); | |
}; | |
var importScript = function importScript(src, callback) { | |
var script = document.createElement("script"); | |
script.src = src; | |
script.defer = true; | |
if (typeof callback === "function") { | |
script.onload = callback; | |
} | |
document.getElementsByTagName("head")[0].appendChild(script); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment