From 93056d6b7b45b41987ea6c941a5bb4cfe09a24bd Mon Sep 17 00:00:00 2001 From: posimai Date: Sun, 19 Apr 2026 00:09:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=98=E5=85=83=E3=82=92=20URL=20=3F?= =?UTF-8?q?unit=3D=20=E3=81=A7=E5=90=8C=E6=9C=9F=E3=81=97=E3=83=AA?= =?UTF-8?q?=E3=83=AD=E3=83=BC=E3=83=89=E5=BE=8C=E3=82=82=E5=90=8C=E3=81=98?= =?UTF-8?q?=E5=8D=98=E5=85=83=E3=82=92=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- index.html | 29 ++++++++++++++++++++++++++++- sw.js | 2 +- 2 files changed, 29 insertions(+), 2 deletions(-) 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 => {