From fb04a947e681e5182775875d0477eb69c9201e84 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Tue, 17 Nov 2026 19:23:33 -0700 Subject: A PAFF film pauses when its post scrolls off screen and carries on when it comes back. "can you ask paff to do the pause command?" (Adam, 2026-11-17). PAFF's embed now takes {source:'paff', command:'pause'|'play'|…} and reports {source:'paff', event:'playing'|'pause'|'ended'}. Each loaded film box is watched: once it's fully off screen while playing, it's told to pause. When it's back at least half in view, it's told to play, but only if we paused it; a viewer's own pause stays paused. link-preview-test runs a stand-in paff.club (self-signed TLS, host-resolver-rules) whose player speaks the protocol. In it the film pauses when scrolled away and plays when scrolled back (commands logged: pause, play). features-smoke passes. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01VMan6SwkivduFDDkMmnXjZ --- src/features/messages.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/features/messages.js b/src/features/messages.js index 158f0ee..797534e 100644 --- a/src/features/messages.js +++ b/src/features/messages.js @@ -9010,7 +9010,7 @@ export function messagesFeature(ctx) { // c copy, t start) in its place ("What would it take … to have it play in // line like other videos and YouTube videos do?", Adam, 2026-11-17). // Only ever on a tap, never on scroll: a PAFF film starts a torrent swarm - // in the viewer's browser. + // in the viewer's browser. Scrolled off, it pauses (paffWatch). function paffEmbedUrl(url) { let u; try { u = new URL(url); } catch { return null; } @@ -9018,6 +9018,42 @@ export function messagesFeature(ctx) { const m = u.pathname.match(/^\/(movie\/[^/]+|show\/[^/]+\/s\d+e\d+)(?:\/play)?\/?$/i); return m ? 'https://paff.club/embed/' + m[1] + u.search : null; } + // A playing film pauses once its post is off the screen and carries on + // when it comes back, if it was us that paused it ("can you ask paff to + // do the pause command?", Adam, 2026-11-17). The embed takes + // {source:'paff', command} and tells us its state as {source:'paff', event}. + let paffObserver = null, paffHeard = false; + const paffSay = (box, command) => { + const f = box.querySelector('iframe'); + try { f?.contentWindow?.postMessage({ source: 'paff', command }, 'https://paff.club'); } catch {} + }; + function paffWatch(box) { + if (typeof window === 'undefined') return; + if (!paffHeard) { + paffHeard = true; + window.addEventListener('message', (e) => { + if (e.origin !== 'https://paff.club' || e.data?.source !== 'paff') return; + for (const b of document.querySelectorAll('.paff-embed[data-playing]')) { + if (b.querySelector('iframe')?.contentWindow !== e.source) continue; + if (e.data.event === 'playing') { b._paffPlaying = true; b._pausedByUs = false; } + else if (e.data.event === 'pause' || e.data.event === 'ended') b._paffPlaying = false; + } + }); + } + if (typeof IntersectionObserver === 'undefined') return; + if (!paffObserver) paffObserver = new IntersectionObserver((entries) => { + for (const en of entries) { + const b = en.target; + if (!b.isConnected) { paffObserver.unobserve(b); continue; } + if (!en.isIntersecting) { + if (b._paffPlaying) { b._pausedByUs = true; paffSay(b, 'pause'); } + } else if (en.intersectionRatio >= 0.5 && b._pausedByUs) { + b._pausedByUs = false; paffSay(b, 'play'); + } + } + }, { threshold: [0, 0.5] }); + paffObserver.observe(box); + } function paffEmbed(url, pv) { const embed = paffEmbedUrl(url); const load = (box) => { @@ -9033,6 +9069,7 @@ export function messagesFeature(ctx) { f.allowFullscreen = true; f.referrerPolicy = 'strict-origin-when-cross-origin'; box.append(f); + paffWatch(box); }; return h('div', { class: 'yt-embed paff-embed', -- cgit v1.2.3