Created
January 12, 2018 18:42
-
-
Save SparK-Cruz/e99665d2c38916fe70734e0d99346643 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 const waitFor = function(search :function, callback :function, interval = 500) :void { | |
const checkLoop = setInterval(function () { | |
let element = search(); | |
if (typeof element === 'undefined' || element === null) { | |
return; | |
} | |
clearInterval(checkLoop); | |
callback(element); | |
}, interval); | |
}; | |
export const waitForElement = function(selector :string, callback :function, interval = 500) :void { | |
waitFor(function(){ return document.querySelector(selector); }, callback, interval); | |
}; | |
export const waitForElements = function(selector :string, callback :function, interval = 500) :void { | |
waitFor(function(){ return document.querySelectorAll(selector); }, callback, interval); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment