console.log("Script running 123"); (function initStandaloneRegistration() { const READY_CHECK_LIMIT = 50; let attempts = 0;
function waitForElements() { const modal = document.querySelector(".modal-body"); const emailInput = document.getElementById("shortRegEmail"); const passwordInput = document.getElementById("shortRegPassword"); const termsCheckbox = document.getElementById("termsCheckbox"); const regButton = document.getElementById("shortRegButton"); const passwordToggle = document.getElementById("passwordToggle"); const livechatLink = document.querySelector(".modal-input__footer--live"); const loginCta = document.querySelector(".modal-input__footer--login"); const closeBtn = document.querySelector(".modal-input__header--close");
if (!modal || !emailInput || !passwordInput || !termsCheckbox || !regButton || !passwordToggle) { if (attempts++ < READY_CHECK_LIMIT) { console.log("[REG] waiting for modal elements", attempts); setTimeout(waitForElements, 100); } else { console.error("[REG] modal elements not found, aborting init"); } return; } console.log("[REG] modal elements ready"); attachHandlers({ modal, emailInput, passwordInput, termsCheckbox, regButton, passwordToggle, livechatLink, loginCta, closeBtn }); } function attachHandlers(ctx) { const { modal, emailInput, passwordInput, termsCheckbox, regButton, passwordToggle, livechatLink, loginCta, closeBtn } = ctx; const emailError = document.getElementById("regError-Email"); const passError = document.getElementById("regError-Password"); const generalError = document.getElementById("regError-general"); window.__ls = window.__ls || function () { console.log("[REG] __ls stub", Array.from(arguments)); }; function setCookie(name, value, days) { const now = new Date(); const expires = days ? new Date(now.getTime() + days * 864e5).toUTCString() : "Fri, 31 Dec 9999 23:59:59 GMT"; document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`; } function getCookie(name) { return document.cookie.split("; ").reduce((acc, item) => { const [key, val] = item.split("="); return key === name ? decodeURIComponent(val) : acc; }, ""); }
function getRegionName() { const locale = (navigator.language || "en-US").split("-")[1] || "US"; try { return new Intl.DisplayNames(["en"], { type: "region" }).of(locale.toUpperCase()) || "Unknown"; } catch (err) { console.warn("[REG] region lookup failed", err); return "Unknown"; } }
function showError(target, message) { target.textContent = message || ""; target.style.opacity = message ? "1" : "0"; }
regButton.disabled = false;
emailInput.addEventListener("input", () => { emailInput.style.borderColor = "#28a745"; showError(emailError, ""); });
passwordInput.addEventListener("input", () => { passwordInput.style.borderColor = "#28a745"; showError(passError, ""); });
termsCheckbox.addEventListener("change", () => { console.log("[REG] terms changed", termsCheckbox.checked); });
passwordToggle.addEventListener("click", () => { const next = passwordInput.type === "password" ? "text" : "password"; passwordInput.type = next; passwordToggle.src = next === "password" ? "/Misc/betplays/img/hide.png" : "/Misc/betplays/img/show.png"; console.log("[REG] password toggle", next); });
if (closeBtn) { closeBtn.addEventListener("click", () => console.log("[REG] close clicked")); } if (loginCta) { loginCta.addEventListener("click", () => console.log("[REG] login CTA clicked")); } if (livechatLink) { livechatLink.addEventListener("click", (e) => { e.preventDefault(); console.log("[REG] livechat CTA"); }); }
regButton.addEventListener("click", async () => { const shortEmail = emailInput.value.trim(); const password = passwordInput.value;
console.log("[REG] submit click", { shortEmailLength: shortEmail.length, passwordLength: password.length, termsChecked: termsCheckbox.checked });
showError(emailError, ""); showError(passError, ""); showError(generalError, "");
if (!shortEmail || !password) { showError(generalError, "Email and password are required to continue."); console.warn("[REG] missing credentials"); return; }
if (!termsCheckbox.checked) { showError(generalError, "Please accept the terms and conditions."); console.warn("[REG] terms unchecked"); return; }
try { regButton.disabled = true; regButton.textContent = "Processing...";
const urlParams = new URLSearchParams(window.location.search); const btag = urlParams.get("btag");
const registrationBody = { site: "betplays", referrer: document.referrer || "", landingpage: window.location.href, currency: "", user: { email: shortEmail, password } };
if (btag) { registrationBody.btag = btag; }
console.log("[REG] registration payload", registrationBody);
const registrationResponse = await fetch("https://bsapi.visitsfilter.com/wp-json/api/v1/register-user", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(registrationBody), redirect: "follow" });
const registrationResult = await registrationResponse.json(); console.log("[REG] registration response", registrationResult);
if (!registrationResult.success) { throw new Error(registrationResult.message || "Registration failed"); }
const username = registrationResult.user?.userName; if (!username) { throw new Error("Missing username in registration response"); }
console.log("[REG] username extracted", username); console.log("[REG] fetching login token");
const loginPageResponse = await fetch("/Login/Login"); const loginPageHtml = await loginPageResponse.text(); const tokenMatch = loginPageHtml.match(/__RequestVerificationToken.*?value="([^"]+)"/); const verificationToken = tokenMatch ? tokenMatch[1] : null;
if (!verificationToken) { throw new Error("Verification token missing"); }
console.log("[REG] token ready"); const loginData = new URLSearchParams({ Email: username, Password: password, __RequestVerificationToken: verificationToken });
const loginResponse = await fetch("/Login/Login", { method: "POST", headers: { "Content-Type": "application/x-www-form-urlencoded" }, body: loginData });
if (!loginResponse.ok) { throw new Error(`Login failed: ${loginResponse.status} ${loginResponse.statusText}`); }
console.log("[REG] login success");
setCookie("setXtreempushRegData", password, 10);
const livesessionParams = {}; const urlSearch = new URLSearchParams(window.location.search); const existingBtag = getCookie("btag") || btag || "Direct"; if (existingBtag) { livesessionParams.btag = existingBtag; const parts = existingBtag.split("_"); livesessionParams.aff_id = parts.length > 1 ? parts[1] : parts[0]; }
["campaign_id", "utm_section", "utm_medium", "afp", "afp1", "afp2"].forEach((key) => { const val = urlSearch.get(key); if (val) { livesessionParams[key] = val; } });
__ls("identify", { params: { ...livesessionParams, country: getRegionName(), currency: "USD" } });
if (window.location.href.includes("wtg")) { const wtgParams = new URLSearchParams(window.location.search); setCookie("wtg", wtgParams.get("wtg") || "", 0.2); }
alert("Registration and login successful! Redirecting..."); window.location.href = "/?deposit=1"; } catch (err) { console.error("[REG] error", err); showError(generalError, err.message || "Unexpected error"); alert(`Error: ${err.message}`); } finally { regButton.textContent = "FREE SIGN UP"; regButton.disabled = false; } });
console.log("[REG] handlers attached"); }
waitForElements(); })();