33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { render } from "preact";
|
|
import { RootRouter } from "@/root-router";
|
|
import { registerServiceWorker } from "@/pwa";
|
|
import { persistUiModePreference, readUiModePreference, resolveUiRoute } from "@/lib/ui-mode";
|
|
import "./typography.css";
|
|
|
|
// Both presentations use the same fonts. A blocked CDN does not block the UI.
|
|
const fonts = document.createElement("link");
|
|
fonts.rel = "stylesheet";
|
|
fonts.href = "https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Orbitron:wght@700;800;900&display=swap";
|
|
document.head.appendChild(fonts);
|
|
|
|
let storage: Storage | null = null;
|
|
try { storage = window.localStorage; } catch { /* Storage may be unavailable in private browsing. */ }
|
|
const connection = (navigator as Navigator & { connection?: { saveData?: boolean } }).connection;
|
|
const route = resolveUiRoute(window.location, {
|
|
userAgent: navigator.userAgent,
|
|
saveData: connection?.saveData,
|
|
}, readUiModePreference(storage));
|
|
if (route.preference) persistUiModePreference(storage, route.preference);
|
|
if (route.url !== `${window.location.pathname}${window.location.search}${window.location.hash}`) {
|
|
window.history.replaceState(window.history.state, "", route.url);
|
|
}
|
|
|
|
if (route.mode === "lite") {
|
|
document.querySelector('meta[name="viewport"]')?.setAttribute("content", "width=device-width, initial-scale=1, viewport-fit=cover");
|
|
document.querySelector('meta[name="theme-color"]')?.setAttribute("content", "#ffffff");
|
|
} else {
|
|
registerServiceWorker();
|
|
}
|
|
|
|
render(<RootRouter />, document.getElementById("app")!);
|