2025-08-11 00:15:58 +02:00
|
|
|
/** biome-ignore-all lint/correctness/noUnusedVariables: utility */
|
|
|
|
|
|
|
|
function storeValue(key, value = false) {
|
|
|
|
if (value === null || value === undefined || value === false) {
|
2025-08-09 21:16:24 +02:00
|
|
|
localStorage.removeItem(key);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage.setItem(key, JSON.stringify(value));
|
|
|
|
}
|
|
|
|
|
|
|
|
function loadValue(key, fallback = false) {
|
|
|
|
const raw = localStorage.getItem(key);
|
|
|
|
|
2025-08-11 00:15:58 +02:00
|
|
|
if (raw === null) {
|
2025-08-09 21:16:24 +02:00
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const value = JSON.parse(raw);
|
|
|
|
|
2025-08-11 00:15:58 +02:00
|
|
|
if (value === null) {
|
2025-08-09 21:16:24 +02:00
|
|
|
throw new Error("no value");
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
|
|
|
} catch {}
|
|
|
|
|
|
|
|
return fallback;
|
|
|
|
}
|
|
|
|
|
2025-08-10 15:53:30 +02:00
|
|
|
function schedule(cb) {
|
|
|
|
if (document.visibilityState === "visible") {
|
|
|
|
requestAnimationFrame(cb);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setTimeout(cb, 80);
|
|
|
|
}
|
|
|
|
|
2025-08-09 21:16:24 +02:00
|
|
|
function uid() {
|
|
|
|
return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function make(tag, ...classes) {
|
|
|
|
const el = document.createElement(tag);
|
|
|
|
|
2025-08-10 16:38:02 +02:00
|
|
|
if (classes.length) {
|
|
|
|
el.classList.add(...classes);
|
|
|
|
}
|
2025-08-09 21:16:24 +02:00
|
|
|
|
|
|
|
return el;
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeHtml(text) {
|
|
|
|
return text
|
|
|
|
.replace(/&/g, "&")
|
|
|
|
.replace(/</g, "<")
|
|
|
|
.replace(/>/g, ">");
|
|
|
|
}
|