Compare commits

...

2 Commits

2 changed files with 18 additions and 26 deletions

View File

@ -1,27 +1,20 @@
const g_captcha_timeout_seconds = 600;
const captcha_hidden_field = document.forms[0].children[4].children[0];
const e_captcha = document.getElementsByClassName("captcha")[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";
}
let g_current_captcha_id = e_captcha.children[0].value;
async function getNewCaptcha() {
const id = await fetch("/api/captcha/", { method: "POST"}).then(r => r.text());
g_current_captcha_id = id;
captcha_hidden_field.value = id;
setTimeout(() => { captcha_img.src = `/api/captcha/${id}/image?style=${getColorScheme()}` }, 600);
g_current_captcha_id = e_captcha.children[0].value = id;
const style = window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark";
setTimeout(() => { e_captcha.children[1].src = `/api/captcha/${id}/image?style=${style}` }, 600);
g_captcha_timeout_remain = g_captcha_timeout_seconds;
}
const captcha_span = document.getElementsByClassName("captcha")[0];
const captcha_img = captcha_span.children[1];
captcha_span.classList.toggle("refresh");
captcha_span.children[3].innerHTML =
e_captcha.classList.toggle("refresh");
e_captcha.children[3].innerHTML =
`<button id="refresh">Refresh</button>ed in <b><span id="remain">600</span></b> seconds.`;
const captcha_refresh = document.getElementById("refresh");
@ -30,11 +23,11 @@ const captcha_remain = document.getElementById("remain");
captcha_refresh.classList.toggle("refresh");
captcha_refresh.addEventListener("click", async e => {
e.preventDefault();
captcha_refresh.disabled = true;
e.target.disabled = true;
setTimeout(async () => {
captcha_refresh.disabled = false;
e.target.disabled = false;
await fetch(`/api/captcha/${g_current_captcha_id}?remove`); }, 3000);
document.getElementsByName("captcha_answer")[0].value = "";
e_captcha.children[2].value = "";
await getNewCaptcha();
});

View File

@ -1,13 +1,12 @@
const buttons = document.getElementsByTagName("button");
const articles = document.getElementsByTagName("article");
document.getElementById("filter").classList.remove("hidden");
for (let i = 0; i < buttons.length; ++i)
if (buttons[i].name !== "")
buttons[i].addEventListener("click", e => {
for (let j = 0; j < articles.length; ++j)
if (articles[j].id.startsWith(e.target.name) || e.target.name === "all")
articles[j].classList.remove("hidden");
else
articles[j].classList.add("hidden"); });
function filter(e) {
for (const a of articles)
a.classList.toggle("hidden",
!(e.target.name === "all" || a.id.startsWith(e.target.name)));
}
for (const b of document.getElementsByTagName("button"))
b.addEventListener("click", filter);