mirror of
https://github.com/Safe-Support-Chat/ocrcc-chatbox
synced 2025-04-07 20:53:40 +00:00
30 lines
634 B
JavaScript
30 lines
634 B
JavaScript
function checkFunc(dom, selector) {
|
|
if (typeof dom.update === 'function') {
|
|
const el = dom.update().find(selector);
|
|
if (el.exists()) {
|
|
return el;
|
|
}
|
|
return null;
|
|
}
|
|
const els = dom.querySelectorAll(selector);
|
|
if (els.length !== 0) {
|
|
return els;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
|
|
export async function waitForSelection(dom, selector) {
|
|
let numSleep = 0;
|
|
for (;;) {
|
|
const el = checkFunc(dom, selector);
|
|
if (el) {
|
|
return el;
|
|
}
|
|
if (numSleep > 2) {
|
|
throw new Error(`could not find ${selector}`);
|
|
}
|
|
await new Promise(resolve => setTimeout(resolve, 250));
|
|
numSleep += 1;
|
|
}
|
|
} |