- 📊 Letzte Eintrage
+ 📊 Letzte Einträge
diff --git a/script.js b/script.js
index b3f5415..bf4949f 100644
--- a/script.js
+++ b/script.js
@@ -8,7 +8,14 @@ const App = {
consumption: [],
currentFilter: 'all',
currentUser: null,
- loading: true
+ loading: true,
+ timer: {
+ totalSeconds: 180,
+ remainingSeconds: 180,
+ endTime: null,
+ intervalId: null,
+ running: false
+ }
},
// Initialisierung
@@ -16,6 +23,8 @@ const App = {
this.bindEvents();
this.setupFirebaseAuth();
this.updateDate();
+ this.updateTimerDisplay();
+ this.updateTimerButtons();
},
// Firebase Auth einrichten
@@ -160,6 +169,28 @@ const App = {
e.target.value = '';
}
});
+
+ // Tee-Timer: Presets (3 / 5 Min.)
+ var presetButtons = document.querySelectorAll('.timer-preset');
+ for (var i = 0; i < presetButtons.length; i++) {
+ presetButtons[i].addEventListener('click', (e) => {
+ this.setTimerPreset(parseInt(e.currentTarget.getAttribute('data-minutes')));
+ });
+ }
+
+ // Tee-Timer: eigene Zeit
+ el = document.getElementById('timerCustomSet');
+ if (el) el.addEventListener('click', () => { this.setTimerCustom(); });
+
+ // Tee-Timer: Start / Pause / Reset
+ el = document.getElementById('timerStart');
+ if (el) el.addEventListener('click', () => { this.startTimer(); });
+
+ el = document.getElementById('timerPause');
+ if (el) el.addEventListener('click', () => { this.pauseTimer(); });
+
+ el = document.getElementById('timerReset');
+ if (el) el.addEventListener('click', () => { this.resetTimer(); });
},
// Google Sign-In
@@ -902,6 +933,180 @@ const App = {
return div.innerHTML;
},
+ // ===== Tee-Timer =====
+
+ // Preset setzen (z. B. 3 oder 5 Minuten)
+ setTimerPreset(minutes) {
+ var total = (parseInt(minutes) || 0) * 60;
+ if (total <= 0) return;
+ var t = this.state.timer;
+ t.totalSeconds = total;
+ t.remainingSeconds = total;
+ t.endTime = null;
+ this.updateTimerDisplay();
+ this.updateTimerButtons();
+ this.setTimerStatus('Timer auf ' + this.formatTime(total) + ' gesetzt');
+ this.markPresetActive(minutes);
+ },
+
+ // Eigene Zeit aus den Eingabefeldern übernehmen
+ setTimerCustom() {
+ var minEl = document.getElementById('timerMinutes');
+ var secEl = document.getElementById('timerSeconds');
+ var minutes = parseInt((minEl && minEl.value) || '0') || 0;
+ var seconds = parseInt((secEl && secEl.value) || '0') || 0;
+ if (minutes < 0) minutes = 0;
+ if (minutes > 180) minutes = 180;
+ if (seconds < 0) seconds = 0;
+ if (seconds > 59) seconds = 59;
+ var total = minutes * 60 + seconds;
+ if (total <= 0) {
+ this.showToast('Bitte eine Zeit größer als 0 eingeben', 'error');
+ return;
+ }
+ var t = this.state.timer;
+ t.totalSeconds = total;
+ t.remainingSeconds = total;
+ t.endTime = null;
+ this.updateTimerDisplay();
+ this.updateTimerButtons();
+ this.setTimerStatus('Timer auf ' + this.formatTime(total) + ' gesetzt');
+ this.markPresetActive(null);
+ },
+
+ // Timer starten (bzw. nach Pause fortsetzen)
+ startTimer() {
+ var t = this.state.timer;
+ if (t.running) return;
+ // Nach vollständigem Ablauf: gleiche Zeit erneut starten
+ if (t.remainingSeconds <= 0) {
+ t.remainingSeconds = t.totalSeconds;
+ }
+ t.running = true;
+ t.endTime = Date.now() + t.remainingSeconds * 1000;
+ var self = this;
+ t.intervalId = setInterval(function() { self.tickTimer(); }, 250);
+ this.updateTimerButtons();
+ this.setTimerStatus('Timer läuft…');
+ },
+
+ // Timer pausieren
+ pauseTimer() {
+ var t = this.state.timer;
+ if (!t.running) return;
+ t.remainingSeconds = Math.max(0, Math.round((t.endTime - Date.now()) / 1000));
+ clearInterval(t.intervalId);
+ t.intervalId = null;
+ t.running = false;
+ t.endTime = null;
+ this.updateTimerDisplay();
+ this.updateTimerButtons();
+ this.setTimerStatus('Timer pausiert');
+ },
+
+ // Timer auf die eingestellte Gesamtzeit zurücksetzen
+ resetTimer() {
+ var t = this.state.timer;
+ clearInterval(t.intervalId);
+ t.intervalId = null;
+ t.running = false;
+ t.endTime = null;
+ t.remainingSeconds = t.totalSeconds;
+ this.updateTimerDisplay();
+ this.updateTimerButtons();
+ this.setTimerStatus('');
+ },
+
+ // Ein Intervall-Tick: Restzeit anhand der Endzeit neu berechnen
+ tickTimer() {
+ var t = this.state.timer;
+ var remaining = Math.max(0, Math.round((t.endTime - Date.now()) / 1000));
+ t.remainingSeconds = remaining;
+ this.updateTimerDisplay();
+ if (remaining <= 0) {
+ clearInterval(t.intervalId);
+ t.intervalId = null;
+ t.running = false;
+ t.endTime = null;
+ this.updateTimerButtons();
+ this.setTimerStatus('⏱️ Tee ist fertig!');
+ this.showToast('⏱️ Der Tee ist fertig!', 'success');
+ this.playTimerAlarm();
+ }
+ },
+
+ // Anzeige aktualisieren
+ updateTimerDisplay() {
+ var el = document.getElementById('timerDisplay');
+ if (el) el.textContent = this.formatTime(this.state.timer.remainingSeconds);
+ },
+
+ // Start/Pause-Buttons je nach Zustand (de)aktivieren
+ updateTimerButtons() {
+ var t = this.state.timer;
+ var startBtn = document.getElementById('timerStart');
+ var pauseBtn = document.getElementById('timerPause');
+ if (startBtn) {
+ startBtn.disabled = t.running;
+ var label = 'Start';
+ if (t.running) label = 'Läuft…';
+ else if (t.remainingSeconds > 0 && t.remainingSeconds < t.totalSeconds) label = 'Weiter';
+ startBtn.textContent = label;
+ }
+ if (pauseBtn) pauseBtn.disabled = !t.running;
+ },
+
+ // Statuszeile unter dem Timer
+ setTimerStatus(text) {
+ var el = document.getElementById('timerStatus');
+ if (el) el.textContent = text;
+ },
+
+ // Aktiven Preset-Button hervorheben
+ markPresetActive(minutes) {
+ var buttons = document.querySelectorAll('.timer-preset');
+ for (var i = 0; i < buttons.length; i++) {
+ var active = buttons[i].getAttribute('data-minutes') == String(minutes);
+ buttons[i].classList.toggle('active', active);
+ }
+ },
+
+ // Sekunden als MM:SS formatieren
+ formatTime(totalSeconds) {
+ var s = Math.max(0, parseInt(totalSeconds) || 0);
+ var m = Math.floor(s / 60);
+ var r = s % 60;
+ return (m < 10 ? '0' + m : '' + m) + ':' + (r < 10 ? '0' + r : '' + r);
+ },
+
+ // Akustisches Signal bei Ablauf (3 Pieptöne via WebAudio)
+ playTimerAlarm() {
+ try {
+ var AudioCtx = window.AudioContext || window.webkitAudioContext;
+ if (!AudioCtx) return;
+ var ctx = new AudioCtx();
+ for (var i = 0; i < 3; i++) {
+ (function(n) {
+ var start = ctx.currentTime + n * 0.35;
+ var osc = ctx.createOscillator();
+ var gain = ctx.createGain();
+ osc.type = 'sine';
+ osc.frequency.value = 880;
+ gain.gain.setValueAtTime(0.0001, start);
+ gain.gain.exponentialRampToValueAtTime(0.3, start + 0.02);
+ gain.gain.exponentialRampToValueAtTime(0.0001, start + 0.3);
+ osc.connect(gain);
+ gain.connect(ctx.destination);
+ osc.start(start);
+ osc.stop(start + 0.32);
+ })(i);
+ }
+ setTimeout(function() { ctx.close(); }, 1500);
+ } catch (e) {
+ console.warn('Alarm konnte nicht abgespielt werden', e);
+ }
+ },
+
// Toast-Nachricht anzeigen
showToast(message, type = 'success') {
// Entferne bestehende Toasts
diff --git a/styles.css b/styles.css
index 31a815e..c5fca33 100644
--- a/styles.css
+++ b/styles.css
@@ -704,3 +704,60 @@ section h2 {
color: var(--text-secondary);
margin-left: 10px;
}
+
+/* Tea Timer Section */
+.timer-section {
+ background: var(--card-background);
+}
+
+.timer-display {
+ font-size: 3.5rem;
+ font-weight: 700;
+ font-variant-numeric: tabular-nums;
+ text-align: center;
+ color: var(--primary-color);
+ font-family: 'Courier New', monospace;
+ letter-spacing: 4px;
+}
+
+.timer-presets {
+ display: flex;
+ gap: 10px;
+ justify-content: center;
+}
+
+.timer-custom {
+ display: flex;
+ gap: 8px;
+ align-items: center;
+ justify-content: center;
+ flex-wrap: wrap;
+}
+
+.timer-custom input[type="number"] {
+ width: 70px;
+ padding: 8px;
+ border: 1px solid var(--border-color);
+ border-radius: var(--border-radius);
+ font-size: 1rem;
+ text-align: center;
+}
+
+.timer-controls {
+ display: flex;
+ gap: 10px;
+ justify-content: center;
+ flex-wrap: wrap;
+}
+
+.timer-controls .btn:disabled {
+ opacity: 0.5;
+ cursor: not-allowed;
+}
+
+.timer-status {
+ text-align: center;
+ font-size: 0.95rem;
+ color: var(--text-secondary);
+ min-height: 1.2em;
+}