Wait for element to display

PHOTO EMBED

Mon Jun 14 2021 14:54:36 GMT+0000 (Coordinated Universal Time)

Saved by @Michael_Gibbons #javascript

  function waitForElementToDisplay(selector, callback, checkFrequencyInMs = 100, timeoutInMs = 10000) {
    const startTimeInMs = Date.now();

    if(!callback){
      callback = () => document.querySelector(selector).style.display = 'none';
    }

    (function loopSearch() {
      if (document.querySelector(selector) != null) {
        callback();
        return;
      }

      setTimeout(function () {
        if (timeoutInMs && Date.now() - startTimeInMs > timeoutInMs){
          return;
        }
        loopSearch();
      }, checkFrequencyInMs);
    })();
  }
content_copyCOPY

If no callback is provided the element is simply hidden. Callback, check frequency, and timeout adjustable.