|
157 | 157 | transform: translateY(1px); |
158 | 158 | box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1); |
159 | 159 | } |
| 160 | + |
| 161 | + #playlistModal { |
| 162 | + z-index: 1000; |
| 163 | + } |
| 164 | + |
| 165 | + input[type="range"] { |
| 166 | + -webkit-appearance: none; |
| 167 | + height: 8px; |
| 168 | + background: #e5e7eb; |
| 169 | + border-radius: 4px; |
| 170 | + outline: none; |
| 171 | + } |
| 172 | + |
| 173 | + input[type="range"]::-webkit-slider-thumb { |
| 174 | + -webkit-appearance: none; |
| 175 | + width: 20px; |
| 176 | + height: 20px; |
| 177 | + background: #1DB954; |
| 178 | + border-radius: 50%; |
| 179 | + cursor: pointer; |
| 180 | + } |
| 181 | + |
| 182 | + input[type="range"]::-moz-range-thumb { |
| 183 | + width: 20px; |
| 184 | + height: 20px; |
| 185 | + background: #1DB954; |
| 186 | + border-radius: 50%; |
| 187 | + cursor: pointer; |
| 188 | + border: none; |
| 189 | + } |
160 | 190 | </style> |
161 | 191 | </head> |
162 | 192 | <body class="bg-gray-100 min-h-screen"> |
|
181 | 211 |
|
182 | 212 | <div id="printArea"></div> |
183 | 213 |
|
| 214 | +<div id="playlistModal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center"> |
| 215 | + <div class="bg-white p-8 rounded-lg shadow-xl max-w-md w-full"> |
| 216 | + <h2 class="text-xl font-bold mb-4">Create QR Codes from Playlist</h2> |
| 217 | + <input |
| 218 | + type="text" |
| 219 | + id="playlistUrl" |
| 220 | + placeholder="Enter Spotify playlist URL" |
| 221 | + class="w-full px-4 py-2 mb-4 border rounded" |
| 222 | + > |
| 223 | + <div class="mb-4"> |
| 224 | + <label class="block text-sm font-medium text-gray-700 mb-2"> |
| 225 | + Number of songs: <span id="songCount">21</span> |
| 226 | + </label> |
| 227 | + <input |
| 228 | + type="range" |
| 229 | + id="songSlider" |
| 230 | + min="3" |
| 231 | + max="300" |
| 232 | + step="3" |
| 233 | + value="21" |
| 234 | + class="w-full" |
| 235 | + > |
| 236 | + </div> |
| 237 | + <div class="flex justify-end gap-4"> |
| 238 | + <button onclick="closePlaylistModal()" class="px-4 py-2 text-gray-600 hover:text-gray-800"> |
| 239 | + Cancel |
| 240 | + </button> |
| 241 | + <button onclick="processPlaylist()" class="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600"> |
| 242 | + Create |
| 243 | + </button> |
| 244 | + </div> |
| 245 | + </div> |
| 246 | +</div> |
184 | 247 | <script> |
185 | 248 | let playerInstance = null; |
186 | 249 | let isPlaying = false; |
|
267 | 330 | return card; |
268 | 331 | } |
269 | 332 |
|
270 | | - async function createQRCodesFromPlaylist() { |
271 | | - const input = prompt("Enter Spotify playlist URL:"); |
272 | | - if (!input) return; |
| 333 | + function showPlaylistModal() { |
| 334 | + document.getElementById('playlistModal').style.display = 'flex'; |
| 335 | + } |
| 336 | + |
| 337 | + function closePlaylistModal() { |
| 338 | + document.getElementById('playlistModal').style.display = 'none'; |
| 339 | + } |
| 340 | + |
| 341 | + // Add this to initialize the slider |
| 342 | + document.getElementById('songSlider').addEventListener('input', function(e) { |
| 343 | + document.getElementById('songCount').textContent = e.target.value; |
| 344 | + }); |
| 345 | + |
| 346 | + async function processPlaylist() { |
| 347 | + const playlistUrl = document.getElementById('playlistUrl').value; |
| 348 | + const songCount = parseInt(document.getElementById('songSlider').value); |
| 349 | + |
| 350 | + if (!playlistUrl) { |
| 351 | + alert('Please enter a playlist URL'); |
| 352 | + return; |
| 353 | + } |
| 354 | + |
273 | 355 | try { |
274 | | - const tracks = await getPlaylistTracks(input); |
| 356 | + const tracks = await getPlaylistTracks(playlistUrl); |
275 | 357 | if (tracks.length === 0) { |
276 | 358 | throw new Error('No valid tracks found in playlist'); |
277 | 359 | } |
| 360 | + |
278 | 361 | const printArea = document.getElementById('printArea'); |
279 | 362 | printArea.innerHTML = ''; |
| 363 | + |
280 | 364 | const qrPage = document.createElement('div'); |
281 | 365 | qrPage.className = 'page'; |
282 | 366 | const qrContainer = document.createElement('div'); |
283 | 367 | qrContainer.className = 'card-container'; |
284 | | - const selectedTracks = tracks.slice(0, 21); |
| 368 | + |
| 369 | + const selectedTracks = tracks.slice(0, songCount); |
285 | 370 | selectedTracks.forEach(track => { |
286 | 371 | qrContainer.appendChild(createQRCard(track, true)); |
287 | 372 | }); |
| 373 | + |
288 | 374 | qrPage.appendChild(qrContainer); |
289 | 375 | printArea.appendChild(qrPage); |
| 376 | + |
290 | 377 | const metadataPage = document.createElement('div'); |
291 | 378 | metadataPage.className = 'page'; |
292 | 379 | const metadataContainer = document.createElement('div'); |
293 | 380 | metadataContainer.className = 'card-container'; |
| 381 | + |
294 | 382 | selectedTracks.forEach(track => { |
295 | 383 | metadataContainer.appendChild(createQRCard(track, false)); |
296 | 384 | }); |
| 385 | + |
297 | 386 | metadataPage.appendChild(metadataContainer); |
298 | 387 | printArea.appendChild(metadataPage); |
| 388 | + |
| 389 | + closePlaylistModal(); |
| 390 | + |
299 | 391 | setTimeout(() => { |
300 | 392 | window.print(); |
301 | 393 | }, 1000); |
|
305 | 397 | } |
306 | 398 | } |
307 | 399 |
|
| 400 | + // Update the click handler for the createQRButton |
| 401 | + document.getElementById('createQRButton').onclick = showPlaylistModal; |
| 402 | + |
308 | 403 | function initializePlayer(token) { |
309 | 404 | document.getElementById('setup').classList.add('hidden'); |
310 | 405 | document.getElementById('player').classList.remove('hidden'); |
|
0 commit comments