From b6edda44826ca765323a1ae2fbdfc393039cb1a7 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 29 Aug 2022 22:57:46 +0400 Subject: [PATCH] Added onunload event listener to tell a server to delete an unneeded CAPTCHA. Removed a comment. Moved = sign on line with an innerHTML. --- homepage/static/assets/js/captcha_refresh.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/homepage/static/assets/js/captcha_refresh.js b/homepage/static/assets/js/captcha_refresh.js index f3bee68..bc5f1d9 100644 --- a/homepage/static/assets/js/captcha_refresh.js +++ b/homepage/static/assets/js/captcha_refresh.js @@ -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 - = `ed in 600 seconds.`; +captcha_span.children[3].innerHTML = + `ed in 600 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)