8787 </ style >
8888</ head >
8989< body class ="bg-gray-100 dark:bg-black min-h-screen overflow-hidden ">
90- < div id ="setup " class ="max-w-md mx-auto p-6 ">
91- < div class ="bg-white dark:bg-gray-900 rounded-lg shadow-xl p-8 ">
92- < input type ="text " id ="clientId " placeholder ="Enter Spotify Client ID "
93- class ="w-full px-4 py-2 mb-4 border rounded bg-white dark:bg-gray-700 text-black dark:text-white ">
94- < button onclick ="startAuth() "
95- class ="w-full bg-green-500 hover:bg-green-600 text-white py-2 px-4 rounded transition-colors ">
96- Initialize
97- </ button >
98- </ div >
99- </ div >
10090
10191< div id ="player " class ="hidden h-screen flex justify-center items-center flex-col ">
10292 < div class ="flex flex-col items-center gap-8 ">
@@ -147,6 +137,7 @@ <h2 class="text-xl font-bold mb-4 text-black dark:text-white">
147137< script >
148138 let playerInstance = null ;
149139 let isPlaying = false ;
140+ const CLIENT_ID = '0c99c2a032ad459c984e55b14b5a78ae' ;
150141 const redirectUri = 'http://gptgames.dev/tools/spotify_music_quiz_cards.html' ;
151142
152143 function togglePauseResume ( ) {
@@ -165,13 +156,13 @@ <h2 class="text-xl font-bold mb-4 text-black dark:text-white">
165156
166157 if ( isPlaying ) {
167158 button . innerHTML = `<svg width="${ size } " height="${ size } " viewBox="0 0 24 24">
168- <rect x="6" y="4" width="4" height="16" fill="white"/>
169- <rect x="14" y="4" width="4" height="16" fill="white"/>
170- </svg>` ;
159+ <rect x="6" y="4" width="4" height="16" fill="white"/>
160+ <rect x="14" y="4" width="4" height="16" fill="white"/>
161+ </svg>` ;
171162 } else {
172163 button . innerHTML = `<svg width="${ size } " height="${ size } " viewBox="0 0 24 24">
173- <path d="M8 5v14l11-7z" fill="white"/>
174- </svg>` ;
164+ <path d="M8 5v14l11-7z" fill="white"/>
165+ </svg>` ;
175166 }
176167 }
177168
@@ -185,10 +176,8 @@ <h2 class="text-xl font-bold mb-4 text-black dark:text-white">
185176 } ;
186177
187178 function startAuth ( ) {
188- const clientId = document . getElementById ( 'clientId' ) . value ;
189- localStorage . setItem ( 'spotify_client_id' , clientId ) ;
190179 const scope = 'streaming user-read-email user-read-private user-modify-playback-state playlist-read-private' ;
191- window . location . href = `https://accounts.spotify.com/authorize?client_id=${ clientId } &response_type=token&redirect_uri=${ encodeURIComponent ( redirectUri ) } &scope=${ encodeURIComponent ( scope ) } ` ;
180+ window . location . href = `https://accounts.spotify.com/authorize?client_id=${ CLIENT_ID } &response_type=token&redirect_uri=${ encodeURIComponent ( redirectUri ) } &scope=${ encodeURIComponent ( scope ) } ` ;
192181 }
193182
194183 function getHashParams ( ) {
@@ -265,6 +254,13 @@ <h3 class="text-lg font-semibold">${track.name}</h3>
265254 } ) ;
266255 document . getElementById ( 'createQRButton' ) . onclick = showPlaylistModal ;
267256 updateButtonIcon ( ) ;
257+
258+ const token = localStorage . getItem ( 'spotify_access_token' ) || getHashParams ( ) . access_token ;
259+ if ( token ) {
260+ initializePlayer ( token ) ;
261+ } else {
262+ startAuth ( ) ;
263+ }
268264 } ) ;
269265
270266 async function processPlaylist ( ) {
@@ -322,8 +318,6 @@ <h3 class="text-lg font-semibold">${track.name}</h3>
322318 }
323319
324320 function initializePlayer ( token ) {
325- document . getElementById ( 'setup' ) . classList . add ( 'hidden' ) ;
326- document . getElementById ( 'player' ) . classList . remove ( 'hidden' ) ;
327321 localStorage . setItem ( 'spotify_access_token' , token ) ;
328322
329323 playerInstance = new Spotify . Player ( {
@@ -377,12 +371,10 @@ <h3 class="text-lg font-semibold">${track.name}</h3>
377371 }
378372
379373 function refreshAuth ( ) {
380- const clientId = localStorage . getItem ( 'spotify_client_id' ) ;
381374 localStorage . clear ( ) ;
382375 sessionStorage . clear ( ) ;
383- localStorage . setItem ( 'spotify_client_id' , clientId ) ;
384376 const scope = 'streaming user-read-email user-read-private user-modify-playback-state playlist-read-private' ;
385- window . location . href = `https://accounts.spotify.com/authorize?client_id=${ clientId } &response_type=token&redirect_uri=${ encodeURIComponent ( redirectUri ) } &scope=${ encodeURIComponent ( scope ) } ` ;
377+ window . location . href = `https://accounts.spotify.com/authorize?client_id=${ CLIENT_ID } &response_type=token&redirect_uri=${ encodeURIComponent ( redirectUri ) } &scope=${ encodeURIComponent ( scope ) } ` ;
386378 }
387379
388380 async function spotifyFetch ( url , options = { } ) {
0 commit comments