// A small, dismissible "Add to Home Screen" hint for iPhone/iPad visitors. // // iOS only grants Web Push to a site the user has added to the Home Screen via // Safari's Share sheet (iOS 16.4+). There is no beforeinstallprompt on iOS, so // the only nudge available is telling people where the control is. This module // shows that nudge — and only when it can actually help: real iOS Safari, not // already installed, not previously dismissed. Everything degrades to nothing. // Not the "tg:" prefix — cache.js sweeps that namespace on every load. The // durable app preferences ("thermograph:unit", "thermograph:loc") use this one. const KEY = "thermograph:ios-a2hs"; function isIOS() { const ua = navigator.userAgent || ""; // iPadOS 13+ reports as "Macintosh"; a touch point count disambiguates it. return /iphone|ipad|ipod/i.test(ua) || (/Macintosh/.test(ua) && (navigator.maxTouchPoints || 0) > 1); } function isStandalone() { return window.navigator.standalone === true || (window.matchMedia && window.matchMedia("(display-mode: standalone)").matches); } function isSafari() { // Add to Home Screen only works from Safari proper — not Chrome (CriOS), // Firefox (FxiOS), Edge (EdgiOS), Opera (OPiOS), or most in-app webviews. const ua = navigator.userAgent || ""; if (/crios|fxios|edgios|opios/i.test(ua)) return false; return /safari/i.test(ua); } function dismissed() { try { return localStorage.getItem(KEY) === "off"; } catch (e) { return false; } } function remember() { try { localStorage.setItem(KEY, "off"); } catch (e) {} } function build() { const el = document.createElement("div"); el.className = "ios-a2hs"; el.setAttribute("role", "note"); el.setAttribute("aria-label", "Install Thermograph on your Home Screen"); // The share glyph mirrors iOS's own Share icon so the instruction is scannable. el.innerHTML = '' + '