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