const endpoint = @json(route('bridge.scan.register')); const identifier = @json($code ?? null); const scanMessages = { retry: @json(__('public_profile_messages.scan_notice.retry')), dismiss: @json(__('public_profile_messages.scan_notice.dismiss')), permissionTitle: @json(__('public_profile_messages.scan_notice.permission_title')), permissionMessage: @json(__('public_profile_messages.scan_notice.permission_message')), unavailableTitle: @json(__('public_profile_messages.scan_notice.unavailable_title')), unavailableMessage: @json(__('public_profile_messages.scan_notice.unavailable_message')), timeoutTitle: @json(__('public_profile_messages.scan_notice.timeout_title')), timeoutMessage: @json(__('public_profile_messages.scan_notice.timeout_message')), }; const scanAttemptTtlMs = 30 * 60 * 1000; const scanAttemptStorageKey = `mycode:scan-attempted:${identifier}`; let notice = null; let permissionStatus = null; let scanRegistered = false; let triedHighAccuracy = false; let locationRequestInFlight = false; if (!identifier || typeof navigator === 'undefined' || !navigator.geolocation) { return; } const sessionStore = () => { try { return window.sessionStorage; } catch (error) { return null; } }; const hasRecentScanAttempt = () => { const store = sessionStore(); if (!store) { return false; } const timestamp = Number(store.getItem(scanAttemptStorageKey)); if (!Number.isFinite(timestamp)) { return false; } if (Date.now() - timestamp <= scanAttemptTtlMs) { return true; } store.removeItem(scanAttemptStorageKey); return false; }; const rememberScanAttempt = () => { const store = sessionStore(); if (!store) { return; } store.setItem(scanAttemptStorageKey, String(Date.now())); }; const dismissNotice = () => { if (notice) { notice.remove(); notice = null; } }; const dispatchLocationEvent = (name, detail = {}) => { if (typeof window === 'undefined') { return; } window.dispatchEvent(new CustomEvent(name, { detail })); };