From 96f6be8dbef248079d5d949aa0861719409d6b4e Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Mon, 27 Apr 2026 08:57:41 -0600 Subject: [PATCH] add maxkb toggle --- src/api.ts | 10 ++++++++++ src/composables/maxkb.ts | 30 ++++++++++++++++++++++++++++++ src/desktop/index.vue | 9 +++++++-- 3 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/composables/maxkb.ts diff --git a/src/api.ts b/src/api.ts index cbd3b0c..f1af08c 100644 --- a/src/api.ts +++ b/src/api.ts @@ -126,6 +126,16 @@ export async function removeCode(id: number) { await api.delete(`/${id}`) } +export async function getMaxkb(): Promise<{ enabled: boolean }> { + const res = await api.get("/maxkb") + return res.data +} + +export async function postMaxkb(): Promise<{ enabled: boolean }> { + const res = await api.post("/maxkb") + return res.data +} + export async function debug(code: string, inputs: string[]) { const res = await api.post("/debug", { code, diff --git a/src/composables/maxkb.ts b/src/composables/maxkb.ts new file mode 100644 index 0000000..cf579b8 --- /dev/null +++ b/src/composables/maxkb.ts @@ -0,0 +1,30 @@ +import { ref } from "vue" +import { getMaxkb, postMaxkb } from "../api" + +const enabled = ref(true) + +function applyState() { + document.querySelectorAll("body > [id^='maxkb-']").forEach(el => { + el.style.display = enabled.value ? "" : "none" + }) +} + +export async function fetchMaxkbState() { + try { + const res = await getMaxkb() + enabled.value = res.enabled + applyState() + } catch {} +} + +export async function toggleMaxkb() { + try { + const res = await postMaxkb() + enabled.value = res.enabled + applyState() + } catch {} +} + +export function initMaxkb() { + fetchMaxkbState() +} diff --git a/src/desktop/index.vue b/src/desktop/index.vue index 702c90c..6857072 100644 --- a/src/desktop/index.vue +++ b/src/desktop/index.vue @@ -22,17 +22,20 @@