diff --git a/static/app.js b/static/app.js index 84ea647..b32d000 100644 --- a/static/app.js +++ b/static/app.js @@ -32,6 +32,7 @@ const THEMES = [ { id: "sunset", label: "Sunset", dark: true, dots: ["#1c1018", "#251420", "#f472b6", "#fb923c"] }, ]; const THEME_CONFIG_KEY = "snotes-theme-config"; +const PREVIEW_KEY = "snotes-preview"; const themeMQ = window.matchMedia("(prefers-color-scheme: dark)"); function findTheme(id) { return THEMES.find((t) => t.id === id); } @@ -499,7 +500,10 @@ function renderEditor(body, owner) { const editorArea = el("div", { class: "editor" }); const previewArea = el("div", { class: "preview" }); const split = el("div", { class: "editor-split" }, [editorArea, previewArea]); - const previewBtn = el("button", { class: "btn ghost preview-toggle active", text: "Preview", title: "Toggle live preview", onclick: () => { split.classList.toggle("preview-hidden"); previewBtn.classList.toggle("active"); } }); + let previewOn = true; + try { previewOn = localStorage.getItem(PREVIEW_KEY) !== "off"; } catch (e) {} + const previewBtn = el("button", { class: "btn ghost preview-toggle" + (previewOn ? " active" : ""), text: "Preview", title: "Toggle live preview", onclick: () => { split.classList.toggle("preview-hidden"); previewBtn.classList.toggle("active"); try { localStorage.setItem(PREVIEW_KEY, previewBtn.classList.contains("active") ? "on" : "off"); } catch (e) {} } }); + if (!previewOn) split.classList.add("preview-hidden"); const status = el("div", { class: "status", text: "" }); const hint = el("div", { class: "editor-hint" }, [ el("p", { html: 'Tags: type #tag anywhere in your note to add a tag.' }),