MCPcopy Index your code
hub / github.com/hoothin/UserScripts / waitForElements

Function waitForElements

Pagetual/pagetual.user.js:12414–12432  ·  view source on GitHub ↗
(sel, doc, maxTime)

Source from the content-addressed store, hash-verified

12412 }
12413
12414 async function waitForElements(sel, doc, maxTime) {
12415 if (!sel) return null;
12416 return new Promise((resolve) => {
12417 let passedTime = 0;
12418 let checkInv = setInterval(() => {
12419 let result = getAllElements(sel, doc, null, true);
12420 if (result && result.length) {
12421 clearInterval(checkInv);
12422 resolve(result);
12423 } else if (maxTime) {
12424 passedTime += 100;
12425 if (passedTime >= maxTime) {
12426 clearInterval(checkInv);
12427 resolve(result);
12428 }
12429 }
12430 }, 100);
12431 });
12432 }
12433
12434 async function clickAction(sel, doc) {
12435 let btn = await waitForElement(sel, doc);

Callers 1

emuPageFunction · 0.85

Calls 2

getAllElementsFunction · 0.85
resolveFunction · 0.50

Tested by

no test coverage detected