Files
elpatron 562a229fa0 Add PWA manifest, service worker, and install hint.
Enables home-screen installation with per-viewer scope and platform-specific guidance in EN/DE.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-20 11:08:32 +02:00

45 lines
1.3 KiB
JavaScript

document.addEventListener("DOMContentLoaded", async () => {
await I18n.init();
applyStaticI18n();
setupLanguage();
await Pwa.init();
setupCreate();
});
function applyStaticI18n() {
document.querySelectorAll("[data-i18n]").forEach((el) => {
el.textContent = t(el.dataset.i18n);
});
}
function setupLanguage() {
const sel = document.getElementById("locale-select");
sel.value = I18n.getPreference();
sel.addEventListener("change", async (e) => {
await I18n.setPreference(e.target.value);
applyStaticI18n();
Pwa.refreshHint();
});
}
function setupCreate() {
const btn = document.getElementById("create-viewer");
const status = document.getElementById("create-status");
btn.addEventListener("click", async () => {
btn.disabled = true;
status.hidden = false;
status.textContent = t("viewer.creating");
status.className = "landing-hint";
try {
const res = await fetch("/api/viewers", { method: "POST" });
const data = await res.json();
if (!res.ok) throw new Error(data.error || t("viewer.createFailed"));
window.location.href = data.url;
} catch (err) {
status.textContent = err.message;
status.className = "landing-hint landing-hint-error";
btn.disabled = false;
}
});
}