From 7a65e3cf384b3c5b533df6e7f0da6c29172a92ef Mon Sep 17 00:00:00 2001 From: NopeCharon <115794254+NopeCharon@users.noreply.github.com> Date: Mon, 16 Nov 2026 07:36:29 +0530 Subject: [PATCH] [xExtension-YouTube] Add an option to only load the player once clicked Every YouTube (or PeerTube) entry displayed embeds a player '; + if ($this->clickToPlay) { + $iframe = $this->getPreviewHtml($entry, $url) ?? $iframe; + } + if ($this->showContent) { $doc = new DOMDocument(); $doc->encoding = 'UTF-8'; @@ -641,6 +689,7 @@ public function handleConfigureAction(): void { FreshRSS_Context::userConf()->_attribute('yt_show_content', Minz_Request::paramBoolean('yt_show_content')); FreshRSS_Context::userConf()->_attribute('yt_download_channel_icons', Minz_Request::paramBoolean('yt_download_channel_icons')); FreshRSS_Context::userConf()->_attribute('yt_nocookie', Minz_Request::paramBoolean('yt_nocookie')); + FreshRSS_Context::userConf()->_attribute('yt_click_to_play', Minz_Request::paramBoolean('yt_click_to_play')); FreshRSS_Context::userConf()->save(); } diff --git a/xExtension-YouTube/i18n/de/ext.php b/xExtension-YouTube/i18n/de/ext.php index 05a76cd9..97d58f27 100644 --- a/xExtension-YouTube/i18n/de/ext.php +++ b/xExtension-YouTube/i18n/de/ext.php @@ -13,5 +13,6 @@ 'fetching_icons' => 'Fetching icons', 'finished_fetching_icons' => 'Finished fetching icons.', 'use_nocookie' => 'Verwende die Cookie-freie Domain www.youtube-nocookie.com', + 'click_to_play' => 'Den Player erst nach einem Klick auf das Vorschaubild laden', ), ); diff --git a/xExtension-YouTube/i18n/en/ext.php b/xExtension-YouTube/i18n/en/ext.php index 56a85ec1..445d3e13 100644 --- a/xExtension-YouTube/i18n/en/ext.php +++ b/xExtension-YouTube/i18n/en/ext.php @@ -13,5 +13,6 @@ 'fetching_icons' => 'Fetching icons', 'finished_fetching_icons' => 'Finished fetching icons.', 'use_nocookie' => 'Use the cookie-free domain www.youtube-nocookie.com', + 'click_to_play' => 'Only load the player once the video thumbnail is clicked', ), ); diff --git a/xExtension-YouTube/i18n/fr/ext.php b/xExtension-YouTube/i18n/fr/ext.php index 32f8937e..d63fde92 100644 --- a/xExtension-YouTube/i18n/fr/ext.php +++ b/xExtension-YouTube/i18n/fr/ext.php @@ -13,5 +13,6 @@ 'fetching_icons' => 'Récupération des icônes', 'finished_fetching_icons' => 'Récupération des icônes terminée.', 'use_nocookie' => 'Utiliser le domaine www.youtube-nocookie.com pour éviter les cookies', + 'click_to_play' => 'Ne charger le lecteur qu’après un clic sur la miniature de la vidéo', ), ); diff --git a/xExtension-YouTube/i18n/pl/ext.php b/xExtension-YouTube/i18n/pl/ext.php index 0f1f7768..fcf32d8b 100644 --- a/xExtension-YouTube/i18n/pl/ext.php +++ b/xExtension-YouTube/i18n/pl/ext.php @@ -13,5 +13,6 @@ 'fetching_icons' => 'Pobieranie ikon', 'finished_fetching_icons' => 'Zakończono pobieranie ikon.', 'use_nocookie' => 'Używaj domeny bez ciasteczek www.youtube-nocookie.com', + 'click_to_play' => 'Ładuj odtwarzacz dopiero po kliknięciu miniatury filmu', ), ); diff --git a/xExtension-YouTube/i18n/tr/ext.php b/xExtension-YouTube/i18n/tr/ext.php index 0d4e0434..70468359 100644 --- a/xExtension-YouTube/i18n/tr/ext.php +++ b/xExtension-YouTube/i18n/tr/ext.php @@ -13,5 +13,6 @@ 'fetching_icons' => 'Fetching icons', 'finished_fetching_icons' => 'Finished fetching icons.', 'use_nocookie' => 'Çerezsiz olan "www.youtube-nocookie.com" alan adını kullanın', + 'click_to_play' => 'Oynatıcıyı yalnızca video küçük resmine tıklandığında yükle', ), ); diff --git a/xExtension-YouTube/metadata.json b/xExtension-YouTube/metadata.json index 525d10b5..d47e9ec8 100644 --- a/xExtension-YouTube/metadata.json +++ b/xExtension-YouTube/metadata.json @@ -2,7 +2,7 @@ "name": "YouTube Video Feed", "author": "Kevin Papst, Inverle", "description": "Embed YouTube feeds inside article content.", - "version": "1.4.1", + "version": "1.5.0", "entrypoint": "YouTube", "type": "user" } diff --git a/xExtension-YouTube/static/clickToPlay.js b/xExtension-YouTube/static/clickToPlay.js new file mode 100644 index 00000000..8eb73483 --- /dev/null +++ b/xExtension-YouTube/static/clickToPlay.js @@ -0,0 +1,31 @@ +'use strict'; + +// Replace the preview of a video by its player once clicked, so that the player is only loaded when the user wants to watch the video +document.addEventListener('click', function (ev) { + if (ev.button !== 0 || ev.ctrlKey || ev.metaKey || ev.shiftKey || ev.altKey) { + return; // Keep the default behaviour of the link, e.g. to open the video in a new tab + } + const preview = ev.target.closest('a.yt-player-preview[data-yt-player-src]'); + if (!preview) { + return; + } + ev.preventDefault(); + + const src = new URL(preview.dataset.ytPlayerSrc, document.baseURI); + src.searchParams.set('autoplay', '1'); + + const iframe = document.createElement('iframe'); + iframe.className = 'youtube-plugin-video'; + if (preview.classList.contains('yt-player-autosize')) { + iframe.classList.add('yt-player-autosize'); + } else { + iframe.width = preview.dataset.ytPlayerWidth; + iframe.height = preview.dataset.ytPlayerHeight; + } + iframe.src = src.href; + iframe.setAttribute('frameborder', '0'); + iframe.referrerPolicy = 'strict-origin-when-cross-origin'; + iframe.allow = 'autoplay'; // Start the video, as it has just been clicked + iframe.allowFullscreen = true; + preview.replaceWith(iframe); +}); diff --git a/xExtension-YouTube/static/style.css b/xExtension-YouTube/static/style.css index e39adc12..f066c25c 100644 --- a/xExtension-YouTube/static/style.css +++ b/xExtension-YouTube/static/style.css @@ -2,3 +2,42 @@ width: 100%; aspect-ratio: 16 / 9; } + +.yt-player-preview { + display: block; + max-width: 100%; + width: fit-content; + position: relative; +} + +.yt-player-preview > img { + display: block; + height: auto; + aspect-ratio: 16 / 9; + object-fit: cover; +} + +.yt-player-preview.yt-player-autosize { + width: 100%; +} + +.yt-player-preview.yt-player-autosize > img { + width: 100%; + height: 100%; +} + +.yt-player-preview::after { + margin: auto; + background: url('data:image/svg+xml,') center / contain no-repeat; + width: 68px; + height: 48px; + position: absolute; + inset: 0; + content: ''; + opacity: 0.8; +} + +.yt-player-preview:hover::after, +.yt-player-preview:focus-visible::after { + opacity: 1; +}