async function fetchActivity() { try { const response = await fetch('http://78.135.66.152:3000/activity'); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const activity = await response.json(); const activitiesDiv = document.getElementById('activities'); activitiesDiv.innerHTML = ''; if (activity && activity.activities && activity.activities.length > 0) { const spotifyActivity = activity.activities.find(act => act.name === 'Spotify'); if (spotifyActivity) { const listeningBar = document.createElement('div'); listeningBar.classList.add('listening-bar'); const img = document.createElement('img'); img.src = `https://i.scdn.co/image/${spotifyActivity.assets.largeImage.replace('spotify:', '')}`; img.alt = 'Album Cover'; listeningBar.appendChild(img); const details = document.createElement('div'); details.classList.add('details'); const song = document.createElement('p'); song.classList.add('song'); song.textContent = spotifyActivity.details; details.appendChild(song); const artist = document.createElement('p'); artist.classList.add('artist'); artist.textContent = spotifyActivity.state; details.appendChild(artist); listeningBar.appendChild(details); activitiesDiv.appendChild(listeningBar); } else { activitiesDiv.innerHTML = '

No Spotify activity found

'; } } else { activitiesDiv.innerHTML = '

No activities found

'; } } catch (error) { console.error('Error fetching activity:', error); const activitiesDiv = document.getElementById('activities'); activitiesDiv.innerHTML = '

Failed to fetch activities

'; } } // Fetch activity every 5 seconds setInterval(fetchActivity, 5000); // Initial fetch fetchActivity