platform-codebase/features/dating-autopilot/codegen/timing.ts

38 lines
1.1 KiB
TypeScript
Executable file

/**
* Timing helper functions for browser scripts
* Generates JavaScript code strings for timing utilities
*/
export function generateTimingHelpers(): string {
return `
// ============== TIMING HELPERS ==============
function sleep(ms) {
return new Promise(r => setTimeout(r, ms));
}
// Adds 25-100% random extra to base time for human-like variance
function randomize(base) {
const extra = base * (0.25 + Math.random() * 0.75);
return Math.round(base + extra);
}
async function wait(baseMs) {
const actual = randomize(baseMs);
// During longer waits, do idle behaviors
if (actual > 1000) {
const chunks = Math.floor(actual / 500);
for (let i = 0; i < chunks; i++) {
await sleep(500);
if (typeof idleMouseWiggle === 'function') await idleMouseWiggle();
if (typeof idleScroll === 'function' && i === Math.floor(chunks / 2)) await idleScroll();
}
await sleep(actual % 500);
} else {
await sleep(actual);
}
return actual;
}
// =============================================`;
}