File size: 1,875 Bytes
d787a09 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | // ParaPilot — small client helpers (theme toggle, first-run modal, examples).
(function () {
"use strict";
// ---- Theme (light/dark) with persistence + system fallback -------------
const root = document.documentElement;
const THEME_KEY = "parapilot-theme";
function applyTheme(theme) {
if (theme === "dark") root.classList.add("dark");
else root.classList.remove("dark");
}
function initTheme() {
const saved = localStorage.getItem(THEME_KEY);
if (saved) {
applyTheme(saved);
} else {
const prefersDark = window.matchMedia("(prefers-color-scheme: dark)").matches;
applyTheme(prefersDark ? "dark" : "light");
}
}
window.toggleTheme = function () {
const isDark = root.classList.toggle("dark");
localStorage.setItem(THEME_KEY, isDark ? "dark" : "light");
};
// ---- First-run disclaimer modal ----------------------------------------
const SEEN_KEY = "parapilot-disclaimer-ack";
window.dismissDisclaimer = function () {
const modal = document.getElementById("disclaimer-modal");
if (modal) modal.classList.add("hidden");
localStorage.setItem(SEEN_KEY, "1");
};
function maybeShowDisclaimer() {
if (localStorage.getItem(SEEN_KEY)) return;
const modal = document.getElementById("disclaimer-modal");
if (modal) modal.classList.remove("hidden");
}
// ---- Ask: clicking an example fills + submits the form ------------------
window.useExample = function (text) {
const input = document.getElementById("question");
if (!input) return;
input.value = text;
const form = document.getElementById("ask-form");
if (form && window.htmx) {
window.htmx.trigger(form, "submit");
}
};
// Initialize theme as early as possible to avoid a flash.
initTheme();
document.addEventListener("DOMContentLoaded", maybeShowDisclaimer);
})();
|