diff --git a/sleeptimer.js b/sleeptimer.js index e6793df..5640cb1 100644 --- a/sleeptimer.js +++ b/sleeptimer.js @@ -1,14 +1,14 @@ -// sleeptimer.js - Verwaltet die automatische Abschaltung +// sleeptimer.js - Verwaltet die automatische Abschaltung und Restzeitanzeige window.SleepTimer = { timeoutId: null, endTime: null, - onExpiry: null, // Callback-Funktion, die bei Ablauf gerufen wird + onExpiry: null, init(onExpiryCallback) { this.onExpiry = onExpiryCallback; }, - start(minutes) { + setTimer(minutes) { this.clear(); const durationMs = minutes * 60000; this.endTime = Date.now() + durationMs; @@ -36,22 +36,22 @@ window.SleepTimer = { if (this.endTime) { const remaining = Math.max(0, Math.ceil((this.endTime - Date.now()) / 60000)); + // Anzeige mit Icon und Restzeit btn.innerHTML = ` ${remaining} Min`; - // Alle 10 Sekunden die Anzeige aktualisieren - setTimeout(() => this.updateButtonUI(), 10000); + // Selbst-Aktualisierung alle 10 Sekunden (nur wenn Timer aktiv) + if (this.timeoutId) { + setTimeout(() => this.updateButtonUI(), 10000); + } } else { - btn.textContent = 'Sleep Timer'; + // Standard-Text wenn kein Timer läuft + btn.textContent = 'Sleeptimer'; } - // Den "Aus"-Button im Modal steuern + // Den "Timer aus"-Button im Modal zeigen/verstecken const offBtn = document.getElementById('off-sleep-timer-modal'); if (offBtn) { offBtn.style.display = this.timeoutId ? 'inline-block' : 'none'; } - }, - - isActive() { - return this.timeoutId !== null; } }; \ No newline at end of file