diff --git a/site/static/app.js b/site/static/app.js
index 331ed31..88c0bec 100644
--- a/site/static/app.js
+++ b/site/static/app.js
@@ -299,10 +299,43 @@
store('timer_state', { total: timer.total, left: timer.left, phase: timer.phase });
}
+ window.groundingIv = null;
+ window.setGroundingInterval = function() {
+ if (window.groundingIv) { clearInterval(window.groundingIv); window.groundingIv = null; }
+ var activeBtn = $('.grounding-chime.active');
+ if (!activeBtn) return;
+ var mins = parseInt(activeBtn.dataset.interval, 10);
+ if (mins > 0 && timer.running) {
+ window.groundingIv = setInterval(function() {
+ if (window.playGroundingPing) window.playGroundingPing();
+ }, mins * 60 * 1000);
+ }
+ };
+
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);
+
+ var portion = timer.total > 0 ? (timer.left / timer.total) : 0;
+ var piePath = $('#ring-pie-path');
+ var pieSvg = $('#ring-pie-svg');
+ if (piePath && pieSvg) {
+ if (portion <= 0) {
+ piePath.setAttribute("d", "M110,110 Z");
+ } else if (portion >= 1) {
+ piePath.setAttribute("d", "M110,110 L110,10 A100,100 0 1,1 109.99,10 Z");
+ } else {
+ var angle = portion * 360;
+ var rad = (angle * Math.PI) / 180;
+ var x = 110 + 100 * Math.sin(rad);
+ var y = 110 - 100 * Math.cos(rad);
+ var largeArc = angle > 180 ? 1 : 0;
+ piePath.setAttribute("d", "M110,110 L110,10 A100,100 0 " + largeArc + ",1 " + x + "," + y + " Z");
+ }
+ pieSvg.classList.toggle('alert-amber', timer.left < 120 && timer.running);
+ }
+
// Ring color matches phase
var ringFg = $('#ring-fg');
if (timer.phase === 'break') { ringFg.classList.add('break-ring'); }
@@ -323,7 +356,7 @@
}
function timerStop() { clearInterval(timer.iv); timer.iv = null; timer.running = false;
- if (window.groundingIv) clearInterval(groundingIv); timerPersist(); }
+ if (window.groundingIv) clearInterval(window.groundingIv); timerPersist(); }
function timerComplete() {
timerStop(); beep();
@@ -356,11 +389,31 @@
timerPaint();
}
+ // Pie Mode Toggle
+ var modeToggleBtn = $('#timer-mode-toggle');
+ if (modeToggleBtn) {
+ modeToggleBtn.addEventListener('click', function() {
+ var pieSvg = $('#ring-pie-svg');
+ var ringSvg = $('.timer-wrap > svg.ring:not(.pie-mode)');
+ var isPie = pieSvg.style.display !== 'none';
+ if (isPie) {
+ pieSvg.style.display = 'none';
+ ringSvg.style.display = '';
+ this.innerHTML = ' switch to visual pie mode';
+ } else {
+ pieSvg.style.display = '';
+ ringSvg.style.display = 'none';
+ this.innerHTML = ' switch to ring mode';
+ }
+ timerPaint();
+ });
+ }
+
$('#timer-start').addEventListener('click', function () {
- if (window.setGroundingInterval) setGroundingInterval();
+ if (window.setGroundingInterval) window.setGroundingInterval();
if (timer.running) { timerStop(); $('#timer-start').textContent = 'resume'; timerPaint(); return; }
timer.running = true;
- if (window.setGroundingInterval) setGroundingInterval();
+ if (window.setGroundingInterval) window.setGroundingInterval();
$('#timer-start').textContent = 'pause';
timer.iv = setInterval(function () {
timer.left--;
@@ -368,7 +421,7 @@
if (timer.left <= 0) {
timerComplete();
return;
- if (window.groundingIv) clearInterval(groundingIv);
+ if (window.groundingIv) clearInterval(window.groundingIv);
}
timerPaint();
}, 1000);
@@ -392,6 +445,14 @@
});
});
+ $$('.grounding-chime').forEach(function(btn) {
+ btn.addEventListener('click', function() {
+ $$('.grounding-chime').forEach(function(b) { b.classList.remove('active'); });
+ btn.classList.add('active');
+ if (window.setGroundingInterval) window.setGroundingInterval();
+ });
+ });
+
// Timer completion overlay actions
$('#timer-take-break').addEventListener('click', function () {
$('#timer-complete').hidden = true;