/**
 * Nexus Connect — Shared content-script helpers
 *
 * MV3 injects every matching content_scripts entry into the SAME isolated world
 * for a document, and the scripts in a manifest "js" array run in order sharing
 * one global scope. A plain (non-module) file listed first therefore exposes its
 * top-level function declarations to the scripts that follow it — no bundler
 * needed.
 *
 * This file holds the human-pacing model that was previously copy-pasted
 * byte-for-byte into content-linkedin.js, content-twitter.js and
 * content-telegram.js. It is prepended (via manifest.json) to those three
 * content_scripts entries; each of them calls these directly.
 *
 * Only the definitions that were IDENTICAL across the copies live here.
 * Per-platform helpers that diverge (crmSync's context guard, the local delay
 * jitter, the twitter isAlive() guard) intentionally stay in their own files.
 */

// ── Humanization helpers ─────────────────────────────────────────────
function humanDelay(meanMs, stdDev = null) {
  const sd = stdDev || meanMs * 0.3;
  const u1 = Math.random(),
    u2 = Math.random();
  const z = Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
  let ms = meanMs + z * sd;
  const roll = Math.random();
  if (roll > 0.9)
    ms *= 1.8 + Math.random() * 0.5; // 10% long pause
  else if (roll > 0.7) ms *= 0.4 + Math.random() * 0.2; // 20% quick burst
  ms = Math.max(500, Math.min(ms, meanMs * 4));
  return new Promise((r) => setTimeout(r, Math.round(ms)));
}
function sessionWarmup(i) {
  return i < 3 ? 1.8 : i < 8 ? 1.3 : 1.0;
}
async function maybeFatiguePause(i) {
  if (i > 20 && Math.random() < 0.15)
    await new Promise((r) => setTimeout(r, 8000 + Math.random() * 7000));
}
