mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2025-04-20 01:26:43 +00:00
52 lines
1.2 KiB
JavaScript
52 lines
1.2 KiB
JavaScript
const elems = [
|
|
document.querySelector("#name"),
|
|
document.querySelector("#note"),
|
|
document.querySelector("#theme"),
|
|
document.querySelector("#log-level"),
|
|
document.querySelector("#whitelist-enabled"),
|
|
document.querySelector("#approval-required")
|
|
]
|
|
|
|
|
|
async function handle_config_change(event) {
|
|
params = {
|
|
key: event.target.id,
|
|
value: event.target.type === "checkbox" ? event.target.checked : event.target.value
|
|
}
|
|
|
|
try {
|
|
await request("POST", "v1/config", params);
|
|
|
|
} catch (error) {
|
|
toast(error);
|
|
return;
|
|
}
|
|
|
|
if (params.key === "name") {
|
|
document.querySelector("#header .title").innerHTML = params.value;
|
|
document.querySelector("title").innerHTML = params.value;
|
|
}
|
|
|
|
if (params.key === "theme") {
|
|
document.querySelector("link.theme").href = `/theme/${params.value}.css`;
|
|
}
|
|
|
|
toast("Updated config", "message");
|
|
}
|
|
|
|
|
|
document.querySelector("#name").addEventListener("keydown", async (event) => {
|
|
if (event.which === 13) {
|
|
await handle_config_change(event);
|
|
}
|
|
});
|
|
|
|
document.querySelector("#note").addEventListener("keydown", async (event) => {
|
|
if (event.which === 13 && event.ctrlKey) {
|
|
await handle_config_change(event);
|
|
}
|
|
});
|
|
|
|
for (const elem of elems) {
|
|
elem.addEventListener("change", handle_config_change);
|
|
}
|