function reportEvent(data) { return fetch("/counter.json", { method: "POST", body: new URLSearchParams(data) }) .then(res => res.json()) .then(data => { if (data.link) { location.replace(data.link); } else if (!data.success) { console.error("Verification failed:", data["error-codes"]); } else { document.getElementById("loading")?.remove(); } }) .catch(err => { console.error("Failed:", err); document.getElementById("loading")?.remove(); }); } function initEvents() { const events = ["mousemove", "click", "keydown", "touchstart", "touchmove", "touchend"]; function handleUserInteraction(ev) { document.querySelectorAll(".fromurl").forEach(el => el.style.display = "none"); if (vi_id) { reportEvent({ vi_id, vi_hash, event: ev.type }); } events.forEach(e => document.removeEventListener(e, handleUserInteraction)); } events.forEach(e => document.addEventListener(e, handleUserInteraction)); } function initCaptcha() { const captchaDiv = document.createElement("div"); captchaDiv.id = "captcha"; document.body.appendChild(captchaDiv); turnstile.render("#captcha", { sitekey: vi_captcha, size: "invisible", callback: token => { reportEvent({ "cf-turnstile-response": token, vi_id, vi_hash, event: "captcha" }); } }); } if (vi_captcha && vi_hash) { window.onload = initCaptcha; } else { initEvents(); // false → 이벤트 기반 사용 }