feat: 新增5部经典下拉选经、TTS重试、PWA可安装
- 新增阿弥陀经/普门品/道德经/清静经/太上感应篇(维基文库底本,OpenCC转简体) - 经典切换改为下拉框(佛/道分组),移动端复用底部面板并显示分组标题 - TTS 请求失败自动重试3次;普门品偈颂拆分修复600字上限问题 - 服务端缓存原子写(.tmp+rename),上限放宽至800字 - PWA:manifest + Service Worker,安装后无地址栏独立窗口 - 偏好记忆/逐字光标/回到诵读处/夜间模式等此前改动一并入库 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* Service Worker:仅做最小化的安装支持与静态壳缓存。
|
||||
* - 静态资源(HTML/CSS/JS/图标)走"网络优先、失败回缓存",保证新版本及时生效
|
||||
* - /api/tts 不拦截,直接透传网络
|
||||
*/
|
||||
const CACHE = "fj-shell-v1";
|
||||
const SHELL = ["/", "/index.html", "/style.css?v=9", "/app.js?v=9", "/icon.svg", "/icon-180.png", "/icon-192.png", "/icon-512.png", "/manifest.json"];
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
const url = new URL(e.request.url);
|
||||
if (e.request.method !== "GET" || url.pathname.startsWith("/api/")) return;
|
||||
e.respondWith(
|
||||
fetch(e.request)
|
||||
.then((resp) => {
|
||||
if (resp.ok) {
|
||||
const clone = resp.clone();
|
||||
caches.open(CACHE).then((c) => c.put(e.request, clone));
|
||||
}
|
||||
return resp;
|
||||
})
|
||||
.catch(() => caches.match(e.request))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user