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); })(); }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter