// ============================================ // 1. UTILITY FUNCTIONS // ============================================ // Function to shuffle array (Fisher-Yates) function shuffleArray(array) { const shuffled = [...array]; for (let i = shuffled.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]; } return shuffled; } // Artist filter list const allowedArtists = [ 'εΎ Setto γ»γγ', 'Settoshi Tonami', 'Sethy Bowoy' ]; // Function to check if a track is by an allowed artist function isAllowedArtist(artist) { if (!artist) return false; const normalizedArtist = artist.trim().toLowerCase(); return allowedArtists.some(allowed => { const normalizedAllowed = allowed.trim().toLowerCase(); return normalizedArtist.includes(normalizedAllowed) || normalizedAllowed.includes(normalizedArtist); }); } // ============================================ // 2. CUSTOM LIGHTBOX // ============================================ let currentPhotos = []; let currentIndex = 0; // Build photo array from DOM function buildPhotoArray() { const photoItems = document.querySelectorAll('.photo-item'); currentPhotos = []; photoItems.forEach(item => { const image = item.querySelector('img'); // FIX: Use dataset values directly const date = item.dataset.date || ''; const pubkey = item.dataset.pubkey || ''; const alt = item.dataset.alt || ''; if (image) { currentPhotos.push({ url: image.src, alt: alt || image.alt || '', date: date, pubkey: pubkey }); } }); } // Open lightbox function openLightbox(index) { const lightbox = document.getElementById('customLightbox'); const lightboxImage = document.getElementById('lightboxImage'); const lightboxCaption = document.getElementById('lightboxCaption'); const lightboxMeta = document.getElementById('lightboxMeta'); const lightboxCounter = document.getElementById('lightboxCounter'); if (!lightbox || !lightboxImage || currentPhotos.length === 0) return; if (index < 0) index = currentPhotos.length - 1; if (index >= currentPhotos.length) index = 0; currentIndex = index; const photo = currentPhotos[currentIndex]; lightboxImage.src = photo.url; lightboxImage.alt = photo.alt; lightboxCaption.textContent = photo.alt; // FIX: Show date and pubkey in the meta let metaText = ''; if (photo.date) metaText += `π ${photo.date}`; lightboxMeta.textContent = metaText || 'π No date available'; lightboxCounter.textContent = `${currentIndex + 1} / ${currentPhotos.length}`; lightbox.classList.add('active'); document.body.style.overflow = 'hidden'; } // Close lightbox function closeLightbox() { const lightbox = document.getElementById('customLightbox'); if (!lightbox) return; lightbox.classList.remove('active'); document.body.style.overflow = ''; } // Navigate function prevPhoto() { openLightbox(currentIndex - 1); } function nextPhoto() { openLightbox(currentIndex + 1); } // Initialize lightbox event listeners function initLightbox() { const lightbox = document.getElementById('customLightbox'); const lightboxClose = document.getElementById('lightboxClose'); const lightboxPrev = document.getElementById('lightboxPrev'); const lightboxNext = document.getElementById('lightboxNext'); if (!lightbox) return; buildPhotoArray(); // Photo click listeners document.querySelectorAll('.photo-item img').forEach((img, index) => { img.removeEventListener('click', img._lightboxClick); img._lightboxClick = function(e) { e.preventDefault(); openLightbox(index); }; img.addEventListener('click', img._lightboxClick); }); // Control listeners lightboxClose.removeEventListener('click', closeLightbox); lightboxClose.addEventListener('click', closeLightbox); lightboxPrev.removeEventListener('click', prevPhoto); lightboxPrev.addEventListener('click', prevPhoto); lightboxNext.removeEventListener('click', nextPhoto); lightboxNext.addEventListener('click', nextPhoto); // Keyboard controls document.removeEventListener('keydown', handleLightboxKeydown); document.addEventListener('keydown', handleLightboxKeydown); // Click outside to close lightbox.removeEventListener('click', handleLightboxClick); lightbox.addEventListener('click', handleLightboxClick); } function handleLightboxKeydown(e) { const lightbox = document.getElementById('customLightbox'); if (!lightbox || !lightbox.classList.contains('active')) return; if (e.key === 'Escape') closeLightbox(); else if (e.key === 'ArrowLeft') prevPhoto(); else if (e.key === 'ArrowRight') nextPhoto(); } function handleLightboxClick(e) { const lightbox = document.getElementById('customLightbox'); if (e.target === lightbox) closeLightbox(); } // ============================================ // 3. MUSIC RENDERER // ============================================ function renderMusicTracks(tracks, containerId, randomize = false) { const container = document.getElementById(containerId); if (!container) return; // Filter tracks by artist const filteredTracks = tracks.filter(track => { let artist = ''; if (track.tags) { track.tags.forEach(tag => { if (tag[0] === 'artist') artist = tag[1]; }); } return isAllowedArtist(artist); }); if (filteredTracks.length === 0) { container.innerHTML = '
No tracks found for the selected artists.
'; return; } let selected; if (randomize) { // Randomize: shuffle and get first 6 const shuffled = shuffleArray(filteredTracks); selected = shuffled.slice(0, 6); } else { // Chronological: sort by created_at (newest first) and get first 6 const sorted = [...filteredTracks].sort((a, b) => b.created_at - a.created_at); selected = sorted.slice(0, 6); } container.innerHTML = ''; selected.forEach(track => { let title = '', url = '', image = '', artist = '', album = '', trackNumber = '', duration = '', released = '', language = '', tags = [], alt = '', content = ''; if (track.tags) { track.tags.forEach(tag => { if (tag[0] === 'title') title = tag[1]; else if (tag[0] === 'url') url = tag[1]; else if (tag[0] === 'image') image = tag[1]; else if (tag[0] === 'artist') artist = tag[1]; else if (tag[0] === 'album') album = tag[1]; else if (tag[0] === 'track_number') trackNumber = tag[1]; else if (tag[0] === 'duration') duration = tag[1]; else if (tag[0] === 'released') released = tag[1]; else if (tag[0] === 'language') language = tag[1]; else if (tag[0] === 't') tags.push(tag[1]); else if (tag[0] === 'alt') alt = tag[1]; }); } content = track.content || ''; const card = document.createElement('div'); card.className = 'music-card'; let cardHTML = ` ${image ? `${artist}
` : ''} ${album ? `${album}
` : ''}${alt}