Download script.js from AlexiDevs/cosmic-canvas-explorer: direct link, hf CLI and curl.
- Browser
- Download file 2.57 kB
-
https://huggingface.co/spaces/AlexiDevs/cosmic-canvas-explorer/resolve/main/script.js
- Command line
-
hf download hf://spaces/AlexiDevs/cosmic-canvas-explorer/script.js
-
curl -L -o script.js https://huggingface.co/spaces/AlexiDevs/cosmic-canvas-explorer/resolve/main/script.js
2.57 kB
| document.addEventListener('DOMContentLoaded', async function() { | |
| try { | |
| // Fetch NASA APOD data | |
| const response = await fetch('https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY&count=6'); | |
| const data = await response.json(); | |
| const galleryContainer = document.querySelector('#gallery .grid'); | |
| galleryContainer.innerHTML = ''; // Clear loading skeletons | |
| data.forEach(item => { | |
| const galleryItem = document.createElement('div'); | |
| galleryItem.className = 'gallery-item overflow-hidden rounded-xl relative group'; | |
| galleryItem.innerHTML = ` | |
| <div class="h-64 w-full relative"> | |
| <img src="${item.media_type === 'video' ? 'https://img.youtube.com/vi/' + item.url.split('=')[1] + '/maxresdefault.jpg' : item.hdurl || item.url}" | |
| alt="${item.title}" | |
| class="w-full h-full object-cover transition-transform duration-300 group-hover:scale-105"> | |
| <div class="absolute inset-0 bg-gradient-to-t from-black/70 via-transparent to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-end p-4"> | |
| <div> | |
| <h3 class="text-lg font-semibold text-white">${item.title}</h3> | |
| <p class="text-sm text-cosmic-200 line-clamp-2">${item.explanation}</p> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| galleryContainer.appendChild(galleryItem); | |
| }); | |
| // Replace feather icons after content is loaded | |
| feather.replace(); | |
| } catch (error) { | |
| console.error('Error fetching NASA data:', error); | |
| const galleryContainer = document.querySelector('#gallery .grid'); | |
| galleryContainer.innerHTML = ` | |
| <div class="col-span-full text-center py-12"> | |
| <i data-feather="alert-circle" class="w-12 h-12 mx-auto text-nebula-500 mb-4"></i> | |
| <h3 class="text-xl font-medium text-cosmic-300">Failed to load cosmic images</h3> | |
| <p class="text-nebula-300 mt-2">We're having trouble connecting to the cosmic database. Please try again later.</p> | |
| <button onclick="window.location.reload()" class="mt-4 px-4 py-2 bg-cosmic-600 hover:bg-cosmic-500 rounded-lg transition-colors"> | |
| Retry | |
| </button> | |
| </div> | |
| `; | |
| feather.replace(); | |
| } | |
| }); |