Added CAPTCHA's styling based on prefers-color-scheme media query.

This commit is contained in:
Alexander Andreev 2022-10-19 21:05:24 +04:00
parent 28120c8f3a
commit 7c39ad7c3c
Signed by: Arav
GPG Key ID: 0388CC8FAA51063F

View File

@ -5,11 +5,15 @@ const captcha_hidden_field = document.forms[0].children[4].children[0];
let g_captcha_timeout_remain = g_captcha_timeout_seconds;
let g_current_captcha_id = captcha_hidden_field.value;
function getColorScheme() {
return window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
}
async function getNewCaptcha() {
const id = await fetch("/captcha/").then(r => r.text());
g_current_captcha_id = id;
captcha_hidden_field.value = id;
setTimeout(() => { captcha_img.src = `/captcha/${id}/image` }, 600);
setTimeout(() => { captcha_img.src = `/captcha/${id}/image?style=${getColorScheme()}` }, 600);
g_captcha_timeout_remain = g_captcha_timeout_seconds;
}