-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoffline.js
More file actions
1 lines (1 loc) · 1.34 KB
/
Copy pathoffline.js
File metadata and controls
1 lines (1 loc) · 1.34 KB
1
(function(){ 'use strict'; if (!('serviceWorker' in navigator)) return; const pack=window.VIRELIA_OFFLINE_MANIFEST, button=document.getElementById('open-offline'), dialog=document.getElementById('offline-dialog'), label=document.getElementById('offline-progress'), total=Math.round(pack.bytes/1e6); let worker=null; button.hidden=false; navigator.serviceWorker.register('/sw.js').then(reg=>{worker=reg.active||reg.waiting||reg.installing;}).catch(()=>{ label.textContent='Offline downloads are unavailable in this browser.'; }); button.onclick=()=>dialog.hidden=false; const close=()=>dialog.hidden=true; document.getElementById('offline-close').onclick=close; document.getElementById('offline-cancel').onclick=close; document.getElementById('offline-download').onclick=()=>{ label.hidden=false; document.getElementById('offline-download').disabled=true; (worker||navigator.serviceWorker.controller)?.postMessage({type:'DOWNLOAD_OFFLINE'}); }; navigator.serviceWorker.addEventListener('message', e=>{ if(e.data.type==='OFFLINE_PROGRESS'){ const pct=Math.round(e.data.done/e.data.total*100), amount=Math.round(total*e.data.done/e.data.total); label.textContent=`Preparing Virelia ${pct}% · ${amount} MB of ${total} MB`; } if(e.data.type==='OFFLINE_READY'){ label.textContent='Offline ready'; } }); document.getElementById('offline-size').textContent=total+' MB'; })();