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 @@