diff --git a/js/app.js b/js/app.js index b6ba0e0..12f7427 100644 --- a/js/app.js +++ b/js/app.js @@ -15,7 +15,7 @@ import { LyricsManager, openLyricsPanel, clearLyricsPanelSync } from './lyrics.j import { createRouter, updateTabTitle, navigate } from './router.js'; import { initializePlayerEvents, initializeTrackInteractions, handleTrackAction } from './events.js'; import { initializeUIInteractions } from './ui-interactions.js'; -import { debounce, SVG_PLAY } from './utils.js'; +import { debounce, SVG_PLAY, getShareUrl } from './utils.js'; import { sidePanelManager } from './side-panel.js'; import { db } from './db.js'; import { syncManager } from './accounts/pocketbase.js'; @@ -1050,7 +1050,7 @@ document.addEventListener('DOMContentLoaded', async () => { if (shareBtn) { shareBtn.style.display = playlist.isPublic ? 'flex' : 'none'; shareBtn.onclick = () => { - const url = `${window.location.origin}/userplaylist/${playlist.id}`; + const url = getShareUrl(`/userplaylist/${playlist.id}`); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); }; } @@ -1091,7 +1091,7 @@ document.addEventListener('DOMContentLoaded', async () => { if (shareBtn) { shareBtn.style.display = playlist.isPublic ? 'flex' : 'none'; shareBtn.onclick = () => { - const url = `${window.location.origin}/userplaylist/${playlist.id}`; + const url = getShareUrl(`/userplaylist/${playlist.id}`); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); }; } diff --git a/js/events.js b/js/events.js index 63b6608..7cde3b9 100644 --- a/js/events.js +++ b/js/events.js @@ -10,6 +10,7 @@ import { SVG_BIN, getTrackArtists, positionMenu, + getShareUrl, } from './utils.js'; import { lastFMStorage, libreFmSettings, waveformSettings } from './storage.js'; import { showNotification, downloadTrackWithMetadata, downloadAlbumAsZip, downloadPlaylistAsZip } from './downloads.js'; @@ -1159,9 +1160,9 @@ export async function handleTrackAction( // Use stored href from card if available, otherwise construct URL const contextMenu = document.getElementById('context-menu'); const storedHref = contextMenu?._contextHref; - const url = storedHref - ? `${window.location.origin}${storedHref}` - : `${window.location.origin}/track/${item.id || item.uuid}`; + const url = getShareUrl( + storedHref ? storedHref : `/track/${item.id || item.uuid}` + ); trackCopyLink(type, item.id || item.uuid); navigator.clipboard.writeText(url).then(() => { diff --git a/js/ui.js b/js/ui.js index 8874a68..20c2765 100644 --- a/js/ui.js +++ b/js/ui.js @@ -18,6 +18,7 @@ import { calculateTotalDuration, formatDuration, escapeHtml, + getShareUrl, } from './utils.js'; import { openLyricsPanel } from './lyrics.js'; import { @@ -3324,7 +3325,7 @@ export class UIRenderer { 'Share'; shareBtn.onclick = () => { - const url = `${window.location.origin}/userplaylist/${playlist.id || playlist.uuid}`; + const url = getShareUrl(`/userplaylist/${playlist.id || playlist.uuid}`); navigator.clipboard.writeText(url).then(() => alert('Link copied to clipboard!')); }; fragment.appendChild(shareBtn); @@ -3660,7 +3661,7 @@ export class UIRenderer { }; shareBtn.onclick = () => { - const url = `${window.location.origin}/track/${track.id}`; + const url = getShareUrl(`/track/${track.id}`); navigator.clipboard.writeText(url).then(() => { showNotification('Link copied to clipboard!'); }); diff --git a/js/utils.js b/js/utils.js index 7adbdc6..10be675 100644 --- a/js/utils.js +++ b/js/utils.js @@ -489,3 +489,9 @@ export function positionMenu(menu, x, y, anchorRect = null) { menu.style.left = `${left}px`; menu.style.visibility = 'visible'; } + +export const getShareUrl = (path) => { + const baseUrl = window.NL_MODE ? 'https://monochrome.tf' : window.location.origin; + const safePath = path.startsWith('/') ? path : `/${path}`; + return `${baseUrl}${safePath}`; +};