Skip to content

Instantly share code, notes, and snippets.

@lexeeech
Created December 28, 2021 09:30
Show Gist options
  • Save lexeeech/6c2f51d2543f52f3b7719f8f8795241d to your computer and use it in GitHub Desktop.
Save lexeeech/6c2f51d2543f52f3b7719f8f8795241d to your computer and use it in GitHub Desktop.
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