Update sleeptimer.js
This commit is contained in:
parent
ba79b2429a
commit
ace00afe19
1 changed files with 11 additions and 11 deletions
|
|
@ -1,14 +1,14 @@
|
||||||
// sleeptimer.js - Verwaltet die automatische Abschaltung
|
// sleeptimer.js - Verwaltet die automatische Abschaltung und Restzeitanzeige
|
||||||
window.SleepTimer = {
|
window.SleepTimer = {
|
||||||
timeoutId: null,
|
timeoutId: null,
|
||||||
endTime: null,
|
endTime: null,
|
||||||
onExpiry: null, // Callback-Funktion, die bei Ablauf gerufen wird
|
onExpiry: null,
|
||||||
|
|
||||||
init(onExpiryCallback) {
|
init(onExpiryCallback) {
|
||||||
this.onExpiry = onExpiryCallback;
|
this.onExpiry = onExpiryCallback;
|
||||||
},
|
},
|
||||||
|
|
||||||
start(minutes) {
|
setTimer(minutes) {
|
||||||
this.clear();
|
this.clear();
|
||||||
const durationMs = minutes * 60000;
|
const durationMs = minutes * 60000;
|
||||||
this.endTime = Date.now() + durationMs;
|
this.endTime = Date.now() + durationMs;
|
||||||
|
|
@ -36,22 +36,22 @@ window.SleepTimer = {
|
||||||
|
|
||||||
if (this.endTime) {
|
if (this.endTime) {
|
||||||
const remaining = Math.max(0, Math.ceil((this.endTime - Date.now()) / 60000));
|
const remaining = Math.max(0, Math.ceil((this.endTime - Date.now()) / 60000));
|
||||||
|
// Anzeige mit Icon und Restzeit
|
||||||
btn.innerHTML = `<i class="fas fa-hourglass-half"></i> ${remaining} Min`;
|
btn.innerHTML = `<i class="fas fa-hourglass-half"></i> ${remaining} Min`;
|
||||||
|
|
||||||
// Alle 10 Sekunden die Anzeige aktualisieren
|
// Selbst-Aktualisierung alle 10 Sekunden (nur wenn Timer aktiv)
|
||||||
setTimeout(() => this.updateButtonUI(), 10000);
|
if (this.timeoutId) {
|
||||||
|
setTimeout(() => this.updateButtonUI(), 10000);
|
||||||
|
}
|
||||||
} else {
|
} 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');
|
const offBtn = document.getElementById('off-sleep-timer-modal');
|
||||||
if (offBtn) {
|
if (offBtn) {
|
||||||
offBtn.style.display = this.timeoutId ? 'inline-block' : 'none';
|
offBtn.style.display = this.timeoutId ? 'inline-block' : 'none';
|
||||||
}
|
}
|
||||||
},
|
|
||||||
|
|
||||||
isActive() {
|
|
||||||
return this.timeoutId !== null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Loading…
Reference in a new issue