Files
hobbypj-contents/ui/app.js
T
Bkk1234 2edbc39805 feat(privacy): privacy page, security headers, Chrome fallback for Samsung installs
The 'privacy' refusal on the S23 is Google Play Protect blocking the WebAPK that
Samsung Internet mints (old targetSdkVersion) — a browser-side bug that also hits
other PWAs; Chrome on the same device installs fine. So:

- ui/install-tip.js: detect Samsung Internet on Android and offer the same URL in
  Chrome (intent:// link, copy-link fallback, dismissable, remembered)
- ui/views/privacy.js + #/privacy route + footer link: Thai privacy policy (what is
  stored locally, no cookies/analytics/third-party scripts, how to delete)
- server/publish.mjs: CSP (script-src 'self', style-src 'self' 'unsafe-inline'),
  Referrer-Policy, Permissions-Policy, X-Content-Type-Options on every response
- ui/boot-motion.js: the head inline script moved out so CSP can forbid inline JS
- ui/data.js: admin publish token now lives in sessionStorage (was localStorage)
- theme.css: .notice / .legal components (44px targets), DESIGN.md + README + AGENTS

Verified: installabilityErrors [], fonts load under CSP, all requests same-origin,
notice renders under the header at 360px with 44px buttons and stays dismissed,
privacy page renders 5 sections. VERSION 2026.11.24.6.
2026-11-24 15:10:32 +07:00

92 lines
2.9 KiB
JavaScript

/* app.js — จุดเริ่มของแอป: โหลดข้อมูล → ผูก router → เรนเดอร์หน้า */
import { hydrateIcons, toast } from "./ui.js";
import { loadProjects, normalizeData } from "./data.js";
import { defineRoutes, markActiveNav, onRouteChange, startRouter } from "./router.js";
import { countUpInside, initMotion, initReveal } from "./motion.js";
import { homeView } from "./views/home.js";
import { adminView } from "./views/admin.js";
import { privacyView } from "./views/privacy.js";
import { initInstallTip } from "./install-tip.js";
import "./pwa.js";
const main = document.getElementById("main");
const state = {
data: normalizeData({}),
source: "empty",
};
const ctx = {
get data() {
return state.data;
},
get source() {
return state.source;
},
setData(data) {
state.data = normalizeData(data);
state.source = "server";
},
async reload() {
const result = await loadProjects();
state.data = result.data;
state.source = result.source;
return result;
},
};
let activeView = null;
const TITLES = {
"/": "โปรเจคอดิเรกของเรา",
"/admin": "จัดการข้อมูล · โปรเจคอดิเรก",
"/privacy": "ความเป็นส่วนตัว · โปรเจคอดิเรก",
};
function renderRoute({ path, view }) {
if (activeView && typeof activeView.destroy === "function") activeView.destroy();
main.replaceChildren();
activeView = view(ctx);
activeView.mount(main);
markActiveNav(path);
document.title = TITLES[path] || TITLES["/"];
window.scrollTo({ top: 0, behavior: "auto" });
main.focus({ preventScroll: true });
initReveal(main);
countUpInside(main);
}
function skeleton() {
main.innerHTML = `
<div class="wrap">
<div class="hero" style="min-height:280px"></div>
<div class="loading" aria-hidden="true">
<div class="skeleton"></div><div class="skeleton"></div><div class="skeleton"></div>
</div>
<p class="visually-hidden" role="status">กำลังโหลดรายชื่อโปรเจค</p>
</div>`;
}
async function boot() {
hydrateIcons();
initMotion();
skeleton();
const result = await loadProjects();
state.data = result.data;
state.source = result.source;
defineRoutes({ "/": homeView, "/admin": adminView, "/privacy": privacyView }, "/");
onRouteChange(renderRoute);
startRouter();
initInstallTip();
if (result.source === "cache") {
toast("เปิดแบบออฟไลน์ — แสดงข้อมูลที่บันทึกไว้ในเครื่อง");
} else if (result.source === "empty") {
toast("อ่านข้อมูลโปรเจคไม่ได้ — เข้าไปเพิ่มรายการได้ที่หน้า “จัดการข้อมูล”", "error");
}
}
boot();