22 lines
817 B
JavaScript
22 lines
817 B
JavaScript
|
|
const uw = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window;
|
|
const BASE_URL = 'https://grepo.haunter-pets.top';
|
|
|
|
// ---- Jitter helpers -----------------------------------------------
|
|
// Returns a random integer between min and max (inclusive)
|
|
function randInt(min, max) {
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
}
|
|
// Schedules fn to run after a random ms delay, then reschedules itself
|
|
function jitterLoop(fn, minMs, maxMs) {
|
|
function schedule() {
|
|
setTimeout(async () => {
|
|
await fn();
|
|
schedule(); // reschedule with a NEW random delay every time
|
|
}, randInt(minMs, maxMs));
|
|
}
|
|
schedule();
|
|
}
|
|
|
|
// ----------------------------------------------------------------
|