3f1da92cf4
YouTube subtitles via OpenRouter become persistent, shareable recaps with timestamp jump links, PIN-protected creation, and Traefik deploy. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
const CACHE = "goldfish-v1";
|
|
const ASSETS = ["/", "/index.html", "/r.html", "/styles.css", "/app.js", "/recap.js", "/api.js", "/manifest.json", "/icon.svg"];
|
|
|
|
self.addEventListener("install", (event) => {
|
|
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(ASSETS)));
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(
|
|
caches.keys().then((keys) =>
|
|
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
|
|
)
|
|
);
|
|
self.clients.claim();
|
|
});
|
|
|
|
self.addEventListener("fetch", (event) => {
|
|
const url = new URL(event.request.url);
|
|
if (url.pathname.startsWith("/api/")) return;
|
|
|
|
event.respondWith(
|
|
caches.match(event.request).then((cached) => {
|
|
if (cached) return cached;
|
|
return fetch(event.request).then((resp) => {
|
|
if (resp.ok && event.request.method === "GET" && url.origin === self.location.origin) {
|
|
const clone = resp.clone();
|
|
caches.open(CACHE).then((cache) => cache.put(event.request, clone));
|
|
}
|
|
return resp;
|
|
});
|
|
})
|
|
);
|
|
});
|