From f7b6f76bb2b646dd1c1d35d17540eb38004b80c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enes=20Yak=C4=B1=C5=9Ft=C4=B1r?= Date: Fri, 16 Oct 2026 18:23:11 +0300 Subject: [PATCH] feat: add embed player support with 10s seek and speed controls (v1.5.11) --- client.js | 98 ++++++++++++++++++++++++++++++++++++++++++++-------- main.js | 28 ++++++++++++--- package.json | 2 +- style.css | 3 +- 4 files changed, 110 insertions(+), 21 deletions(-) diff --git a/client.js b/client.js index d2a55cb..0729ed2 100644 --- a/client.js +++ b/client.js @@ -1231,10 +1231,12 @@ try { var toast = document.createElement('div'); toast.id = 'yaktube-quick-toast'; toast.className = 'yaktube-quick-toast'; + var isEmbed = (typeof isEmbedUrl === 'function' && isEmbedUrl()) || (window.self !== window.top); + var toastTop = isEmbed ? '28px' : '80px'; toast.style.cssText = - 'position:fixed!important;top:80px!important;left:50%!important;transform:translateX(-50%)!important;' + + 'position:fixed!important;top:' + toastTop + '!important;left:50%!important;transform:translateX(-50%)!important;' + 'background:rgba(24,24,31,0.92)!important;border:1px solid #ff8f37!important;color:#fff!important;' + - 'padding:10px 22px!important;border-radius:30px!important;font-size:14px!important;font-weight:700!important;' + + 'padding:8px 18px!important;border-radius:30px!important;font-size:13px!important;font-weight:700!important;' + 'box-shadow:0 10px 30px rgba(0,0,0,0.8)!important;z-index:999999!important;pointer-events:none!important;' + 'backdrop-filter:blur(8px)!important;display:flex!important;align-items:center!important;gap:8px!important;'; toast.innerHTML = (icon ? '' + icon + ' ' : '') + '' + message + ''; @@ -1738,14 +1740,19 @@ try { // YAKTUBE ACCESSIBLE VIDEO PLAYER & WATCH PAGE ENGINE (W3C WAI-ARIA) // ========================================================================== function focusVideoPlayer() { - var playerWrapper = document.getElementById('videojs-wrapper') || document.querySelector('.video-js'); + var playerWrapper = + document.getElementById('videojs-wrapper') || + document.querySelector('.video-js') || + document.getElementById('video-wrapper'); if (playerWrapper) { playerWrapper.scrollIntoView({ behavior: 'smooth', block: 'center' }); playerWrapper.focus(); var titleEl = document.querySelector( 'h1.video-info-name, .video-info-name h1, my-video-watch h1, .video-title, .title' ); - var videoTitle = titleEl ? titleEl.textContent.trim() : 'Video'; + var videoTitle = titleEl + ? titleEl.textContent.trim() + : (document.title ? document.title.replace(/\s*-\s*(PeerTube|YakTube).*$/i, '').trim() : 'Video'); var video = getVideoElement(); var status = video ? (video.paused ? 'Duraklatıldı' : 'Oynatılıyor') : ''; announce( @@ -1895,10 +1902,21 @@ try { } } + function isEmbedUrl() { + if (typeof window === 'undefined' || !window.location) return false; + var p = window.location.pathname; + return p.includes('/videos/embed/') || p.startsWith('/videos/embed/'); + } + function isWatchUrl() { if (typeof window === 'undefined' || !window.location) return false; var p = window.location.pathname; - return p.includes('/videos/watch/') || p.startsWith('/w/') || p.includes('/w/'); + return ( + p.includes('/videos/watch/') || + p.startsWith('/w/') || + p.includes('/w/') || + isEmbedUrl() + ); } function injectControlBarSeekButtons(playerWrapper) { @@ -1907,6 +1925,7 @@ try { var rewindBtn = controlBar.querySelector('.yaktube-vjs-rewind-btn'); var forwardBtn = controlBar.querySelector('.yaktube-vjs-forward-btn'); + var speedBtn = controlBar.querySelector('.yaktube-vjs-speed-btn'); var playControl = controlBar.querySelector('.vjs-play-control'); if (!rewindBtn) { @@ -1968,6 +1987,55 @@ try { controlBar.appendChild(forwardBtn); } } + + if (!speedBtn) { + speedBtn = document.createElement('button'); + speedBtn.className = 'vjs-control vjs-button yaktube-vjs-seek-btn yaktube-vjs-speed-btn'; + speedBtn.type = 'button'; + speedBtn.setAttribute('tabindex', '0'); + speedBtn.setAttribute('aria-label', 'Oynatma Hızı: 1x (Değiştirmek için tıklayın veya Alt+.)'); + speedBtn.setAttribute('title', 'Hız: 1x (Alt+.)'); + speedBtn.innerHTML = + '' + + 'Hız Değiştir'; + + speedBtn.addEventListener('click', function (e) { + e.preventDefault(); + e.stopPropagation(); + var video = getVideoElement(); + if (video) { + var speeds = [1, 1.25, 1.5, 1.75, 2, 0.5, 0.75]; + var cur = video.playbackRate || 1; + var curIdx = speeds.indexOf(cur); + var nextSpeed = curIdx === -1 ? 1 : speeds[(curIdx + 1) % speeds.length]; + video.playbackRate = nextSpeed; + var speedText = nextSpeed + 'x'; + var numEl = speedBtn.querySelector('.yaktube-vjs-speed-val'); + if (numEl) numEl.textContent = speedText; + speedBtn.setAttribute('aria-label', 'Oynatma Hızı: ' + speedText); + speedBtn.setAttribute('title', 'Hız: ' + speedText + ' (Alt+.)'); + announce('Oynatma hızı: ' + speedText); + showQuickToast('⚡ Hız: ' + speedText); + } + }); + + if (forwardBtn && forwardBtn.nextSibling) { + controlBar.insertBefore(speedBtn, forwardBtn.nextSibling); + } else { + controlBar.appendChild(speedBtn); + } + } else { + var v = getVideoElement(); + if (v) { + var curRate = (v.playbackRate || 1) + 'x'; + var numEl = speedBtn.querySelector('.yaktube-vjs-speed-val'); + if (numEl && numEl.textContent !== curRate) { + numEl.textContent = curRate; + speedBtn.setAttribute('aria-label', 'Oynatma Hızı: ' + curRate); + speedBtn.setAttribute('title', 'Hız: ' + curRate + ' (Alt+.)'); + } + } + } } function enhanceVideoPlayerAccessibility() { @@ -2010,10 +2078,12 @@ try { var titleEl = document.querySelector( 'h1.video-info-name, .video-info-name h1, my-video-watch h1, .video-title, .title' ); - var videoTitle = titleEl ? titleEl.textContent.trim() : 'Video'; + var videoTitle = titleEl + ? titleEl.textContent.trim() + : (document.title ? document.title.replace(/\s*-\s*(PeerTube|YakTube).*$/i, '').trim() : 'Video'); // 3. Setup Top-Level Skip Link: "🎬 Video Oynatıcıya Atla (Alt+P)" - if (!skipLink) { + if (!skipLink && !isEmbedUrl()) { skipLink = document.createElement('a'); skipLink.id = 'yaktube-skip-to-player'; skipLink.className = 'yaktube-skip-link'; @@ -2027,8 +2097,11 @@ try { document.body.insertBefore(skipLink, document.body.firstChild); } - // 4. Configure Player Container (#videojs-wrapper or .video-js) - var playerWrapper = document.getElementById('videojs-wrapper') || document.querySelector('.video-js'); + // 4. Configure Player Container (#videojs-wrapper or .video-js or #video-wrapper) + var playerWrapper = + document.getElementById('videojs-wrapper') || + document.querySelector('.video-js') || + document.getElementById('video-wrapper'); if (playerWrapper) { if (!playerWrapper.hasAttribute('data-yaktube-a11y-enhanced')) { playerWrapper.setAttribute('data-yaktube-a11y-enhanced', 'true'); @@ -2206,6 +2279,7 @@ try { // 3.1. Injects Accessible Player Action Bar under the Watch Video function injectAccessiblePlayerBar() { if (!isWatchUrl()) return; + if (isEmbedUrl()) return; var targetContainer = document.querySelector( 'my-video-watch, .video-watch, .watch-container, #yaktube-ondemand-container, .player-container, #video-wrapper, #videojs-wrapper' @@ -5315,9 +5389,3 @@ try { } catch (err) { console.error('[YakTube] Safe catch error:', err); } - -export async function register(options) { - return true; -} -export { register as registerClient }; -export default register; diff --git a/main.js b/main.js index 493cef7..8d4be9c 100644 --- a/main.js +++ b/main.js @@ -838,18 +838,38 @@ async function register({ getRouter, registerSetting, settingsManager, peertubeH }); // 6. Video YouTube Origin Detection Route + const BASE58_ALPHABET = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; + function shortToUuid(shortStr) { + if (!shortStr || typeof shortStr !== 'string' || shortStr.length < 20 || shortStr.length > 24) return shortStr; + if (/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(shortStr)) return shortStr; + try { + let num = 0n; + for (let i = 0; i < shortStr.length; i++) { + const idx = BASE58_ALPHABET.indexOf(shortStr[i]); + if (idx === -1) return shortStr; + num = num * 58n + BigInt(idx); + } + const hex = num.toString(16).padStart(32, '0'); + if (hex.length !== 32) return shortStr; + return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20, 32)}`; + } catch (e) { + return shortStr; + } + } + router.get('/video-origin/:uuid', async (req, res) => { - const uuid = (req.params.uuid || '').trim(); - if (!uuid) return res.status(400).json({ error: 'UUID required' }); + const rawParam = (req.params.uuid || '').trim(); + if (!rawParam) return res.status(400).json({ error: 'UUID required' }); + const resolvedUuid = shortToUuid(rawParam); try { const rows = await dbQuery( `SELECT v.id, v.uuid, v.name, v.description, vi."targetUrl" FROM "video" v LEFT JOIN "videoImport" vi ON vi."videoId" = v.id - WHERE v.uuid::text = $1 OR v."shortUUID" = $1 OR v.id::text = $1 + WHERE v.uuid::text = $1 OR v.id::text = $2 LIMIT 1`, - [uuid] + [resolvedUuid, rawParam] ); if (rows.length === 0) { return res.status(404).json({ error: 'Video not found' }); diff --git a/package.json b/package.json index a578b4e..290386c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "peertube-plugin-yaktube-ondemand", - "version": "1.5.10", + "version": "1.5.11", "description": "Accessible On-Demand YouTube Import, Live Streams, Smart Recommendations, Sleep Timer, Touch Gestures, Voice Assistant & A11y Engine for PeerTube", "main": "main.js", "library": "./main.js", diff --git a/style.css b/style.css index b1ac4d4..fdf81d6 100644 --- a/style.css +++ b/style.css @@ -1527,7 +1527,8 @@ my-date-toggle .date-toggle:focus-visible { line-height: 1 !important; } -.yaktube-vjs-seek-num { +.yaktube-vjs-seek-num, +.yaktube-vjs-speed-val { font-size: 10px !important; font-weight: 800 !important; font-family: