mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
30 lines
660 B
JavaScript
30 lines
660 B
JavaScript
const waitForQuery = settings =>
|
|
{
|
|
const MaxRetry = settings.maxQueryRetry;
|
|
let retry = 0;
|
|
const tryQuery = (query, condition, action, failed) =>
|
|
{
|
|
if (retry >= MaxRetry)
|
|
{
|
|
if (failed)
|
|
{
|
|
failed();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
const result = query();
|
|
if (condition(result))
|
|
{
|
|
action(result);
|
|
}
|
|
else
|
|
{
|
|
retry++;
|
|
setTimeout(() => tryQuery(query, condition, action, failed), settings.queryInterval);
|
|
}
|
|
}
|
|
};
|
|
return tryQuery;
|
|
};
|