diff --git a/nginx.conf b/nginx.conf index 22f3212..58248d1 100644 --- a/nginx.conf +++ b/nginx.conf @@ -17,7 +17,12 @@ http { error_page 404 /404.html; add_header X-Content-Type-Options nosniff always; add_header Referrer-Policy strict-origin-when-cross-origin always; - location ~* \.(css|js|svg|png|jpg|ico|woff2?)$ { + # Service worker must not be cached aggressively + location = /sw.js { + add_header Cache-Control "no-cache"; + add_header X-Content-Type-Options nosniff always; + } + location ~* \.(css|js|svg|png|jpg|ico|woff2?|json)$ { expires 7d; add_header Cache-Control "public"; } diff --git a/site/404.html b/site/404.html new file mode 100644 index 0000000..aae5849 --- /dev/null +++ b/site/404.html @@ -0,0 +1,35 @@ + + + + + +Page not found β€” myadhd.dev + + + + + +
+ +
+
+
+
+

That page wandered off.

+

We got distracted and didn't build this page. Totally fair.

+
+
+

πŸ§ πŸ’¨

+

This page doesn't exist β€” but you do, and that's more important.

+ +
+
+
+ + + diff --git a/site/index.html b/site/index.html index 0aa30c7..dd13adf 100644 --- a/site/index.html +++ b/site/index.html @@ -8,40 +8,70 @@ + + + +
+ + + -
+ + + diff --git a/site/manifest.json b/site/manifest.json new file mode 100644 index 0000000..782e690 --- /dev/null +++ b/site/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "myadhd.dev", + "short_name": "myadhd", + "description": "ADHD-friendly tools for focus, tasks and momentum", + "start_url": "/", + "display": "standalone", + "background_color": "#14141c", + "theme_color": "#14141c", + "icons": [ + { "src": "/static/icon-192.png", "sizes": "192x192", "type": "image/png" }, + { "src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png" } + ] +} diff --git a/site/static/app.js b/site/static/app.js index 375c243..0608319 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -9,59 +9,256 @@ } function today() { return new Date().toISOString().slice(0, 10); } + /* ---------- register service worker ---------- */ + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/sw.js').catch(function () {}); + } + + /* ---------- audio helpers ---------- */ + var audioCtx = null; + function getAudio() { + if (!audioCtx) { + try { audioCtx = new (window.AudioContext || window.webkitAudioContext)(); } catch (e) {} + } + return audioCtx; + } + + function beep() { + var ctx = getAudio(); if (!ctx) return; + [[660, 0], [880, 0.18]].forEach(function (n) { + var o = ctx.createOscillator(), g = ctx.createGain(); + o.frequency.value = n[0]; o.type = 'sine'; + g.gain.setValueAtTime(0.001, ctx.currentTime + n[1]); + g.gain.exponentialRampToValueAtTime(0.12, ctx.currentTime + n[1] + 0.02); + g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + n[1] + 0.4); + o.connect(g); g.connect(ctx.destination); + o.start(ctx.currentTime + n[1]); o.stop(ctx.currentTime + n[1] + 0.45); + }); + } + + function tickSound() { + var ctx = getAudio(); if (!ctx) return; + var o = ctx.createOscillator(), g = ctx.createGain(); + o.frequency.value = 520; o.type = 'sine'; + g.gain.setValueAtTime(0.001, ctx.currentTime); + g.gain.exponentialRampToValueAtTime(0.08, ctx.currentTime + 0.01); + g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.15); + o.connect(g); g.connect(ctx.destination); + o.start(ctx.currentTime); o.stop(ctx.currentTime + 0.2); + } + + function celebrateSound() { + var ctx = getAudio(); if (!ctx) return; + var notes = [523, 659, 784, 1047]; + notes.forEach(function (freq, i) { + var o = ctx.createOscillator(), g = ctx.createGain(); + o.frequency.value = freq; o.type = 'sine'; + g.gain.setValueAtTime(0.001, ctx.currentTime + i * 0.12); + g.gain.exponentialRampToValueAtTime(0.1, ctx.currentTime + i * 0.12 + 0.02); + g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + i * 0.12 + 0.35); + o.connect(g); g.connect(ctx.destination); + o.start(ctx.currentTime + i * 0.12); o.stop(ctx.currentTime + i * 0.12 + 0.4); + }); + } + + /* ---------- confetti ---------- */ + function confetti() { + var canvas = $('#confetti'); + if (!canvas) return; + var ctx2d = canvas.getContext('2d'); + canvas.width = window.innerWidth; + canvas.height = window.innerHeight; + var colors = ['#a78bfa', '#7dd3a0', '#f9c846', '#f472b6', '#60a5fa', '#e6e6f0']; + var pieces = []; + for (var i = 0; i < 80; i++) { + pieces.push({ + x: Math.random() * canvas.width, + y: Math.random() * canvas.height - canvas.height, + w: Math.random() * 8 + 4, + h: Math.random() * 6 + 3, + r: Math.random() * 6.28, + dx: (Math.random() - 0.5) * 4, + dy: Math.random() * 3 + 2, + dr: (Math.random() - 0.5) * 0.2, + color: colors[Math.floor(Math.random() * colors.length)], + life: 1 + }); + } + var frame; + function draw() { + ctx2d.clearRect(0, 0, canvas.width, canvas.height); + var alive = 0; + pieces.forEach(function (p) { + if (p.life <= 0) return; + alive++; + p.x += p.dx; + p.y += p.dy; + p.r += p.dr; + p.dy += 0.08; + p.life -= 0.008; + ctx2d.save(); + ctx2d.translate(p.x, p.y); + ctx2d.rotate(p.r); + ctx2d.globalAlpha = Math.max(0, p.life); + ctx2d.fillStyle = p.color; + ctx2d.fillRect(-p.w / 2, -p.h / 2, p.w, p.h); + ctx2d.restore(); + }); + if (alive > 0) { frame = requestAnimationFrame(draw); } + else { ctx2d.clearRect(0, 0, canvas.width, canvas.height); } + } + if (frame) cancelAnimationFrame(frame); + draw(); + } + /* ---------- tabs ---------- */ function showTab(name) { $$('.tool').forEach(function (t) { t.hidden = (t.id !== name); }); - $$('.tab').forEach(function (t) { t.classList.toggle('on', t.dataset.tab === name); }); - if (!location.hash.slice(1)) {} // keep url in sync without loops + $$('.tab').forEach(function (t) { + var isOn = t.dataset.tab === name; + t.classList.toggle('on', isOn); + t.setAttribute('aria-selected', isOn ? 'true' : 'false'); + }); try { history.replaceState(null, '', '#' + name); } catch (e) {} } $$('.tab').forEach(function (t) { t.addEventListener('click', function (e) { e.preventDefault(); showTab(t.dataset.tab); }); }); + + /* ---------- welcome / first visit ---------- */ + var visited = store('visited'); var initial = location.hash.slice(1); - showTab(['breaker', 'timer', 'dopamine', 'now'].indexOf(initial) !== -1 ? initial : 'breaker'); + if (!visited && !initial) { + showTab('welcome'); + store('visited', true); + } else { + showTab(['breaker', 'timer', 'dopamine', 'now'].indexOf(initial) !== -1 ? initial : 'breaker'); + } + + $$('.welcome-btn').forEach(function (b) { + b.addEventListener('click', function () { + var target = b.dataset.goto; + if (target === 'pick') { + var tabs = ['breaker', 'timer', 'dopamine', 'now']; + target = tabs[Math.floor(Math.random() * tabs.length)]; + } + showTab(target); + }); + }); + + /* ---------- session stats ---------- */ + function paintStats() { + var sessions = store('sessions') || 0; + var el = $('#session-stats'); + var text = $('#stats-text'); + if (sessions > 0 && el && text) { + el.hidden = false; + text.textContent = sessions + ' focus round' + (sessions !== 1 ? 's' : '') + ' completed β€” nice work.'; + } + } + paintStats(); /* ---------- task breaker ---------- */ var breakerKey = 'breaker'; function breakerTemplates(task) { return [ - { t: 'Write down what β€œdone” looks like for: ' + task + '.', mins: 2, done: false }, - { t: 'Gather everything you need for β€œ' + task + '” in one spot.', mins: 5, done: false }, - { t: 'Do the ugliest possible first version of β€œ' + task + '”. No polish allowed.', mins: 5, done: false }, - { t: 'Set a 10-minute timer and start β€œ' + task + '”. Starting is the whole job.', mins: 10, done: false }, + { t: 'Write down what "done" looks like for: ' + task + '.', mins: 2, done: false }, + { t: 'Gather everything you need for "' + task + '" in one spot.', mins: 5, done: false }, + { t: 'Do the ugliest possible first draft of "' + task + '". Rough is the goal.', mins: 5, done: false }, + { t: 'Set a 10-minute timer and start "' + task + '". Starting is the whole job.', mins: 10, done: false }, { t: 'Momentum check: keep going, or park it with a note for next time.', mins: 2, done: false }, { t: 'Close the loop: tidy up and write down the very next step.', mins: 2, done: false } ]; } + + function breakerFindNextStep(b) { + if (!b || !b.steps) return -1; + for (var i = 0; i < b.steps.length; i++) { + if (!b.steps[i].done) return i; + } + return -1; + } + function breakerRender() { var b = store(breakerKey); $('#breaker-out').hidden = !b; if (!b) return; var ul = $('#breaker-steps'); ul.innerHTML = ''; + var done = 0; + var allDone = true; b.steps.forEach(function (s, i) { + if (s.done) done++; + else allDone = false; var li = document.createElement('li'); li.className = s.done ? 'done' : ''; var tick = document.createElement('button'); tick.className = 'tick'; tick.type = 'button'; - tick.setAttribute('aria-label', 'toggle done'); + tick.setAttribute('aria-label', s.done ? 'Mark undone' : 'Mark done'); tick.addEventListener('click', function () { - s.done = !s.done; store(breakerKey, b); breakerRender(); + var wasDone = s.done; + s.done = !s.done; + store(breakerKey, b); + if (!wasDone) { + tickSound(); + li.classList.add('step-just-done'); + setTimeout(function () { li.classList.remove('step-just-done'); }, 300); + } + breakerRender(); + // If all done, celebrate! + if (!wasDone) { + var allNow = b.steps.every(function (st) { return st.done; }); + if (allNow) { + celebrateSound(); + confetti(); + } + } }); var txt = document.createElement('span'); txt.className = 'txt'; txt.contentEditable = 'true'; txt.textContent = s.t; + txt.setAttribute('role', 'textbox'); + txt.setAttribute('aria-label', 'Step ' + (i + 1) + ' text'); txt.addEventListener('blur', function () { s.t = txt.textContent.trim(); store(breakerKey, b); }); var mins = document.createElement('span'); mins.className = 'mins'; mins.textContent = s.mins ? s.mins + ' min' : ''; - li.appendChild(tick); li.appendChild(txt); li.appendChild(mins); + + // "start this step" button for undone steps + var actions = document.createElement('span'); + actions.className = 'step-actions'; + if (!s.done) { + var goBtn = document.createElement('button'); + goBtn.className = 'step-go'; + goBtn.textContent = 'start β†’'; + goBtn.type = 'button'; + goBtn.setAttribute('aria-label', 'Start working on this step'); + goBtn.addEventListener('click', function () { + // Set this step as the One Thing + store('now', { text: s.t, fromBreaker: true, stepIndex: i }); + showTab('now'); + nowRender(); + }); + actions.appendChild(goBtn); + } + + li.appendChild(tick); li.appendChild(txt); li.appendChild(mins); li.appendChild(actions); ul.appendChild(li); }); - var done = b.steps.filter(function (s) { return s.done; }).length; + $('#breaker-progress').style.width = b.steps.length ? (100 * done / b.steps.length) + '%' : '0'; - $('#breaker-count').textContent = done + ' of ' + b.steps.length + ' steps done' + - (done === b.steps.length && b.steps.length ? ' β€” look at you. πŸŽ‰' : ''); + $('#breaker-count').textContent = done + ' of ' + b.steps.length + ' steps done'; + + // Show/hide done message + var doneMsg = $('#breaker-done-msg'); + var actionsRow = $('#breaker-actions'); + if (allDone && b.steps.length) { + doneMsg.hidden = false; + actionsRow.hidden = true; + } else { + doneMsg.hidden = true; + actionsRow.hidden = false; + } } + $('#breaker-form').addEventListener('submit', function (e) { e.preventDefault(); var task = $('#breaker-input').value.trim(); @@ -79,70 +276,148 @@ $('#breaker-input').value = ''; breakerRender(); }); + $('#breaker-new').addEventListener('click', function () { + localStorage.removeItem('myadhd.' + breakerKey); + $('#breaker-input').value = ''; + breakerRender(); + $('#breaker-input').focus(); + }); breakerRender(); /* ---------- focus timer ---------- */ var CIRC = 628.3; - var timer = { total: 25 * 60, left: 25 * 60, running: false, phase: 'focus', iv: null }; + // Restore persisted timer state or default + var timerState = store('timer_state'); + var timer; + if (timerState && timerState.left > 0) { + timer = { total: timerState.total, left: timerState.left, running: false, phase: timerState.phase || 'focus', iv: null }; + } else { + timer = { total: 25 * 60, left: 25 * 60, running: false, phase: 'focus', iv: null }; + } + + function timerPersist() { + store('timer_state', { total: timer.total, left: timer.left, phase: timer.phase }); + } + function timerPaint() { var m = Math.floor(timer.left / 60), s = timer.left % 60; $('#timer-time').textContent = (m < 10 ? '0' : '') + m + ':' + (s < 10 ? '0' : '') + s; $('#ring-fg').style.strokeDashoffset = CIRC * (1 - timer.left / timer.total); + // Ring color matches phase + var ringFg = $('#ring-fg'); + if (timer.phase === 'break') { ringFg.classList.add('break-ring'); } + else { ringFg.classList.remove('break-ring'); } var ph = $('#timer-phase'); ph.textContent = timer.running ? (timer.phase === 'focus' ? 'focus β€” you got this' : 'break β€” actually rest') : ph.textContent; ph.className = 'timer-phase' + (timer.phase === 'break' ? ' break' : ''); + // Update context bar + var nowData = store('now'); + var ctxBar = $('#timer-context-bar'); + var ctxText = $('#timer-context-text'); + if (nowData && nowData.text && ctxBar && ctxText) { + ctxBar.hidden = false; + ctxText.textContent = nowData.text; + } else if (ctxBar) { + ctxBar.hidden = true; + } } - function beep() { - try { - var ctx = new (window.AudioContext || window.webkitAudioContext)(); - [[660, 0], [880, 0.18]].forEach(function (n) { - var o = ctx.createOscillator(), g = ctx.createGain(); - o.frequency.value = n[0]; o.type = 'sine'; - g.gain.setValueAtTime(0.001, ctx.currentTime + n[1]); - g.gain.exponentialRampToValueAtTime(0.12, ctx.currentTime + n[1] + 0.02); - g.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + n[1] + 0.4); - o.connect(g); g.connect(ctx.destination); - o.start(ctx.currentTime + n[1]); o.stop(ctx.currentTime + n[1] + 0.45); - }); - } catch (e) {} + + function timerStop() { clearInterval(timer.iv); timer.iv = null; timer.running = false; timerPersist(); } + + function timerComplete() { + timerStop(); beep(); + if (timer.phase === 'focus') { + var sessions = (store('sessions') || 0) + 1; + store('sessions', sessions); + paintStats(); + // Show completion overlay + var overlay = $('#timer-complete'); + if (overlay) { + overlay.hidden = false; + $('#timer-complete-sessions').textContent = sessions + ' focus round' + (sessions !== 1 ? 's' : '') + ' completed.'; + // Show "mark step done" only if there's a linked one-thing from breaker + var nowData = store('now'); + var markBtn = $('#timer-mark-done'); + if (markBtn) { + markBtn.hidden = !(nowData && nowData.fromBreaker); + } + } + celebrateSound(); + confetti(); + } else { + // Break is over + timer.phase = 'focus'; + timer.total = timer.left = 25 * 60; + $('#timer-start').textContent = 'start'; + $('#timer-note').textContent = 'Break over. Pick a length and go again β€” or stop here, that is allowed too.'; + } + timerPersist(); + timerPaint(); } - function timerStop() { clearInterval(timer.iv); timer.iv = null; timer.running = false; } + $('#timer-start').addEventListener('click', function () { if (timer.running) { timerStop(); $('#timer-start').textContent = 'resume'; timerPaint(); return; } timer.running = true; $('#timer-start').textContent = 'pause'; timer.iv = setInterval(function () { timer.left--; + timerPersist(); if (timer.left <= 0) { - timerStop(); beep(); - if (timer.phase === 'focus') { - store('sessions', (store('sessions') || 0) + 1); - timer.phase = 'break'; - $('#timer-note').textContent = 'Focus round done (' + store('sessions') + ' total). Stand up. Drink water. Actually take the break.'; - } else { - timer.phase = 'focus'; - $('#timer-note').textContent = 'Break over. Pick a length and go again β€” or stop here, that is allowed too.'; - } - timer.total = timer.left = (timer.phase === 'break' ? 5 : 25) * 60; - $('#timer-start').textContent = 'start'; + timerComplete(); + return; } timerPaint(); }, 1000); timerPaint(); }); - $('#timer-reset').addEventListener('click', function () { + + function timerReset() { timerStop(); timer.left = timer.total; $('#timer-start').textContent = 'start'; - timerPaint(); - }); + timerPersist(); timerPaint(); + } + + $('#timer-reset').addEventListener('click', timerReset); + $$('.preset').forEach(function (p) { p.addEventListener('click', function () { timerStop(); timer.total = timer.left = (+p.dataset.min) * 60; timer.phase = p.classList.contains('break') ? 'break' : 'focus'; $('#timer-start').textContent = 'start'; - timerPaint(); + timerPersist(); timerPaint(); }); }); + + // Timer completion overlay actions + $('#timer-take-break').addEventListener('click', function () { + $('#timer-complete').hidden = true; + timer.phase = 'break'; + timer.total = timer.left = 5 * 60; + $('#timer-start').textContent = 'start'; + $('#timer-note').textContent = 'Focus round done. Stand up. Drink water. Actually take the break.'; + timerPersist(); timerPaint(); + }); + + $('#timer-mark-done').addEventListener('click', function () { + $('#timer-complete').hidden = true; + // Mark the current one-thing step as done in the breaker + var nowData = store('now'); + if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') { + var b = store(breakerKey); + if (b && b.steps[nowData.stepIndex]) { + b.steps[nowData.stepIndex].done = true; + store(breakerKey, b); + breakerRender(); + } + } + // Reset timer so it's fresh for the next step + timerReset(); + // Clear one-thing and show next step prompt + localStorage.removeItem('myadhd.now'); + showTab('now'); + nowShowNext(true); + }); + timerPaint(); /* ---------- dopamine menu ---------- */ @@ -197,7 +472,15 @@ ] }; var lastPick = null; + var currentMenuMins = store('menu_mins') || null; + function menuPick(mins) { + currentMenuMins = mins; + store('menu_mins', mins); + // Highlight the selected time button + $$('.menu-pick').forEach(function (b) { + b.classList.toggle('on', +b.dataset.min === mins); + }); var pool = MENU[mins].filter(function (x) { return x !== lastPick; }); var item = pool[Math.floor(Math.random() * pool.length)]; lastPick = item; @@ -205,13 +488,16 @@ $('#menu-item').hidden = false; $('#menu-actions').hidden = false; } + $$('.menu-pick').forEach(function (b) { b.addEventListener('click', function () { menuPick(+b.dataset.min); }); }); + $('#menu-reroll').addEventListener('click', function () { - var mins = $$('.menu-pick').filter(function (b) { return b.classList.contains('on'); })[0]; - menuPick(mins ? +mins.dataset.min : 5); + // Use tracked mins instead of .on class + menuPick(currentMenuMins || 5); }); + function paintStreak() { var s = store('streak'); $('#menu-streak').innerHTML = s && s.streak ? @@ -226,39 +512,181 @@ s.last = today(); store('streak', s); } + tickSound(); $('#menu-item').hidden = true; $('#menu-actions').hidden = true; paintStreak(); }); paintStreak(); - /* ---------- one thing ---------- */ - var nowSaved = store('now'); - if (nowSaved && nowSaved.text) { - $('#now-text').textContent = nowSaved.text; - $('#now-form').hidden = true; - $('#now-view').hidden = false; + // Restore menu time selection highlight on page load + if (currentMenuMins) { + $$('.menu-pick').forEach(function (b) { + b.classList.toggle('on', +b.dataset.min === currentMenuMins); + }); } + + /* ---------- one thing ---------- */ + function nowRender() { + var nowSaved = store('now'); + var nextPrompt = $('#now-next'); + if (nextPrompt) nextPrompt.hidden = true; + + if (nowSaved && nowSaved.text) { + $('#now-text').textContent = nowSaved.text; + $('#now-form').hidden = true; + $('#now-view').hidden = false; + // Show source info if from breaker + var sourceEl = $('#now-source'); + if (sourceEl && nowSaved.fromBreaker) { + sourceEl.hidden = false; + var b = store(breakerKey); + if (b && typeof nowSaved.stepIndex === 'number') { + $('#now-step-num').textContent = nowSaved.stepIndex + 1; + $('#now-step-total').textContent = b.steps.length; + } + } else if (sourceEl) { + sourceEl.hidden = true; + } + } else { + $('#now-form').hidden = false; + $('#now-view').hidden = true; + } + } + + function nowShowNext(skipCelebration) { + var nextPrompt = $('#now-next'); + if (!nextPrompt) return; + var b = store(breakerKey); + if (!b) { + // No breaker data, just show "done" and reset form + nowRender(); + return; + } + var nextIdx = breakerFindNextStep(b); + nextPrompt.hidden = false; + $('#now-form').hidden = true; + $('#now-view').hidden = true; + + if (nextIdx >= 0) { + $('#now-next-step').hidden = false; + $('#now-all-done').hidden = true; + $('#now-next-text').textContent = b.steps[nextIdx].t; + // Wire up "Let's do it" + $('#now-next-go').onclick = function () { + store('now', { text: b.steps[nextIdx].t, fromBreaker: true, stepIndex: nextIdx }); + nowRender(); + }; + $('#now-next-skip').onclick = function () { + nextPrompt.hidden = true; + $('#now-form').hidden = false; + $('#now-view').hidden = true; + $('#now-input').value = ''; + $('#now-input').focus(); + }; + } else { + // All steps done + $('#now-next-step').hidden = true; + $('#now-all-done').hidden = false; + if (!skipCelebration) { + celebrateSound(); + confetti(); + } + } + } + + nowRender(); + $('#now-form').addEventListener('submit', function (e) { e.preventDefault(); var t = $('#now-input').value.trim(); if (!t) return; store('now', { text: t }); - $('#now-text').textContent = t; - $('#now-form').hidden = true; - $('#now-view').hidden = false; + nowRender(); }); + $('#now-edit').addEventListener('click', function () { $('#now-view').hidden = true; $('#now-form').hidden = false; $('#now-input').value = ''; $('#now-input').focus(); }); + $('#now-done').addEventListener('click', function () { + var nowData = store('now'); + tickSound(); + // If from breaker, mark that step done + if (nowData && nowData.fromBreaker && typeof nowData.stepIndex === 'number') { + var b = store(breakerKey); + if (b && b.steps[nowData.stepIndex]) { + b.steps[nowData.stepIndex].done = true; + store(breakerKey, b); + breakerRender(); + } + } localStorage.removeItem('myadhd.now'); - $('#now-view').hidden = true; - $('#now-form').hidden = false; - $('#now-input').value = ''; - $('#now-input').focus(); + // Check if there's a next step from breaker + var b2 = store(breakerKey); + if (nowData && nowData.fromBreaker && b2) { + nowShowNext(); + } else { + nowRender(); + $('#now-input').focus(); + } }); + + // "Start timer" button on One Thing + $('#now-timer').addEventListener('click', function () { + showTab('timer'); + // If timer isn't already running, pre-set 25 min + if (!timer.running) { + timer.total = timer.left = 25 * 60; + timer.phase = 'focus'; + $('#timer-start').textContent = 'start'; + timerPersist(); + timerPaint(); + } + }); + + // "Start something new" after all breaker steps done in now view + var nowFresh = $('#now-fresh'); + if (nowFresh) { + nowFresh.addEventListener('click', function () { + localStorage.removeItem('myadhd.now'); + $('#now-next').hidden = true; + showTab('breaker'); + localStorage.removeItem('myadhd.' + breakerKey); + $('#breaker-input').value = ''; + breakerRender(); + $('#breaker-input').focus(); + }); + } + + /* ---------- keyboard shortcuts ---------- */ + document.addEventListener('keydown', function (e) { + // Don't trigger shortcuts when typing in an input or contenteditable + var tag = e.target.tagName; + if (tag === 'INPUT' || tag === 'TEXTAREA' || e.target.contentEditable === 'true') return; + + // Number keys 1-4 switch tabs + if (e.key === '1') { showTab('breaker'); e.preventDefault(); } + if (e.key === '2') { showTab('timer'); e.preventDefault(); } + if (e.key === '3') { showTab('dopamine'); e.preventDefault(); } + if (e.key === '4') { showTab('now'); e.preventDefault(); } + + // Space to start/pause timer when on timer tab + if (e.key === ' ' && !$('#timer').hidden) { + e.preventDefault(); + $('#timer-start').click(); + } + + // Escape to close completion overlay + if (e.key === 'Escape') { + var overlay = $('#timer-complete'); + if (overlay && !overlay.hidden) { + overlay.hidden = true; + } + } + }); + })(); diff --git a/site/static/icon-192.png b/site/static/icon-192.png new file mode 100644 index 0000000..23a784b Binary files /dev/null and b/site/static/icon-192.png differ diff --git a/site/static/icon-512.png b/site/static/icon-512.png new file mode 100644 index 0000000..aae681c Binary files /dev/null and b/site/static/icon-512.png differ diff --git a/site/static/og.png b/site/static/og.png new file mode 100644 index 0000000..4f3b79b Binary files /dev/null and b/site/static/og.png differ diff --git a/site/static/style.css b/site/static/style.css index bdc255f..b521099 100644 --- a/site/static/style.css +++ b/site/static/style.css @@ -10,6 +10,7 @@ --accent: #a78bfa; --accent-dim: #6d5aa8; --good: #7dd3a0; + --warm: #f9c846; --radius: 18px; } body { @@ -19,6 +20,21 @@ body { } main { max-width: 760px; margin: 0 auto; padding: 0 20px 60px; } +/* sr-only for accessibility */ +.sr-only { + position: absolute; width: 1px; height: 1px; padding: 0; + margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); + white-space: nowrap; border: 0; +} + +/* skip link */ +.skip-link { + position: absolute; top: -100%; left: 16px; z-index: 1000; + background: var(--accent); color: #fff; padding: 8px 16px; border-radius: 8px; + text-decoration: none; font-weight: 700; +} +.skip-link:focus { top: 8px; } + /* header */ .top { max-width: 760px; margin: 0 auto; padding: 22px 20px 6px; @@ -30,8 +46,10 @@ main { max-width: 760px; margin: 0 auto; padding: 0 20px 60px; } .tab { color: var(--dim); text-decoration: none; font-weight: 600; font-size: .95rem; padding: 8px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--bg2); + transition: all 0.15s ease; } .tab:hover { color: var(--text); } +.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .tab.on { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; } /* tools */ @@ -51,14 +69,19 @@ input[type="text"] { flex: 1 1 240px; font: inherit; color: var(--text); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 16px; outline: none; + transition: border-color 0.15s ease; } input[type="text"]:focus { border-color: var(--accent-dim); } +input[type="text"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } .btn { font: inherit; font-weight: 700; cursor: pointer; color: #fff; background: var(--accent-dim); border: none; border-radius: 12px; padding: 12px 22px; + transition: filter 0.15s ease, transform 0.1s ease; } .btn:hover { filter: brightness(1.15); } +.btn:active { transform: scale(0.97); } +.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .btn.ghost { background: transparent; border: 1.5px solid var(--line); color: var(--dim); } .btn.ghost:hover { color: var(--text); border-color: var(--accent-dim); } @@ -66,12 +89,34 @@ input[type="text"]:focus { border-color: var(--accent-dim); } font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; color: var(--dim); background: var(--bg2); border: 1.5px solid var(--line); border-radius: 999px; padding: 7px 15px; + transition: all 0.15s ease; } .chip:hover, .chip.on { color: var(--text); border-color: var(--accent-dim); } +.chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .presets { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 22px; } .tiny { color: var(--dim); font-size: .85rem; margin-top: 14px; } +/* welcome */ +.welcome-q { + font-size: 1.2rem; font-weight: 600; margin-bottom: 20px; +} +.welcome-picks { + display: flex; flex-direction: column; gap: 10px; + max-width: 360px; margin: 0 auto; +} +.welcome-btn { + font-size: 1rem; text-align: left; padding: 14px 20px; +} + +/* context bar (shows when timer is linked to a task step) */ +.context-bar { + background: var(--bg2); border: 1.5px solid var(--accent-dim); + border-radius: 12px; padding: 10px 16px; margin-bottom: 12px; + font-size: .9rem; color: var(--dim); text-align: center; +} +.context-bar strong { color: var(--text); margin-left: 6px; } + /* breaker */ .progress-wrap { height: 8px; background: var(--bg2); border-radius: 999px; overflow: hidden; margin: 18px 0 6px; } .progress { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .3s ease; } @@ -79,16 +124,38 @@ input[type="text"]:focus { border-color: var(--accent-dim); } .steps li { display: flex; align-items: flex-start; gap: 12px; background: var(--bg2); border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; + transition: opacity 0.2s ease, border-color 0.2s ease; } +.steps li.active-step { border-color: var(--accent-dim); background: #22223a; } .steps li .tick { flex: 0 0 auto; width: 22px; height: 22px; margin-top: 2px; cursor: pointer; border: 2px solid var(--accent-dim); border-radius: 7px; background: transparent; + transition: all 0.15s ease; } +.steps li .tick:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } .steps li.done .tick { background: var(--good); border-color: var(--good); } .steps li.done .txt { color: var(--dim); text-decoration: line-through; } .steps li .txt { flex: 1; outline: none; } .steps li .txt:focus { background: var(--bg); border-radius: 6px; } .steps li .mins { flex: 0 0 auto; color: var(--accent); font-weight: 700; font-size: .85rem; margin-top: 3px; } +.steps li .step-actions { + flex: 0 0 auto; display: flex; gap: 4px; margin-top: 1px; +} +.step-go { + font: inherit; font-size: .75rem; font-weight: 700; cursor: pointer; + color: var(--accent); background: transparent; border: 1.5px solid var(--accent-dim); + border-radius: 8px; padding: 3px 10px; white-space: nowrap; + transition: all 0.15s ease; +} +.step-go:hover { background: var(--accent-dim); color: #fff; } +.step-go:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; } +.steps li.done .step-go { display: none; } + +/* done message */ +.done-msg { + text-align: center; padding: 24px 0; +} +.done-text { font-size: 1.15rem; font-weight: 600; margin-bottom: 14px; } /* timer */ .timer-wrap { position: relative; width: 240px; margin: 10px auto; } @@ -97,7 +164,9 @@ input[type="text"]:focus { border-color: var(--accent-dim); } .ring-fg { fill: none; stroke: var(--accent); stroke-width: 10; stroke-linecap: round; stroke-dasharray: 628.3; stroke-dashoffset: 0; + transition: stroke 0.3s ease; } +.ring-fg.break-ring { stroke: var(--good); } .timer-readout { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; @@ -106,6 +175,33 @@ input[type="text"]:focus { border-color: var(--accent-dim); } .timer-phase { color: var(--dim); font-size: .9rem; font-weight: 600; } .timer-phase.break { color: var(--good); } +/* completion overlay */ +.completion-overlay { + position: fixed; inset: 0; z-index: 100; + background: rgba(20, 20, 28, 0.92); + display: flex; align-items: center; justify-content: center; + animation: fadeIn 0.3s ease; +} +.completion-card { + background: var(--card); border: 1.5px solid var(--accent-dim); + border-radius: var(--radius); padding: 40px 32px; + max-width: 400px; text-align: center; + animation: scaleIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); +} +.completion-emoji { font-size: 3rem; margin-bottom: 12px; } +.completion-title { font-size: 1.4rem; margin-bottom: 8px; } +.completion-stat { color: var(--dim); margin-bottom: 18px; } + +/* next step prompt */ +.next-step-prompt { + text-align: center; padding: 24px 0; + animation: fadeIn 0.3s ease; +} +.next-step-text { + font-size: 1.15rem; font-weight: 600; margin: 8px 0 4px; + color: var(--accent); +} + /* dopamine menu */ .menu-item { background: var(--bg2); border: 1.5px dashed var(--accent-dim); border-radius: 14px; @@ -118,6 +214,16 @@ input[type="text"]:focus { border-color: var(--accent-dim); } /* one thing */ .now-label { color: var(--dim); text-transform: uppercase; letter-spacing: 2px; font-size: .8rem; margin-top: 8px; } .now-text { font-size: 1.5rem; font-weight: 700; margin: 12px 0 20px; } +.now-source { margin-bottom: 16px; } + +/* confetti canvas */ +.confetti-canvas { + position: fixed; inset: 0; width: 100%; height: 100%; + pointer-events: none; z-index: 200; +} + +/* session stats */ +.session-stats { margin-top: 12px; } /* footer */ .foot { @@ -126,7 +232,41 @@ input[type="text"]:focus { border-color: var(--accent-dim); } } .foot .tiny { margin-top: 6px; } +/* keyboard shortcut hints */ +.kbd-hint { + font-size: .7rem; color: var(--dim); opacity: 0.6; + margin-left: 6px; +} + +/* animations */ +@keyframes fadeIn { + from { opacity: 0; } + to { opacity: 1; } +} +@keyframes scaleIn { + from { opacity: 0; transform: scale(0.85); } + to { opacity: 1; transform: scale(1); } +} +@keyframes stepComplete { + 0% { transform: scale(1); } + 50% { transform: scale(1.03); } + 100% { transform: scale(1); } +} +.step-just-done { + animation: stepComplete 0.3s ease; +} + +/* Reduced motion: disable all animations and transitions */ +@media (prefers-reduced-motion: reduce) { + *, *::before, *::after { + animation-duration: 0.01ms !important; + animation-iteration-count: 1 !important; + transition-duration: 0.01ms !important; + } +} + @media (max-width: 560px) { h1 { font-size: 1.55rem; } .timer-wrap, .ring { width: 200px; height: 200px; } + .welcome-btn { font-size: .9rem; padding: 12px 16px; } } diff --git a/site/sw.js b/site/sw.js new file mode 100644 index 0000000..bde4c3c --- /dev/null +++ b/site/sw.js @@ -0,0 +1,32 @@ +/* myadhd.dev β€” service worker for offline PWA */ +var CACHE = 'myadhd-v2'; +var ASSETS = [ + '/', + '/index.html', + '/static/style.css', + '/static/app.js', + '/static/favicon.svg', + '/static/icon-192.png', + '/static/icon-512.png', + '/manifest.json' +]; + +self.addEventListener('install', function (e) { + e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(ASSETS); })); + self.skipWaiting(); +}); + +self.addEventListener('activate', function (e) { + e.waitUntil( + caches.keys().then(function (names) { + return Promise.all(names.filter(function (n) { return n !== CACHE; }).map(function (n) { return caches.delete(n); })); + }) + ); + self.clients.claim(); +}); + +self.addEventListener('fetch', function (e) { + e.respondWith( + caches.match(e.request).then(function (r) { return r || fetch(e.request); }) + ); +});