diff --git a/index.html b/index.html index dc3d047..d8305ca 100644 --- a/index.html +++ b/index.html @@ -422,7 +422,7 @@ header{display:flex;align-items:center;justify-content:space-between;padding:0 1
- @@ -790,12 +790,38 @@ function bokiApp(){ catch{ this.scores = {}; } const t = localStorage.getItem('posimai-boki-theme')||'system'; this.isDark = t==='dark'||(t==='system'&&matchMedia('(prefers-color-scheme:dark)').matches); + const uid=(new URLSearchParams(location.search).get('unit')||'').trim().toLowerCase(); + if(uid){ + const u=this.allUnits().find(x=>x.id===uid); + if(u){ this.currentUnit=u; this.quizState={}; } + else{ try{ const url=new URL(window.location.href); url.searchParams.delete('unit'); const q=url.searchParams.toString(); history.replaceState(null,'',url.pathname+(q?'?'+q:'')+url.hash); }catch(e){} } + } + this.syncUnitToUrl(); this.$nextTick(()=>{ if(window.lucide) lucide.createIcons(); }); if('serviceWorker' in navigator){ navigator.serviceWorker.register('/sw.js').catch(()=>{}); } }, + syncUnitToUrl(){ + try{ + const url=new URL(window.location.href); + if(this.currentUnit&&this.currentUnit.id) url.searchParams.set('unit',this.currentUnit.id); + else url.searchParams.delete('unit'); + const q=url.searchParams.toString(); + const path=url.pathname+(q?'?'+q:'')+url.hash; + if(path!==window.location.pathname+window.location.search+window.location.hash) + history.replaceState(null,'',path); + }catch(e){} + }, + + goHome(){ + this.currentUnit=null; + this.quizState={}; + this.syncUnitToUrl(); + this.$nextTick(()=>{ if(window.lucide) lucide.createIcons(); }); + }, + get filteredCats(){ if(!this.search) return this.categories; const q=this.search.toLowerCase(); @@ -872,6 +898,7 @@ function bokiApp(){ openUnit(unit){ this.currentUnit=unit; this.quizState={}; + this.syncUnitToUrl(); this.$nextTick(()=>{ if(window.lucide) lucide.createIcons(); const m=document.getElementById('main'); diff --git a/sw.js b/sw.js index b45a0e0..64e558c 100644 --- a/sw.js +++ b/sw.js @@ -1,5 +1,5 @@ // posimai-boki SW — stale-while-revalidate + skipWaiting -const CACHE = 'posimai-boki-v9'; +const CACHE = 'posimai-boki-v10'; const STATIC = ['/', '/index.html', '/manifest.json', '/logo.png']; self.addEventListener('install', e => {