// ── ตรวจอุปกรณ์ / สภาพแวดล้อมการรัน ───────────────────────── const SAMSUNG_MODELS = { "SM-S911": "Galaxy S23", "SM-S916": "Galaxy S23+", "SM-S918": "Galaxy S23 Ultra", "SM-S921": "Galaxy S24", "SM-S926": "Galaxy S24+", "SM-S928": "Galaxy S24 Ultra", "SM-S931": "Galaxy S25", "SM-S936": "Galaxy S25+", "SM-S938": "Galaxy S25 Ultra", "SM-G991": "Galaxy S21", "SM-G996": "Galaxy S21+", "SM-G998": "Galaxy S21 Ultra", "SM-G780": "Galaxy S20 FE", "SM-A546": "Galaxy A54", "SM-A556": "Galaxy A55", }; export function detectDevice() { const ua = navigator.userAgent || ""; const samsung = ua.match(/\b(SM-[A-Z0-9]{3,10})\b/i); const android = ua.match(/Android\s+([\d.]+)/i); const generic = ua.match(/Android[^;]*;\s*([^;)]+?)\s*(?:Build\/|\))/i); const chrome = ua.match(/(Chrome|CriOS)\/([\d.]+)/i); let code = samsung ? samsung[1].toUpperCase() : generic ? generic[1].trim() : ""; let brand = samsung ? "Samsung" : /iPhone/.test(ua) ? "Apple" : generic ? "Android" : "Unknown"; let model = code; if (samsung) { const key = code.slice(0, 8); // SM-S911B → SM-S911 model = SAMSUNG_MODELS[key] ? `Samsung ${SAMSUNG_MODELS[key]}` : `Samsung ${code}`; } else if (/iPhone/.test(ua)) { brand = "Apple"; model = "iPhone"; } return { code: code || "ไม่ทราบรุ่น", brand, model: model || "ไม่ทราบรุ่น", androidVersion: android ? android[1] : null, chromeVersion: chrome ? chrome[2] : null, ua, }; } export function environment() { const d = detectDevice(); const vv = window.visualViewport; return { ...d, url: location.href, secureContext: window.isSecureContext === true, protocol: location.protocol, standalone: window.matchMedia("(display-mode: standalone)").matches, dpr: window.devicePixelRatio, viewport: `${window.innerWidth}×${window.innerHeight}`, visualViewport: vv ? `${Math.round(vv.width)}×${Math.round(vv.height)}` : "—", screen: `${screen.width}×${screen.height}`, safeArea: getComputedStyle(document.documentElement).getPropertyValue("--safe-top").trim() || "0px", touch: navigator.maxTouchPoints > 0, share: !!(navigator.canShare && navigator.share), imageCapture: typeof window.ImageCapture !== "undefined", languages: navigator.languages?.join(", ") || navigator.language, }; } /** นามสกุลอุปกรณ์สำหรับ EXIF Model */ export function exifModelName() { const d = detectDevice(); return d.model || "Samsung Galaxy S23"; }