Added onunload event listener to tell a server to delete an unneeded CAPTCHA. Removed a comment. Moved = sign on line with an innerHTML.

This commit is contained in:
Alexander Andreev 2022-08-29 22:57:46 +04:00
parent 3892cbbd50
commit b6edda4482
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -17,8 +17,8 @@ const captcha_span = document.getElementsByClassName("captcha")[0];
const captcha_img = captcha_span.children[1];
captcha_span.classList.toggle("refresh");
captcha_span.children[3].innerHTML
= `<button id="refresh">Refresh</button>ed in <b><span id="remain">600</span></b> seconds.`;
captcha_span.children[3].innerHTML =
`<button id="refresh">Refresh</button>ed in <b><span id="remain">600</span></b> seconds.`;
const captcha_refresh = document.getElementById("refresh");
const captcha_remain = document.getElementById("remain");
@ -27,13 +27,15 @@ captcha_refresh.classList.toggle("refresh");
captcha_refresh.addEventListener("click", async e => {
e.preventDefault();
captcha_refresh.disabled = true;
// Checking if CAPTCHA is solved deletes it.
setTimeout(async () => {
captcha_refresh.disabled = false;
await fetch(`/captcha/${g_current_captcha_id}`); }, 3000);
await getNewCaptcha();
});
// Remove unused CAPTCHA on a server.
window.addEventListener("unload", () => fetch(`/captcha/${g_current_captcha_id}`));
setInterval(async () => {
captcha_remain.innerText = --g_captcha_timeout_remain;
if (g_captcha_timeout_remain == 0)