Repository navigation
Expand file tree
/
Copy pathcomb-sw.js
More file actions
22 lines (22 loc) · 2.9 KB
/
Copy pathcomb-sw.js
File metadata and controls
22 lines (22 loc) · 2.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* Comb Code, Copyright (c) 2026 Avi Shor. Free to use, with or without credit. See LICENSE.md. No warranty. */
// Comb Code offline cache. Same-origin GET only. Bump VERSION to refresh.
const VERSION='prism-shell-166';
const SHELL=[
'./','index.html','landing.html','use.html','comb.html','docs.html','print.html','progress.html','install.html','comb-secure.html','boarding.html',
'scan.html','reader-lab.html','reader.html','simulator.html','steg.html','stegtest.html','offline.html','404.html',
'site.css','controls-motion.css','motion.js','use.css','common.css','site-reader.css','site-camera.css','site-install.css','site-secure.css','lab.html','a11y.css','reader-flow.css','reader-flow.js','first-run.css','first-run.js','comb-qrlink.js','camera-ux-overrides.css','comb-creator.css','comb-parts.js','comb-parts.css','comb-demos.js','comb-creator.js','comb-logo.js','comb-share.js','comb-issuers.js',
'comb-cards.js','issuers.json','comb-pwa.js','manifest.webmanifest', 'brand/favicon.ico','brand/icon-32.png','brand/icon-180.png','brand/icon-192.png','brand/icon-512.png','brand/icon-maskable-512.png',
'license.html','camera-beta.html','secure-logo.js','phone-fit-overrides.css','site-camera-app.css','site-reader-overrides.css','test-report.json','brand/comb-secure-lock-locked-on-dark.svg','brand/sample-signed-code.png','brand/comb-mark-on-dark.svg','brand/logo-stacked.png',
'brand/comb-mark.svg','brand/comb-app-icon.svg','brand/comb-mark-color-on-dark.svg','brand/logo-horizontal.png','brand/sample-prism-code.png',
'brand/fonts/Poppins-Regular.ttf','brand/fonts/Poppins-SemiBold.ttf','brand/fonts/Poppins-Bold.ttf'
];
self.addEventListener('install',e=>{e.waitUntil(caches.open(VERSION).then(c=>Promise.all(SHELL.map(u=>c.add(new Request(u,{cache:'reload'})).catch(()=>{})))).then(()=>self.skipWaiting()))});
self.addEventListener('activate',e=>{e.waitUntil(caches.keys().then(k=>Promise.all(k.filter(n=>n!==VERSION&&n.startsWith('prism-shell')).map(n=>caches.delete(n)))).then(()=>self.clients.claim()))});
self.addEventListener('fetch',e=>{
const r=e.request;
if(r.method==='POST'&&new URL(r.url).pathname.endsWith('/share-target')){
e.respondWith((async()=>{try{const fd=await r.formData();const f=fd.get('image');
if(f&&f.size){const c=await caches.open('prism-share');await c.put('shared-image',new Response(f,{headers:{'content-type':f.type||'image/png','x-name':f.name||'shared.png'}}))}}catch(_){}
return Response.redirect('./use.html?shared=1',303)})());return}if(r.method!=='GET'||new URL(r.url).origin!==location.origin)return;
e.respondWith(Promise.resolve().then(()=>r.mode==='navigate'?fetch(r.url,{cache:'no-cache',credentials:'same-origin'}):fetch(r,{cache:'no-cache'})).then(res=>{if(res.ok){const cp=res.clone();caches.open(VERSION).then(c=>c.put(r,cp))}return res}).catch(()=>caches.match(r,{ignoreSearch:true}).then(m=>m||(r.mode==='navigate'?caches.match('offline.html'):Response.error()))));
});