share button
This commit is contained in:
parent
4fa607ab86
commit
88fefad2fd
4 changed files with 164 additions and 2 deletions
|
|
@ -180,6 +180,9 @@ function renderMusicTracks(tracks, containerId, randomize = false) {
|
|||
window.musicPlaylist = [];
|
||||
filteredTracks.forEach(track => {
|
||||
let title = '', url = '', image = '', artist = '', album = '', duration = '';
|
||||
// ADD THIS: Store the track ID
|
||||
const trackId = track.id || '';
|
||||
|
||||
if (track.tags) {
|
||||
track.tags.forEach(tag => {
|
||||
const key = tag[0];
|
||||
|
|
@ -194,6 +197,7 @@ function renderMusicTracks(tracks, containerId, randomize = false) {
|
|||
}
|
||||
if (url) {
|
||||
window.musicPlaylist.push({
|
||||
id: trackId, // ADD THIS LINE
|
||||
title: title || 'Untitled',
|
||||
url: url,
|
||||
image: image || '',
|
||||
|
|
@ -564,6 +568,8 @@ let musicPlayer = null;
|
|||
|
||||
// Open music lightbox
|
||||
function openMusicLightbox(index) {
|
||||
|
||||
|
||||
if (!window.musicPlaylist || window.musicPlaylist.length === 0) return;
|
||||
|
||||
// Stop any existing playback
|
||||
|
|
@ -595,6 +601,74 @@ function openMusicLightbox(index) {
|
|||
// Get the lyrics element
|
||||
const lyricsDisplay = document.getElementById('musicLightboxLyrics');
|
||||
|
||||
// Share button - in its own row
|
||||
const shareBtn = document.getElementById('musicShareBtn');
|
||||
|
||||
// Create feedback element if it doesn't exist
|
||||
let feedbackEl = document.getElementById('shareFeedbackPopout');
|
||||
if (!feedbackEl) {
|
||||
feedbackEl = document.createElement('div');
|
||||
feedbackEl.id = 'shareFeedbackPopout';
|
||||
feedbackEl.className = 'share-feedback';
|
||||
feedbackEl.innerHTML = '<span class="checkmark">✓</span> Copied!';
|
||||
document.body.appendChild(feedbackEl);
|
||||
}
|
||||
|
||||
if (shareBtn) {
|
||||
shareBtn.onclick = function() {
|
||||
if (!track.id) {
|
||||
feedbackEl.textContent = '⚠️ No ID';
|
||||
feedbackEl.classList.add('visible');
|
||||
setTimeout(() => {
|
||||
feedbackEl.classList.remove('visible');
|
||||
}, 2000);
|
||||
return;
|
||||
}
|
||||
|
||||
const shareUrl = `https://nostr.basspistol.org/notes/${track.id}`;
|
||||
|
||||
if (navigator.share) {
|
||||
navigator.share({
|
||||
title: track.title || 'Music Track',
|
||||
text: `Check out "${track.title}" by ${track.artist || 'Unknown Artist'}`,
|
||||
url: shareUrl
|
||||
}).catch(err => {
|
||||
console.log('Share cancelled or failed:', err);
|
||||
});
|
||||
} else {
|
||||
navigator.clipboard.writeText(shareUrl).then(() => {
|
||||
feedbackEl.innerHTML = '<span class="checkmark">✓</span> Copied!';
|
||||
feedbackEl.classList.add('visible');
|
||||
setTimeout(() => {
|
||||
feedbackEl.classList.remove('visible');
|
||||
}, 2000);
|
||||
}).catch(err => {
|
||||
console.error('Could not copy text: ', err);
|
||||
const textArea = document.createElement('textarea');
|
||||
textArea.value = shareUrl;
|
||||
document.body.appendChild(textArea);
|
||||
textArea.select();
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
feedbackEl.innerHTML = '<span class="checkmark">✓</span> Copied!';
|
||||
feedbackEl.classList.add('visible');
|
||||
setTimeout(() => {
|
||||
feedbackEl.classList.remove('visible');
|
||||
}, 2000);
|
||||
} catch (err) {
|
||||
console.error('Fallback copy failed:', err);
|
||||
feedbackEl.textContent = '⚠️ Copy failed';
|
||||
feedbackEl.classList.add('visible');
|
||||
setTimeout(() => {
|
||||
feedbackEl.classList.remove('visible');
|
||||
}, 2000);
|
||||
}
|
||||
document.body.removeChild(textArea);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Set album art
|
||||
const artUrl = track.image || '/images/default-album.jpg';
|
||||
img.src = artUrl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue