// Recently Played Tracks functionality async function updateRecentlyPlayed() { try { const response = await fetch('/api/asteroid/recently-played'); const result = await response.json(); // Radiance wraps API responses in a data envelope const data = result.data || result; if (data.status === 'success' && data.tracks && data.tracks.length > 0) { const listEl = document.getElementById('recently-played-list'); if (!listEl) return; // Build HTML for tracks let html = ''; listEl.innerHTML = html; } else { const listEl = document.getElementById('recently-played-list'); if (listEl) { listEl.innerHTML = '

No tracks played yet

'; } } } catch (error) { console.error('Error fetching recently played:', error); const listEl = document.getElementById('recently-played-list'); if (listEl) { listEl.innerHTML = '

Error loading recently played tracks

'; } } } function formatTimeAgo(timestamp) { const now = Math.floor(Date.now() / 1000); const diff = now - timestamp; if (diff < 60) return 'Just now'; if (diff < 3600) return `${Math.floor(diff / 60)}m ago`; if (diff < 86400) return `${Math.floor(diff / 3600)}h ago`; return `${Math.floor(diff / 86400)}d ago`; } function escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } // Initialize on page load document.addEventListener('DOMContentLoaded', function() { const panel = document.getElementById('recently-played-panel'); if (panel) { updateRecentlyPlayed(); // Update every 30 seconds setInterval(updateRecentlyPlayed, 30000); } else { const list = document.getElementById('recently-played-list'); if (list) { updateRecentlyPlayed(); setInterval(updateRecentlyPlayed, 30000); } } });