From 7c39ad7c3cc3b06903b5ea925419140ae8140d2f Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Wed, 19 Oct 2022 21:05:24 +0400 Subject: [PATCH] Added CAPTCHA's styling based on prefers-color-scheme media query. --- homepage/static/assets/js/captcha_refresh.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homepage/static/assets/js/captcha_refresh.js b/homepage/static/assets/js/captcha_refresh.js index dc2a7b9..47dcbc2 100644 --- a/homepage/static/assets/js/captcha_refresh.js +++ b/homepage/static/assets/js/captcha_refresh.js @@ -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; }