function generateMathCaptcha() { const num1 = Math.floor(Math.random() * 10) + 1; const num2 = Math.floor(Math.random() * 10) + 1; const operators = ["+", "-"]; const operator = operators[Math.floor(Math.random() * operators.length)]; let question = `${num1} ${operator} ${num2} = ?`; let answer; if (operator === "+") { answer = num1 + num2; } else { answer = num1 - num2; } return { question, answer, num1, num2, operator }; } function updateMathCaptcha() { const { question, answer, num1, num2, operator } = generateMathCaptcha(); const deg1 = Math.floor(Math.random() * 45) + 1; const deg2 = Math.floor(Math.random() * 45) + 1; document.getElementById("one").textContent = num1; document.getElementById("one").style.transform = `skew(${deg1}deg)`; document.getElementById("two").textContent = operator; document.getElementById("three").textContent = num2; document.getElementById("three").style.transform = `skew(-${deg2}deg)`; return answer; } let correctAnswer = updateMathCaptcha(); document.getElementById("mathCaptchaCheck").addEventListener("click", () => { const userInput = document.getElementById("mathCaptchaInput").value; const resultDiv = document.getElementById("mathCaptchaResult"); if (parseInt(userInput) === correctAnswer) { resultDiv.textContent = "✅ Correct!"; resultDiv.style.color = "green"; window.location.href = window.location.href + '?come_from=web'; } else { resultDiv.textContent = "❌ Error, please try again!"; resultDiv.style.color = "red"; } }); document.getElementById("captchaRefresh").addEventListener("click", () => { correctAnswer = updateMathCaptcha(); document.getElementById("mathCaptchaResult").textContent = ""; document.getElementById("mathCaptchaInput").value = ""; }); const captchaInput = document.getElementById("mathCaptchaInput"); captchaInput.addEventListener('keydown', (event) => { if (event.key === 'Enter') { const userInput = document.getElementById("mathCaptchaInput").value; const resultDiv = document.getElementById("mathCaptchaResult"); if (parseInt(userInput) === correctAnswer) { resultDiv.textContent = "✅ Correct!"; resultDiv.style.color = "green"; window.location.href = window.location.href + '?come_from=web'; } else { resultDiv.textContent = "❌ Error, please try again!"; resultDiv.style.color = "red"; } } });