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