Guest User

Untitled

a guest
Jan 22nd, 2018
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. export const waitFor = function(search :function, callback :function, interval = 500) :void {
  2. const checkLoop = setInterval(function () {
  3. let element = search();
  4.  
  5. if (typeof element === 'undefined' || element === null) {
  6. return;
  7. }
  8.  
  9. clearInterval(checkLoop);
  10. callback(element);
  11. }, interval);
  12. };
  13.  
  14. export const waitForElement = function(selector :string, callback :function, interval = 500) :void {
  15. waitFor(function(){ return document.querySelector(selector); }, callback, interval);
  16. };
  17.  
  18. export const waitForElements = function(selector :string, callback :function, interval = 500) :void {
  19. waitFor(function(){ return document.querySelectorAll(selector); }, callback, interval);
  20. };
Add Comment
Please, Sign In to add comment