This commit is contained in:
@@ -2,6 +2,7 @@ import { ref } from "vue"
|
||||
import { getMaxkb, postMaxkb } from "../api"
|
||||
|
||||
const enabled = ref(true)
|
||||
let observer: MutationObserver | null = null
|
||||
|
||||
function applyState() {
|
||||
document.querySelectorAll<HTMLElement>("body > [id^='maxkb-']").forEach(el => {
|
||||
@@ -9,6 +10,14 @@ function applyState() {
|
||||
})
|
||||
}
|
||||
|
||||
function startObserver() {
|
||||
if (observer) return
|
||||
observer = new MutationObserver(() => {
|
||||
if (!enabled.value) applyState()
|
||||
})
|
||||
observer.observe(document.body, { childList: true })
|
||||
}
|
||||
|
||||
export async function fetchMaxkbState() {
|
||||
try {
|
||||
const res = await getMaxkb()
|
||||
@@ -26,5 +35,6 @@ export async function toggleMaxkb() {
|
||||
}
|
||||
|
||||
export function initMaxkb() {
|
||||
startObserver()
|
||||
fetchMaxkbState()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user