Patch When Available Library

Calls a function (getExpectedFnc()) repeatedly until it gives an expected result (confirmIsAvailableFnc()). Forwards it to (doPatchFnc()).

Mint 2021.06.16.. Lásd a legutóbbi verzió

Ezt a szkriptet nem ajánlott közvetlenül telepíteni. Ez egy könyvtár más szkriptek számára, amik tartalmazzák a // @require https://update.greasyfork.org/scripts/428034/941187/Patch%20When%20Available%20Library.js hivatkozást.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Patch When Available Library
// @namespace    hoehleg.userscripts.private
// @version      0.1
// @description  Calls a function (getExpectedFnc()) repeatedly until it gives an expected result (confirmIsAvailableFnc()). Forwards it to (doPatchFnc()).
// @author       Gerrit Höhle
// @grant        none
// ==/UserScript==
 
/* jslint esnext: true */
const patchWhenAvailable = ({ getExpectedFnc, doPatchFnc, confirmIsAvailableFnc = null, timeOutRetryMillis = 200, maxPeriodTryMillis = 5000 }) => {
    const valueOrObject = getExpectedFnc();
    const isAvailable = confirmIsAvailable ? confirmIsAvailableFnc(expected) : !!valueOrObject;
    
    if (!isAvailable) {
        if (timeOutRetryMillis <= maxPeriodTryMillis) {

            setTimeout(() => {
                maxPeriodTryMillis -= timeOutRetryMillis;
                patchObject({ getExpected, doPatch, confirmAvailable, timeOutRetryMillis, maxPeriodTryMillis });

            }, timeOutRetryMillis);
        }

        return;
    }

    doPatchFnc(valueOrObject);
};