Greasy Fork is available in English.

awaitFor

Waits until a condition is true, executing a callback function when the condition is met.

Verzia zo dňa 14.08.2023. Pozri najnovšiu verziu.

Tento skript by nemal byť nainštalovaný priamo. Je to knižnica pre ďalšie skripty, ktorú by mali používať cez meta príkaz // @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);
};