const queryInput = document.getElementById('query'); const searchBtn = document.getElementById('searchBtn'); const results = document.getElementById('results'); const statusEl = document.getElementById('status'); const dialog = document.getElementById('albumDialog'); const dialogTitle = document.getElementById('dialogTitle'); const dialogArtist = document.getElementById('dialogArtist'); const trackList = document.getElementById('trackList'); const sendBtn = document.getElementById('sendBtn'); const cleanupToggle = document.getElementById('cleanupToggle'); let selectedAlbum = null; let selectedTracks = []; const CLEANUP_KEY = 'cleanupExtras'; cleanupToggle.checked = localStorage.getItem(CLEANUP_KEY) === 'true'; cleanupToggle.addEventListener('change', () => { localStorage.setItem(CLEANUP_KEY, String(cleanupToggle.checked)); }); function setStatus(text, isError = false) { statusEl.textContent = text; statusEl.style.color = isError ? 'var(--danger)' : 'var(--text)'; } function formatDuration(ms) { const totalSec = Math.floor(ms / 1000); const min = Math.floor(totalSec / 60); const sec = totalSec % 60; return `${min}:${String(sec).padStart(2, '0')}`; } async function fetchJson(url, options = {}) { const response = await fetch(url, options); const data = await response.json(); if (!response.ok) { throw new Error(data.error || `HTTP ${response.status}`); } return data; } function renderAlbums(albums) { results.innerHTML = ''; if (!albums.length) { results.innerHTML = '
Keine Alben gefunden.
'; return; } for (const album of albums) { const card = document.createElement('article'); card.className = 'album-card'; card.innerHTML = ` ${album.image ? `${album.artist}
${album.totalTracks} Tracks - ${album.releaseDate || 'unbekannt'}