Waits until a condition is true, executing a callback function when the condition is met.
이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/467272/1235249/awaitFor.js을(를) 사용하여 포함하는 라이브러리입니다.
// ==UserScript==
// @name awaitFor
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Waits until a condition is true, executing a callback function when the condition is met.
// @author IgnaV
// @grant none
// ==/UserScript==
const awaitFor = (condition, callback, maxAttempts=null, awaitTime=500, maxAwaitTime=10000, ...params) => {
maxAttempts ||= maxAwaitTime / awaitTime;
let attempts = 0
const intervalId = setInterval(() => {
const result = condition();
attempts++;
if (attempts >= maxAttempts || result) {
clearInterval(intervalId);
}
if (result) {
callback(result, ...params);
}
}, awaitTime);
};