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.
This commit is contained in:
1 parent
ddec75b99e
commit
2edbc39805
12 files changed
+346
-20
No files matched your search
@@ -0,0 +1,97 @@
|
||||
/* install-tip.js — แนะนำทางติดตั้งที่ผ่านการตรวจของระบบ
|
||||
*
|
||||
* ทำไมต้องมี: Samsung Internet สร้าง WebAPK ด้วย targetSdkVersion เก่า ทำให้ Android 14+
|
||||
* (One UI 9 / Android 16) ขึ้นกล่อง Google Play Protect ว่า "แอปสร้างสำหรับ Android รุ่นเก่า
|
||||
* และไม่มีการป้องกันความเป็นส่วนตัวล่าสุด" แล้วบล็อกการติดตั้ง — เป็นปัญหาของตัวเบราว์เซอร์
|
||||
* ไม่ใช่ของเว็บ (Chrome บนเครื่องเดียวกันติดตั้งได้ปกติ)
|
||||
* → ตรวจ UA แล้วพาไปติดตั้งผ่าน Chrome แทน พร้อมคัดลอกลิงก์ไว้เปิดเอง
|
||||
*/
|
||||
|
||||
const DISMISS_KEY = "hobbypj.install.tip.dismissed.v1";
|
||||
|
||||
function isSamsungInternet() {
|
||||
return /SamsungBrowser\//i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
function isStandalone() {
|
||||
return (
|
||||
window.matchMedia("(display-mode: standalone)").matches ||
|
||||
window.matchMedia("(display-mode: minimal-ui)").matches ||
|
||||
navigator.standalone === true
|
||||
);
|
||||
}
|
||||
|
||||
function isAndroid() {
|
||||
return /Android/i.test(navigator.userAgent);
|
||||
}
|
||||
|
||||
/** intent เปิดลิงก์เดียวกันด้วย Chrome (ถ้าเครื่องมี Chrome) */
|
||||
function chromeIntent(url) {
|
||||
const clean = url.replace(/^https?:\/\//i, "");
|
||||
return `intent://${clean}#Intent;scheme=https;package=com.android.chrome;end`;
|
||||
}
|
||||
|
||||
function dismissed() {
|
||||
try {
|
||||
return localStorage.getItem(DISMISS_KEY) === "1";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function rememberDismissed() {
|
||||
try {
|
||||
localStorage.setItem(DISMISS_KEY, "1");
|
||||
} catch {
|
||||
/* เก็บไม่ได้ก็ไม่เป็นไร */
|
||||
}
|
||||
}
|
||||
|
||||
/** เรียกตอนบูต — แสดงคำแนะนำเฉพาะ Samsung Internet ที่ยังไม่ได้ติดตั้ง */
|
||||
export function initInstallTip() {
|
||||
if (!isAndroid() || !isSamsungInternet() || isStandalone() || dismissed()) return null;
|
||||
const host = document.getElementById("install-tip");
|
||||
if (!host) return null;
|
||||
|
||||
const currentUrl = location.href;
|
||||
host.innerHTML = `
|
||||
<div class="notice" role="status">
|
||||
<div class="notice__body">
|
||||
<p class="notice__title">ติดตั้งผ่าน Samsung Internet ยังถูกบล็อก</p>
|
||||
<p class="notice__text">
|
||||
Android ขึ้นเตือนว่า “ไม่มีการป้องกันความเป็นส่วนตัวล่าสุด” เพราะ Samsung Internet
|
||||
สร้างแพ็กเกจติดตั้งเวอร์ชันเก่า (ไม่ใช่ปัญหาของเว็บนี้) — เปิดลิงก์เดียวกันด้วย Chrome
|
||||
แล้วเลือก “ติดตั้งแอป” จะติดตั้งได้ปกติ
|
||||
</p>
|
||||
<div class="notice__actions">
|
||||
<a class="btn btn--primary btn--sm" href="${chromeIntent(currentUrl)}">เปิดด้วย Chrome</a>
|
||||
<button class="btn btn--quiet btn--sm" type="button" data-act="copy">คัดลอกลิงก์</button>
|
||||
<button class="btn btn--quiet btn--sm" type="button" data-act="dismiss">ปิดข้อความนี้</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
host.hidden = false;
|
||||
|
||||
host.addEventListener("click", async (event) => {
|
||||
const action = event.target.closest("[data-act]")?.dataset.act;
|
||||
if (!action) return;
|
||||
if (action === "dismiss") {
|
||||
rememberDismissed();
|
||||
host.hidden = true;
|
||||
host.replaceChildren();
|
||||
return;
|
||||
}
|
||||
if (action === "copy") {
|
||||
try {
|
||||
await navigator.clipboard.writeText(currentUrl);
|
||||
event.target.textContent = "คัดลอกแล้ว";
|
||||
} catch {
|
||||
/* Safari/เบราว์เซอร์ที่ไม่ให้ clipboard — ผู้ใช้คัดลอกจาก address bar เองได้ */
|
||||
window.prompt("คัดลอกลิงก์นี้ไปเปิดใน Chrome", currentUrl);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return host;
|
||||
}
|
||||
Reference in new issue
Block a user