GymLog: Gym- & Körpergewicht-Tracker — PWA mit Passkey-Login

Frontend: Static-SPA (Vanilla JS) — Dashboard, Wochenplan mit Per-Tag-Umplanung,
geführter Workout-Flow (Körpergewicht-Abfrage, Set-Logging, Rest-Timer, PR-Erkennung,
Gewichts-Bestätigung pro Übung), Activity-Heatmap, Kraft- & Gewichts-Charts,
Übungs-Bibliothek (1324 Übungen, autoplay GIFs), Swipe-Sheets, PWA/offline.

Backend: Node + @simplewebauthn — Passkey-Registrierung/-Login (Face ID),
HMAC-Session-Cookies, Per-User-State-Sync mit JSON-File-Storage.

Übungsdaten aus hasaneyldrm/exercises-dataset (Medien via scripts/fetch-media.sh).
This commit is contained in:
Duarte Santos committed 2026-07-18 22:53:08 +02:00
commit 29f5f64f8e
15 files changed
+2476

No files matched your search

+1568
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
const EXDB=[{"id":"0001","n":"3/4 sit-up","bp":"waist","eq":"body weight","tg":"abs","mg":"hip flexors","sm":["hip flexors","lower back"],"st":["Lie flat on your back with your knees bent and feet flat on the ground.","Place your hands behind your head with your elbows pointing outwards.","Engaging your abs, slowly lift your upper body off the ground, curling forward until your torso is at a 45-degree angle.","Pause for a moment at the top, then slowly lower your upper body back down to the starting position.","Repeat for the desired number of repetitions."],"img":"0001-2gPfomN.jpg","gif":"0001-2gPfomN.gif"},{"id":"0002","n":"45° side bend","bp":"waist","eq":"body weight","tg":"abs","mg":"obliques","sm":["obliques"],"st":["Stand with your feet shoulder-width apart and your arms extended straight down by your sides.","Keeping your back straight and your core engaged, slowly bend your torso to one side, lowering your hand towards your knee.","Pause for a moment at the bottom, then slowly return to the starting position.","Repeat on the other side.","Continue alternating sides for the desired number of repetitions."],"img":"0002-Hy9D21L.jpg","gif":"0002-Hy9D21L.gif"},{"id":"0003","n":"air bike","bp":"waist","eq":"body weight","tg":"abs","mg":"hip flexors","sm":["hip flexors"],"st":["Lie flat on your back with your hands placed behind your head.","Lift your legs off the ground and bend your knees at a 90-degree angle.","Bring your right elbow towards your left knee while simultaneously straightening your right leg.","Return to the starting position and repeat the movement on the opposite side, bringing your left elbow towards your right knee while straightening your left leg.","Continue alternating sides in a pedaling motion for the desired number of repetitions."],"img":"0003-1ZFqTDN.jpg","gif":"0003-1ZFqTDN.gif"},{"id":"1512","n":"all fours squad stretch","bp":"upper legs","eq":"body weight","tg":"quads","mg":"hamstrings","sm":["hamstrings","glutes"],"st":["Start on all fours with your hands directly under your shoulders and your knees directly under your hips.","Extend one leg straight back, keeping your knee bent and your foot flexed.","Slowly lower your hips towards the ground, feeling a stretch in your quads.","Hold this position for 20-30 seconds.","Switch legs and repeat the stretch on the other side."],"img":"1512-qBcKorM.jpg","gif":"1512-qBcKorM.gif"},{"id":"0006","n":"alternate heel touchers","bp":"waist","eq":"body weight","tg":"abs","mg":"obliques","sm":["obliques"],"st":["Lie flat on your back with your knees bent and feet flat on the ground.","Extend your arms straight out to the sides, parallel to the ground.","Engaging your abs, lift your shoulders off the ground and reach your right hand towards your right heel.","Return to the starting position and repeat on the left side, reaching your left hand towards your left heel.","Continue alternating sides for the desired number of repetitions."],"img":"0006-qaZVsGk.jpg","gif":"0006-qaZVsGk.gif"},{"id":"0007","n":"alternate lateral pulldown","bp":"back","eq":"cable","tg":"lats","mg":"biceps","sm":["biceps","rhomboids"],"st":["Sit on the cable machine with your back straight and feet flat on the ground.","Grasp the handles with an overhand grip, slightly wider than shoulder-width apart.","Lean back slightly and pull the handles towards your chest, squeezing your shoulder blades together.","Pause for a moment at the peak of the movement, then slowly release the handles back to the starting position.","Repeat for the desired number of repetitions."],"img":"0007-4IKbhHV.jpg","gif":"0007-4IKbhHV.gif"},{"id":"1368","n":"ankle circles","bp":"lower legs","eq":"body weight","tg":"calves","mg":"ankle stabilizers","sm":["ankle stabilizers"],"st":["Sit on the ground with your legs extended in front of you.","Lift one leg off the ground and rotate your ankle in a circular motion.","Perform the desired number of circles in one direction, then switch to the other direction.","Repeat with the other leg."],"img":"1368-uL9CsKm.jpg","gif":"1368-uL9CsKm.gif"},{"id":"3293","n":"archer pull up","bp":"back","eq":"body weight","tg":"lats","mg":"biceps","sm":["biceps","forearms"],"st":["Start by hanging from a pull-up bar with an overhand grip, slightly wider than shoulder-width apart.","Engage your core and pull your shoulder blades down and back.","As you pull yourself up, bend one arm and bring your elbow towards your side, while keeping the other arm straight.","Continue pulling until your chin is above the bar and your bent arm is fully flexed.","Lower yourself back down with control, straightening the bent arm and repeating the movement on the other side.","Alternate sides with each repetition."],"img":"3293-72BC5Za.jpg","gif":"3293-72BC5Za.gif"},{"id":"3294","n":"archer push up","bp":"chest","eq":"body weight","tg":"pectorals","mg":"triceps","sm":["triceps","shoulders","core"],"st":["Start in a push-up position with your hands slightly wider than shoulder-width aparLine truncated
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 515 B

BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

+51
View File
@@ -0,0 +1,51 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover,user-scalable=no">
<title>GymLog</title>
<meta name="description" content="Personal gym & body weight tracker">
<meta name="theme-color" content="#0c0e12">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="GymLog">
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="icon-180.png">
<link rel="icon" type="image/png" href="icon-180.png">
<link rel="stylesheet" href="style.css?v=5">
</head>
<body>
<div id="app"><div style="padding-top:42vh;text-align:center;font-size:2.2rem">🏋️</div></div>
<nav id="tabbar">
<button data-tab="home" aria-label="Home">
<svg viewBox="0 0 24 24"><path d="M3 10.5 12 3l9 7.5"/><path d="M5 9.5V21h14V9.5"/></svg>
<span>Home</span>
</button>
<button data-tab="plan" aria-label="Plan">
<svg viewBox="0 0 24 24"><rect x="3" y="5" width="18" height="16" rx="2"/><path d="M8 3v4M16 3v4M3 11h18"/></svg>
<span>Plan</span>
</button>
<button data-tab="workout" class="start" aria-label="Start workout">
<span class="cir"><svg viewBox="0 0 24 24"><path d="M6.5 6.5v11M17.5 6.5v11M2.5 9.5v5M21.5 9.5v5M6.5 12h11"/></svg></span>
<span>Start</span>
</button>
<button data-tab="stats" aria-label="Stats">
<svg viewBox="0 0 24 24"><path d="M4 20V10M10 20V4M16 20v-8M22 20H2"/></svg>
<span>Stats</span>
</button>
<button data-tab="library" aria-label="Library">
<svg viewBox="0 0 24 24"><circle cx="11" cy="11" r="7"/><path d="m21 21-4.3-4.3"/></svg>
<span>Exercises</span>
</button>
</nav>
<div id="timer-root"></div>
<div id="modal-root"></div>
<div id="toast"></div>
<script src="data.js?v=5"></script>
<script src="app.js?v=5"></script>
</body>
</html>
+15
View File
@@ -0,0 +1,15 @@
{
"name": "GymLog",
"short_name": "GymLog",
"description": "Personal gym & body weight tracker",
"start_url": "./",
"scope": "./",
"display": "standalone",
"orientation": "portrait",
"background_color": "#0c0e12",
"theme_color": "#0c0e12",
"icons": [
{ "src": "icon-180.png", "sizes": "180x180", "type": "image/png" },
{ "src": "icon-512.png", "sizes": "512x512", "type": "image/png" }
]
}
+226
View File
@@ -0,0 +1,226 @@
/* GymLog — mobile-first dark theme */
:root{
--bg:#0c0e12; --bg2:#14171d; --card:#1a1e26; --card2:#222733;
--line:#2b3140; --txt:#eef1f6; --mut:#8b94a7; --dim:#5c6475;
--acc:#a3e635; --acc2:#84cc16; --accT:rgba(163,230,53,.14);
--blue:#60a5fa; --orange:#fb923c; --red:#f87171; --gold:#fbbf24;
--r:16px; --pad:16px;
--sab:env(safe-area-inset-bottom,0px); --sat:env(safe-area-inset-top,0px);
}
*{margin:0;padding:0;box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html{font-size:16px}
body{
background:var(--bg); color:var(--txt);
font-family:-apple-system,BlinkMacSystemFont,'SF Pro Text','Segoe UI',Roboto,sans-serif;
min-height:100vh; overscroll-behavior-y:none;
-webkit-font-smoothing:antialiased; touch-action:manipulation;
}
button{font:inherit;color:inherit;background:none;border:none;cursor:pointer}
input,select,textarea{font:inherit;color:var(--txt)}
img{max-width:100%}
a{color:var(--acc)}
#app{padding:calc(var(--sat) + 10px) var(--pad) calc(96px + var(--sab)); max-width:560px; margin:0 auto}
/* ---------- header ---------- */
.hdr{display:flex;align-items:center;justify-content:space-between;margin:6px 0 16px}
.hdr h1{font-size:1.7rem;font-weight:800;letter-spacing:-.02em}
.hdr .sub{color:var(--mut);font-size:.86rem;margin-top:2px}
.iconbtn{width:42px;height:42px;border-radius:12px;background:var(--card);border:1px solid var(--line);
display:flex;align-items:center;justify-content:center;font-size:1.15rem;flex:none}
.iconbtn:active{background:var(--card2)}
/* ---------- cards ---------- */
.card{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:16px;margin-bottom:14px}
.card h2{font-size:.8rem;text-transform:uppercase;letter-spacing:.08em;color:var(--mut);font-weight:700;margin-bottom:10px}
.card .big{font-size:1.9rem;font-weight:800;letter-spacing:-.02em}
.row{display:flex;align-items:center;gap:12px}
.row.between{justify-content:space-between}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.muted{color:var(--mut)} .dim{color:var(--dim)} .small{font-size:.82rem}
.accent{color:var(--acc)}
/* ---------- buttons ---------- */
.btn{display:flex;align-items:center;justify-content:center;gap:8px;width:100%;
padding:15px;border-radius:14px;font-weight:700;font-size:1rem;
background:var(--card2);border:1px solid var(--line);transition:transform .08s}
.btn:active{transform:scale(.97)}
.btn.primary{background:var(--acc);color:#111;border:none}
.btn.danger{background:rgba(248,113,113,.12);color:var(--red);border-color:rgba(248,113,113,.3)}
.btn.ghost{background:none}
.btn.sm{padding:9px 14px;width:auto;font-size:.86rem;border-radius:11px}
.btn:disabled{opacity:.4}
/* ---------- tab bar ---------- */
#tabbar{position:fixed;left:0;right:0;bottom:0;z-index:50;
background:rgba(16,18,24,.88);backdrop-filter:blur(18px);-webkit-backdrop-filter:blur(18px);
border-top:1px solid var(--line);
display:flex;justify-content:space-around;align-items:flex-end;
padding:8px 6px calc(8px + var(--sab))}
#tabbar button{flex:1;display:flex;flex-direction:column;align-items:center;gap:3px;
color:var(--dim);font-size:.62rem;font-weight:600;padding-top:4px}
#tabbar button svg{width:23px;height:23px;fill:none;stroke:currentColor;stroke-width:1.9;stroke-linecap:round;stroke-linejoin:round}
#tabbar button.on{color:var(--txt)}
#tabbar button.start{margin-top:-26px}
#tabbar button.start .cir{width:58px;height:58px;border-radius:50%;background:var(--acc);
display:flex;align-items:center;justify-content:center;box-shadow:0 6px 20px rgba(163,230,53,.35)}
#tabbar button.start .cir svg{width:26px;height:26px;stroke:#111;stroke-width:2.2}
#tabbar button.start span{color:var(--acc)}
#tabbar button.start.rec .cir{background:var(--orange);box-shadow:0 6px 20px rgba(251,146,60,.4);animation:pulse 1.6s infinite}
#tabbar button.start.rec span{color:var(--orange)}
@keyframes pulse{0%,100%{transform:scale(1)}50%{transform:scale(1.06)}}
/* ---------- week strip ---------- */
.week{display:flex;justify-content:space-between;gap:6px}
.wday{flex:1;text-align:center;padding:9px 2px 10px;border-radius:12px;background:var(--bg2);border:1px solid transparent}
.wday .lbl{font-size:.62rem;color:var(--dim);font-weight:700;text-transform:uppercase}
.wday .num{font-size:.95rem;font-weight:700;margin:3px 0}
.wday .dot{width:7px;height:7px;border-radius:50%;background:var(--line);margin:0 auto}
.wday .dot.plan{background:var(--blue)}
.wday .dot.ovr{background:var(--orange)}
.wday .dot.done{background:var(--acc)}
.wday:active{background:var(--card2)}
.wday.today{border-color:var(--acc);background:var(--accT)}
/* ---------- lists ---------- */
.list{display:flex;flex-direction:column;gap:10px}
.item{display:flex;align-items:center;gap:12px;background:var(--card);border:1px solid var(--line);
border-radius:14px;padding:12px;min-height:60px}
.item:active{background:var(--card2)}
.thumb{width:52px;height:52px;border-radius:10px;object-fit:cover;background:#fff;flex:none}
.item .tt{font-weight:600;font-size:.93rem;line-height:1.25;text-transform:capitalize}
.item .ss{color:var(--mut);font-size:.78rem;margin-top:2px;text-transform:capitalize}
.item .grow{flex:1;min-width:0}
.chev{color:var(--dim);flex:none}
.tag{display:inline-block;background:var(--bg2);border:1px solid var(--line);color:var(--mut);
border-radius:99px;padding:2px 9px;font-size:.7rem;font-weight:600;text-transform:capitalize}
.tag.acc{background:var(--accT);border-color:transparent;color:var(--acc)}
/* ---------- chips ---------- */
.chips{display:flex;gap:8px;overflow-x:auto;padding-bottom:4px;scrollbar-width:none;-webkit-overflow-scrolling:touch}
.chips::-webkit-scrollbar{display:none}
.chip{flex:none;padding:8px 14px;border-radius:99px;background:var(--card);border:1px solid var(--line);
font-size:.82rem;font-weight:600;color:var(--mut);text-transform:capitalize}
.chip.on{background:var(--acc);color:#111;border-color:var(--acc)}
/* ---------- inputs ---------- */
.input{width:100%;background:var(--bg2);border:1px solid var(--line);border-radius:12px;
padding:13px 14px;font-size:1rem;outline:none}
.input:focus{border-color:var(--acc)}
.search{position:relative}
.search .input{padding-left:40px}
.search svg{position:absolute;left:13px;top:50%;transform:translateY(-50%);width:17px;height:17px;
stroke:var(--dim);fill:none;stroke-width:2;stroke-linecap:round}
/* stepper */
.step{display:flex;align-items:center;gap:2px;background:var(--bg2);border:1px solid var(--line);border-radius:12px}
.step button{width:38px;height:44px;font-size:1.25rem;color:var(--mut);flex:none}
.step input{width:58px;text-align:center;background:none;border:none;font-size:1.05rem;font-weight:700;outline:none;
-moz-appearance:textfield}
.step input::-webkit-inner-spin-button{display:none}
/* ---------- workout ---------- */
.wprog{height:5px;background:var(--bg2);border-radius:99px;overflow:hidden;margin-bottom:14px}
.wprog i{display:block;height:100%;background:var(--acc);border-radius:99px;transition:width .3s}
.exmedia{position:relative;border-radius:var(--r);overflow:hidden;background:#fff;margin-bottom:12px}
.exmedia img{width:100%;height:340px;object-fit:contain;display:block}
.exmedia .gifhint{position:absolute;right:10px;bottom:10px;background:rgba(0,0,0,.62);color:#fff;
border-radius:99px;padding:4px 11px;font-size:.72rem;font-weight:600}
.setrow{display:flex;align-items:center;gap:9px;padding:9px 0;border-bottom:1px solid var(--bg2)}
.setrow:last-child{border-bottom:none}
.setrow .n{width:26px;height:26px;border-radius:50%;background:var(--bg2);color:var(--mut);
display:flex;align-items:center;justify-content:center;font-size:.78rem;font-weight:700;flex:none}
.setrow .prev{width:74px;font-size:.72rem;color:var(--dim);flex:none;line-height:1.2}
.setrow.done .n{background:var(--acc);color:#111}
.setrow.done{opacity:.55}
.ck{width:44px;height:44px;border-radius:12px;background:var(--bg2);border:1px solid var(--line);
display:flex;align-items:center;justify-content:center;flex:none}
.ck svg{width:20px;height:20px;stroke:var(--dim);fill:none;stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
.ck.on{background:var(--acc);border-color:var(--acc)}
.ck.on svg{stroke:#111}
/* rest timer */
#timer{position:fixed;left:14px;right:14px;bottom:calc(92px + var(--sab));z-index:60;
background:var(--card2);border:1px solid var(--acc);border-radius:16px;padding:13px 16px;
display:flex;align-items:center;gap:14px;box-shadow:0 10px 30px rgba(0,0,0,.5);
animation:slideup .25s}
@keyframes slideup{from{transform:translateY(20px);opacity:0}to{transform:none;opacity:1}}
#timer .t{font-size:1.5rem;font-weight:800;font-variant-numeric:tabular-nums;min-width:74px}
#timer .bar{flex:1;height:5px;background:var(--bg);border-radius:99px;overflow:hidden}
#timer .bar i{display:block;height:100%;background:var(--acc);transition:width 1s linear}
/* ---------- modal ---------- */
#modal-root{position:fixed;inset:0;z-index:100;display:none}
#modal-root.open{display:block}
.mback{position:absolute;inset:0;background:rgba(0,0,0,.6);backdrop-filter:blur(3px)}
.sheet{position:absolute;left:0;right:0;bottom:0;background:var(--bg2);
border-radius:22px 22px 0 0;padding:10px 18px calc(22px + var(--sab));
max-height:88vh;overflow-y:auto;-webkit-overflow-scrolling:touch;animation:slideup .28s;
overscroll-behavior:contain;touch-action:pan-y}
.sheet .grab{width:40px;height:4px;border-radius:99px;background:var(--line);margin:4px auto 14px}
.sheet h3{font-size:1.15rem;font-weight:800;margin-bottom:12px}
.center{position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);width:min(88vw,360px);
background:var(--bg2);border:1px solid var(--line);border-radius:20px;padding:22px}
/* emoji grid picker */
.emoji-grid{display:grid;grid-template-columns:repeat(5,1fr);gap:8px}
.emoji-cell{font-size:1.9rem;padding:10px 0;border-radius:14px;background:var(--card);
border:1px solid var(--line);line-height:1}
.emoji-cell:active{background:var(--card2)}
.emoji-cell.on{background:var(--accT);border-color:var(--acc)}
/* big weight input */
.bwin{display:flex;align-items:baseline;justify-content:center;gap:8px;margin:18px 0}
.bwin input{width:150px;background:none;border:none;outline:none;text-align:right;
font-size:3.2rem;font-weight:800;letter-spacing:-.03em;color:var(--txt)}
.bwin span{color:var(--mut);font-size:1.2rem;font-weight:600}
/* ---------- charts ---------- */
.chart{width:100%;overflow:hidden}
.chart svg{display:block;width:100%;height:auto}
/* activity heatmap (GitHub-style) */
.hm-wrap{overflow-x:auto;-webkit-overflow-scrolling:touch;scrollbar-width:none;padding-bottom:2px}
.hm-wrap::-webkit-scrollbar{display:none}
.hm-months{display:flex;margin-left:30px;margin-bottom:4px}
.hm-months span{flex:none;width:14px;font-size:.62rem;color:var(--dim);white-space:nowrap;overflow:visible}
.hm-body{display:flex}
.hm-days{display:flex;flex-direction:column;gap:3px;flex:none;width:30px}
.hm-days span{height:11px;font-size:.6rem;color:var(--dim);line-height:11px}
.hm-grid{display:flex;gap:3px}
.hm-col{display:flex;flex-direction:column;gap:3px}
.hm-c{width:11px;height:11px;border-radius:3px;background:var(--bg2);flex:none}
.hm-c.l1{background:#33451b}
.hm-c.l2{background:#527221}
.hm-c.l3{background:#7aa629}
.hm-c.l4{background:var(--acc)}
.hm-c.today{outline:1.5px solid var(--txt);outline-offset:-1.5px}
.hm-c.future{opacity:.28}
.hm-legend{display:flex;align-items:center;gap:4px;justify-content:flex-end;margin-top:8px;
font-size:.65rem;color:var(--dim)}
.hm-legend .hm-c{width:10px;height:10px}
/* stat tiles */
.tiles{display:grid;grid-template-columns:1fr 1fr;gap:12px;margin-bottom:14px}
.tile{background:var(--card);border:1px solid var(--line);border-radius:var(--r);padding:14px}
.tile .v{font-size:1.45rem;font-weight:800;letter-spacing:-.02em;margin-top:2px}
.tile .l{color:var(--mut);font-size:.72rem;font-weight:600;text-transform:uppercase;letter-spacing:.06em}
/* PR badge */
.pr{display:inline-flex;align-items:center;gap:4px;background:rgba(251,191,36,.15);color:var(--gold);
border-radius:99px;padding:3px 10px;font-size:.72rem;font-weight:700}
/* toast */
#toast{position:fixed;left:50%;transform:translateX(-50%);bottom:calc(100px + var(--sab));z-index:200;
background:var(--card2);border:1px solid var(--line);border-radius:99px;padding:10px 20px;
font-size:.88rem;font-weight:600;box-shadow:0 8px 24px rgba(0,0,0,.5);
opacity:0;pointer-events:none;transition:opacity .25s}
#toast.show{opacity:1}
/* misc */
.empty{text-align:center;color:var(--mut);padding:34px 16px;font-size:.9rem;line-height:1.5}
.empty .ico{font-size:2.4rem;margin-bottom:10px}
.divider{height:1px;background:var(--line);margin:12px 0}
.capitalize{text-transform:capitalize}
h4.sec{font-size:.8rem;text-transform:uppercase;letter-spacing:.08em;color:var(--mut);margin:20px 0 10px;font-weight:700}
.steps-list{padding-left:20px;color:var(--mut);font-size:.9rem;line-height:1.55;display:flex;flex-direction:column;gap:8px}
+31
View File
@@ -0,0 +1,31 @@
/* GymLog service worker — network-first for app shell, cache-first for media */
const CACHE = 'gymlog-v5';
const SHELL = ['./', 'index.html', 'style.css?v=5', 'app.js?v=5', 'data.js?v=5', '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.origin !== location.origin) return;
if (url.pathname.startsWith('/api/')) return; // auth/data requests: never cache
const isMedia = url.pathname.includes('/img/') || url.pathname.includes('/gif/');
if (isMedia) {
// cache-first: exercise images never change
e.respondWith(caches.open(CACHE).then(c => c.match(e.request).then(hit =>
hit || fetch(e.request).then(res => { if (res.ok) c.put(e.request, res.clone()); return res; })
)));
} else {
// network-first: shell updates propagate, offline falls back to cache
e.respondWith(fetch(e.request).then(res => {
if (res.ok) caches.open(CACHE).then(c => c.put(e.request, res.clone()));
return res;
}).catch(() => caches.match(e.request, { ignoreSearch: false })
.then(hit => hit || caches.match('index.html'))));
}
});