(() => { 'use strict'; const nativeFetch = window.fetch.bind(window); const json = (payload, status = 200) => new Response(JSON.stringify(payload), { status, headers: { 'content-type': 'application/json; charset=utf-8' } }); const keyFor = value => { const u = new URL(value, location.origin); u.searchParams.sort(); return u.pathname + u.search; }; const read = (key, fallback) => { try { return JSON.parse(localStorage.getItem(key) || 'null') || fallback; } catch { return fallback; } }; const save = (key, value) => { try { localStorage.setItem(key, JSON.stringify(value)); } catch {} }; let manifestPromise; const manifest = () => manifestPromise ||= nativeFetch('/data/api-manifest.json').then(r => r.json()); const messages = { zh: '已保存到此浏览器。本地静态演示,不会向原站提交。', en: 'Saved in this browser only. Static demo; nothing was submitted to the original website.', ru: 'Сохранено только в этом браузере. Статическая демоверсия; данные не отправлены на исходный сайт.' }; const locale = () => document.documentElement.lang.startsWith('ru') ? 'ru' : document.documentElement.lang.startsWith('en') ? 'en' : 'zh'; window.CARDNAV_STATIC = { version: '1.0.0', dataMode: 'snapshot', backend: false }; // Suppress tracking and counters. All local UI, favorites and converters remain operational. const noop = () => {}; window.umami = { track: noop }; try { navigator.sendBeacon = () => true; } catch {} function showIpDemoNotice(event) { const target = event.target instanceof Element ? event.target : null; if (!target || (target.id !== 'ipPurityForm' && !target.closest('#ipPurityDetectCurrent'))) return; event.preventDefault(); event.stopImmediatePropagation(); const note = locale()==='zh' ? '静态演示版:实时 IP 信誉查询未启用。' : 'Static demo: live IP reputation checks are not enabled.'; const error = document.querySelector('#ipPurityError'); if (error) { error.textContent = note; error.classList.remove('hidden'); } const status = document.querySelector('#ipPurityStatus'); if (status) status.textContent = note; } document.addEventListener('submit', showIpDemoNotice, true); document.addEventListener('click', showIpDemoNotice, true); window.fetch = async (input, options = {}) => { const url = new URL(typeof input === 'string' || input instanceof URL ? input : input.url, location.href); const method = (options.method || (input instanceof Request ? input.method : 'GET')).toUpperCase(); if (url.origin !== location.origin) { if (/analytics|umami|googletagmanager|beacon|collect/.test(url.href)) return new Response(null, {status:204}); if (location.pathname.includes('/tools/ip-purity')) return json({ok:false, message:'静态演示版不进行实时 IP 风险查询。'}, 200); return nativeFetch(input, options); } const isApi = url.pathname.startsWith('/api/') || url.pathname.startsWith('/fragments/') || url.pathname.endsWith('-search.json'); if (!isApi) return nativeFetch(input, options); if (url.pathname === '/api/shop-products-page.json' || url.pathname === '/api/shop-merchants.json') { let body = {}; try { body = JSON.parse(options.body || '{}'); } catch {} const adapter = await import('/market-adapter.js'); return json(await adapter.respond(url.pathname, url.searchParams, body)); } if (method !== 'GET' && method !== 'HEAD') { if (/shop-submit|gateway-submit|\/submit$/.test(url.pathname)) { let payload = {}; try { payload = JSON.parse(options.body || '{}'); } catch {} const submissions = read('cardnav.static.submissions', []); submissions.push({ ...payload, kind: url.pathname.includes('gateway') ? 'gateway' : 'shop', savedAt: new Date().toISOString() }); save('cardnav.static.submissions', submissions); return json({ok:true, message:messages[locale()], url:payload.url || ''}); } if (url.pathname.startsWith('/api/support')) return json({ok:false,message:locale()==='zh'?'静态演示版不创建真实订单或付款。':'Payments are not enabled in the static demo.'}); if (url.pathname.includes('shop-favorites')) return json({ok:true}); return new Response(null, {status:204}); } if (url.pathname === '/api/ip-purity/check') return json({ok:false, message: locale()==='zh'?'当前为纯静态演示版,仅复刻检测界面;实时 IP 信誉数据需要查询服务。':'Static demo: live IP reputation requires a query service.'}); const index = await manifest(); let item = index[keyFor(url)]; if (!item) item = index[url.pathname]; if (!item) { const candidates = Object.entries(index).filter(([key]) => key.split('?')[0] === url.pathname); item = candidates.find(([key]) => new URL(key,location.origin).searchParams.get('locale') === locale())?.[1] || candidates[0]?.[1]; } if (!item) { if (url.pathname === '/api/support/sites') return json({ok:true,sites:[]}); return json({ok:false, message:'此内容未包含在离线快照中。',items:[],totalCount:0}); } const response = await nativeFetch(item.file, { signal: options.signal }); if (url.pathname === '/api/shop-products.json' && url.searchParams.has('siteId')) { const data = await response.json(); const id = url.searchParams.get('siteId'); const siteIndex = data.s.findIndex(s => s[0] === id); if (siteIndex >= 0) { data.p = data.p.filter(p => p[0] === siteIndex); data.pc = data.p.length; data.sc = 1; data.x = 0; data.l = null; } return json(data); } return new Response(await response.arrayBuffer(), {status:response.status,headers:{'content-type':item.type}}); }; })();