Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // DOM Elements
+ const connectBtn = document.getElementById('connect-button');
+ const statsValues = document.querySelectorAll('.stat-value');
+ const trackGrid = document.querySelector('.track-grid');
+ const artistGrid = document.querySelector('.artist-grid');
+
+ // Spotify OAuth Configuration
+ const clientId = 'YOUR_CLIENT_ID'; // Replace with your Spotify Client ID
+ const redirectUri = window.location.href.includes('localhost')
+ ? 'http://localhost:8000'
+ : 'https://groovescroll.pub';
+ const scopes = 'user-top-read user-read-recently-played';
+
+ // Connect Button Event
+ connectBtn.addEventListener('click', () => {
+ window.location.href = `https://accounts.spotify.com/authorize?client_id=${clientId}&response_type=token&redirect_uri=${encodeURIComponent(redirectUri)}&scope=${encodeURIComponent(scopes)}&show_dialog=true`;
+ });
+
+ // Check for access token in URL hash
+ function checkForToken() {
+ const hash = window.location.hash.substring(1);
+ const params = new URLSearchParams(hash);
+ const accessToken = params.get('access_token');
+
+ if (accessToken) {
+ // Hide connect section
+ document.querySelector('.connect-section').style.display = 'none';
+
+ // Fetch user data
+ fetchUserData(accessToken);
+
+ // Clear URL hash
+ history.pushState(null, null, ' ');
+ }
+ }
+
+ // Fetch user data from Spotify API
+ async function fetchUserData(token) {
+ try {
+ // Fetch top tracks
+ const tracksResponse = await fetch('https://api.spotify.com/v1/me/top/tracks?limit=6&time_range=short_term', {
+ headers: { 'Authorization': `Bearer ${token}` }
+ });
+ const tracksData = await tracksResponse.json();
+ displayTopTracks(tracksData.items);
+
+ // Fetch top artists
+ const artistsResponse = await fetch('https://api.spotify.com/v1/me/top/artists?limit=6&time_range=short_term', {
+ headers: { 'Authorization': `Bearer ${token}` }
+ });
+ const artistsData = await artistsResponse.json();
+ displayTopArtists(artistsData.items);
+
+ // Update stats (mock data for demo)
+ updateStats();
+
+ } catch (error) {
+ console.error('Error fetching data:', error);
+ }
+ }
+
+ // Display top tracks
+ function displayTopTracks(tracks) {
+ trackGrid.innerHTML = '';
+
+ tracks.forEach(track => {
+ const trackCard = document.createElement('div');
+ trackCard.className = 'track-card';
+ trackCard.innerHTML = `
+

+
+
${track.name}
+
${track.artists.map(a => a.name).join(', ')}
+
+ `;
+ trackGrid.appendChild(trackCard);
+ });
+ }
+
+ // Display top artists
+ function displayTopArtists(artists) {
+ artistGrid.innerHTML = '';
+
+ artists.forEach(artist => {
+ const artistCard = document.createElement('div');
+ artistCard.className = 'artist-card';
+ artistCard.innerHTML = `
+

+
+
${artist.name}
+
${artist.genres[0] || 'Various genres'}
+
+ `;
+ artistGrid.appendChild(artistCard);
+ });
+ }
+
+ // Update stats (mock data for demo)
+ function updateStats() {
+ statsValues[0].textContent = '4,382';
+ statsValues[1].textContent = 'Indie Pop';
+ statsValues[2].textContent = '8-10 PM';
+ statsValues[3].textContent = 'Energetic';
+ }
+
+ // Initialize
+ checkForToken();
+
+ // Add animation to stat cards
+ const statCards = document.querySelectorAll('.stat-card');
+ statCards.forEach((card, index) => {
+ card.style.animationDelay = `${index * 0.1}s`;
+ });
+ });