const check_solution = async (solution) => { const body = { "TotalSum": "78278", "FnNumber": "9960440301173139", "ReceiptOperationType": "1", "DocNumber": "35704", "DocFiscalSign": "4149689833", "Captcha": solution, "DocDateTime": "2022-09-21T20:28:00.000Z" } const result = await fetch("https://check.ofd.ru/Document/FetchReceiptFromFns", { method: "POST", headers: { "Content-Type": "application/json;charset=utf-8", // "Origin": "https://check.ofd.ru" }, body: JSON.stringify(body), }); return result.status != 400; } const get_cookie = (name) => { const cookies = document.cookie.split(';'); for (let i = 0; i < cookies.length; i++) { const cookie = cookies[i].trim(); if (cookie.startsWith(name + '=')) { const value = cookie.substring(name.length + 1); } } } const blobToBase64 = (blob) => { return new Promise((resolve, _) => { const reader = new FileReader(); reader.onloadend = () => resolve(reader.result); reader.readAsDataURL(blob); }); } const show_stats = async () => { const response = await fetch("/api/user/stats", { method: "GET", headers: { 'Content-Type': 'application/json' } }); const stats = (await response.json()).stats; const statsText = document.getElementById("topSolversText"); statsText.innerHTML += '
' stats.top_five.forEach(stat => { statsText.innerHTML += `${stat.username}: ${stat.count}
`; }); statsText.innerHTML += `You have solved ${stats.my_count} captcha(s)` } window.onload = async () => { const inputField = document.getElementById("captcha"); inputField.focus(); // intentionally do not wait for it show_stats(); if (!document.cookie.includes('JWT')) { document.location.href = "/login"; } const response = await fetch("https://check.ofd.ru/api/captcha/common/img"); captcha = await response.blob(); const url = URL.createObjectURL(captcha); document.getElementById("captcha_image").src = url; const form = document.getElementById("captchaForm"); form.addEventListener('submit', async (e) => { e.preventDefault(); // if (!await check_solution(inputField.value)) { // alert("Капча решена неверно") // returnl // } const response = await fetch(`/api/captcha/submit`, {method: "POST", headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ "image": await blobToBase64(captcha), "solution": inputField.value})}); if (response.status == 200) { inputField.value = ""; window.location.reload(); } else { response_json = await response.json() alert(response_json.message) } }); };