modified: templates/quiz.html

This commit is contained in:
2025-11-15 00:54:12 +01:00
parent e4aa2a09ee
commit e239cfbf15

View File

@@ -286,13 +286,11 @@
window.spotifyPlayer = player; window.spotifyPlayer = player;
}; };
// Globale Variable für den Abspiel-Timer
let playTimer = null;
function updatePlayButton(state) { function updatePlayButton(state) {
let playButton = document.getElementById('playPauseBtn'); // Nicht mehr benötigt, kann entfernt oder leer bleiben
if (state && !state.paused) {
playButton.innerHTML = i18n.pause;
} else {
playButton.innerHTML = '▶️ Play';
}
} }
function setCorrectAnswer() { function setCorrectAnswer() {
@@ -312,18 +310,38 @@
} }
} }
function togglePlay() { function extendPlayTime() {
const deviceId = document.getElementById('device_id').value; // Hole die gewählte Verlängerungsdauer
const extendDuration = parseInt(document.getElementById('extendDuration').value, 10);
fetch('/toggle_playback', { // Starte Wiedergabe, falls pausiert
method: 'POST', if (window.spotifyPlayer) {
headers: { 'Content-Type': 'application/json' }, window.spotifyPlayer.resume().then(() => {
body: JSON.stringify({ device_id: deviceId }) console.log('Playback resumed/extended');
}) });
.then(response => response.json()) }
.catch(error => {
console.error('Error toggling playback:', error); // Setze Timer für automatisches Pausieren
}); if (playTimer) {
clearTimeout(playTimer);
}
playTimer = setTimeout(() => {
if (window.spotifyPlayer) {
window.spotifyPlayer.pause();
}
}, extendDuration * 1000);
// Visuelles Feedback
const btn = document.getElementById('extendPlayBtn');
const originalText = btn.innerHTML;
btn.innerHTML = `⏱️ +${extendDuration}s`;
btn.disabled = true;
setTimeout(() => {
btn.innerHTML = originalText;
btn.disabled = false;
}, 1000);
} }
function searchTracks() { function searchTracks() {
@@ -510,9 +528,18 @@ window.onload = function() {
</label> </label>
</div> </div>
<!-- Player Controls --> <!-- Player Controls: Abspielzeit verlängern -->
<div class="controls"> <div class="controls">
<button id="playPauseBtn" class="btn" onclick="togglePlay()">{{ translations['pause'] if translations.get('pause') else '⏸ Pause' }}</button> <label style="margin-right: 10px; color: #e0e0e0; font-weight: 500;">
{{ translations['extend_playtime'] if translations.get('extend_playtime') else 'Extend Playtime' }}:
<select id="extendDuration" style="margin-left: 10px; padding: 8px 12px; border-radius: 15px; border: 2px solid rgba(29, 185, 84, 0.3); background: rgba(15, 20, 35, 0.6); color: #e0e0e0;">
<option value="10">10s</option>
<option value="15" selected>15s</option>
<option value="30">30s</option>
<option value="60">60s</option>
</select>
</label>
<button id="extendPlayBtn" class="btn" onclick="extendPlayTime()">🎵 {{ translations['extend_play'] if translations.get('extend_play') else '+Zeit abspielen' }}</button>
</div> </div>
<!-- Antwort-Eingabe --> <!-- Antwort-Eingabe -->