aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/messages.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/messages.js')
-rw-r--r--src/features/messages.js82
1 files changed, 81 insertions, 1 deletions
diff --git a/src/features/messages.js b/src/features/messages.js
index 797534e..8f8bdd4 100644
--- a/src/features/messages.js
+++ b/src/features/messages.js
@@ -7483,7 +7483,7 @@ export function messagesFeature(ctx) {
if (!url) continue;
if ((md && md[1]) || /\.(png|jpe?g|gif|webp|avif)(\?[^\s]*)?$/i.test(url)) urls.push(url);
else if (youtubeId(url)) urls.push('https://i.ytimg.com/vi/' + youtubeId(url) + '/hqdefault.jpg');
- else if (paffEmbedUrl(url) && previews.get(url)?.image) urls.push(previews.get(url).image);
+ else if ((paffEmbedUrl(url) || paffMusicUrl(url)) && previews.get(url)?.image) urls.push(previews.get(url).image);
}
return urls;
}
@@ -9054,6 +9054,78 @@ export function messagesFeature(ctx) {
}, { threshold: [0, 0.5] });
paffObserver.observe(box);
}
+ // A PAFF song or album link: a slim card in the post (cover, title, ▶).
+ // The tap doesn't play it there: PAFF's slim player loads into a bar
+ // pinned above the bottom nav, outside the page, so the music carries on
+ // while you scroll, open threads, change tabs ("make songs embed nicely
+ // in nostr posts" … "From the start please", Adam, 2026-11-17). The bar
+ // is never moved (a moved iframe reloads); a new song changes its src,
+ // its × removes it.
+ function paffMusicUrl(url) {
+ let u;
+ try { u = new URL(url); } catch { return null; }
+ if (u.hostname !== 'paff.club' && u.hostname !== 'www.paff.club') return null;
+ const m = u.pathname.match(/^\/(?:play\/)?(song|album)\/([^/]+)\/?$/i);
+ if (!m) return null;
+ const q = new URLSearchParams(u.search);
+ q.set('bar', '1');
+ return 'https://paff.club/embed/' + m[1].toLowerCase() + '/' + m[2] + '?' + q;
+ }
+ let musicBar = null, musicUrl = null;
+ function playInBar(url, title) {
+ if (typeof document === 'undefined') return;
+ if (!musicBar) {
+ musicBar = document.createElement('div');
+ musicBar.className = 'music-bar';
+ const f = document.createElement('iframe');
+ f.allow = 'autoplay; fullscreen; picture-in-picture';
+ f.referrerPolicy = 'strict-origin-when-cross-origin';
+ const x = document.createElement('button');
+ x.type = 'button'; x.className = 'music-close'; x.textContent = '×';
+ x.setAttribute('aria-label', t('musicClose')); x.title = t('musicClose');
+ x.onclick = (e) => { e.stopPropagation(); closeMusic(); };
+ musicBar.append(f, x);
+ document.body.append(musicBar);
+ }
+ const f = musicBar.querySelector('iframe');
+ f.title = title || 'PAFF';
+ if (musicUrl !== url) f.src = paffMusicUrl(url);
+ musicUrl = url;
+ document.body.classList.add('music-open');
+ render();
+ }
+ function closeMusic() {
+ if (musicBar) { musicBar.remove(); musicBar = null; }
+ musicUrl = null;
+ document.body.classList.remove('music-open');
+ render();
+ }
+ function paffSongCard(url, pv) {
+ const on = musicUrl === url;
+ return h('div', {
+ class: 'paff-song' + (on ? ' on' : ''), role: 'button', tabindex: '0',
+ onClick: (e) => {
+ if (e.target.closest('.paff-song-open')) return;
+ e.stopPropagation(); e.preventDefault();
+ playInBar(url, pv?.title);
+ },
+ },
+ pv?.image ? h('img', {
+ class: 'paff-song-cover', loading: 'lazy', alt: '',
+ src: !feedPaint || feedMedia(pv.image) ? pv.image : undefined,
+ onError: (e) => { e.target.style.visibility = 'hidden'; },
+ }) : h('div', { class: 'paff-song-cover' }),
+ h('div', { class: 'paff-song-meta' },
+ h('div', { class: 'paff-song-title' }, pv?.title || t('musicSong')),
+ h('div', { class: 'small faint' }, on ? t('musicPlayingBelow') : pv?.description || 'paff.club')),
+ h('span', { class: 'paff-song-play', 'aria-hidden': 'true', html: on
+ ? '<svg width="18" height="18" viewBox="0 0 24 24" fill="currentColor"><rect x="5" y="10" width="3" height="9" rx="1"/><rect x="10.5" y="5" width="3" height="14" rx="1"/><rect x="16" y="8" width="3" height="11" rx="1"/></svg>'
+ : '<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M8 5v14l11-7z"/></svg>' }),
+ h('a', {
+ class: 'paff-song-open', href: url, target: '_blank', rel: 'noopener noreferrer',
+ title: t('openOnPaff'), onClick: (e) => e.stopPropagation(),
+ }, '↗'));
+ }
function paffEmbed(url, pv) {
const embed = paffEmbedUrl(url);
const load = (box) => {
@@ -10893,6 +10965,14 @@ export function messagesFeature(ctx) {
});
}
if (youtubeId(url)) return youtubeEmbed(url, youtubeId(url));
+ if (!label && paffMusicUrl(url)) {
+ let pv = previews.get(url) || null;
+ if (feedPaint) {
+ if (!feedPaint.media.has('pv:' + url)) feedPaint.media.set('pv:' + url, pv);
+ pv = feedPaint.media.get('pv:' + url);
+ }
+ return paffSongCard(url, pv);
+ }
if (!label && paffEmbedUrl(url)) {
let pv = previews.get(url) || null;
if (feedPaint) {