feat: pwa and responsive

This commit is contained in:
phattaranun.a committed 2026-09-12 17:21:19 +07:00
1 parent 71dacc0da2
commit 6b612e2758
7 files changed
+269 -18

No files matched your search

+32
View File
@@ -12,6 +12,38 @@
var CHECK_INTERVAL_MS = 30 * 60 * 1000; // ตรวจอัปเดตทุก 30 นาที
/* ---- ปุ่มติดตั้งแอป (ก่อน install prompt) ---- */
var deferredPrompt = null;
var installBtn = null;
function makeInstallBtn() {
var btn = document.createElement("button");
btn.type = "button";
btn.className = "mu-install-btn";
btn.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><path d="m7 10 5 5 5-5"/><path d="M12 15V3"/></svg> ติดตั้งแอป';
btn.addEventListener("click", function () {
if (!deferredPrompt) return;
deferredPrompt.prompt();
deferredPrompt.userChoice.then(function () {
deferredPrompt = null;
if (installBtn) installBtn.style.display = "none";
});
});
document.body.appendChild(btn);
return btn;
}
window.addEventListener("beforeinstallprompt", function (e) {
e.preventDefault();
deferredPrompt = e;
if (!installBtn) installBtn = makeInstallBtn();
installBtn.style.display = "inline-flex";
});
window.addEventListener("appinstalled", function () {
if (installBtn) installBtn.style.display = "none";
});
window.addEventListener("load", function () {
navigator.serviceWorker
.register("./sw.js", { updateViaCache: "none" })