Repository navigation
[xExtension-YouTube] Add an option to only load the player once clicked - #581
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
Every YouTube (or PeerTube) entry displayed embeds a player <iframe>, which loads the YouTube player, its scripts and its tracking requests. With many video entries on a page, this makes the page slow to render and floods the browser with requests, even for videos that the user never watches. Add an "Only load the player once the video thumbnail is clicked" checkbox to the configuration page, stored in the `yt_click_to_play` user attribute. When it is enabled, the extension inserts a link to the video showing its thumbnail instead of the player: - the thumbnail is the one of the entry (e.g. the `media:thumbnail` of YouTube feeds), or `i.ytimg.com/vi/<id>/hqdefault.jpg` for YouTube videos without one. When no thumbnail is available (e.g. a PeerTube entry without any), the player is embedded as before - the new `static/clickToPlay.js` replaces the preview by the usual player once clicked, with `autoplay=1` so that a single click starts the video. Control/command/shift/middle clicks keep the default link behaviour, e.g. to open the video in a new tab - the preview uses the configured width with a 16:9 ratio, or the responsive sizing when enabled, and shows a play button - without JavaScript, e.g. in API clients, it degrades to a thumbnail linking to the video The check preventing the player from being inserted twice now also matches the preview (and the responsive player, whose class attribute did not match before). The option is disabled by default, so existing installations keep their current behaviour. Add translations for all supported languages, and bump the extension version to 1.5.0. Fixes FreshRSS#236
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every YouTube/PeerTube entry displayed embeds a player
<iframe>, which loads the YouTube player, its scripts and tracking requests. With many video entries on a page (especially with the articles expanded), the page is slow to render and keeps sending requests, even for videos that are never watched (#236).yt_click_to_playuser attribute, disabled by default so existing installations keep their current behaviour)media:thumbnailof YouTube feeds), orhttps://i.ytimg.com/vi/<id>/hqdefault.jpgfor YouTube videos without one. If no thumbnail is available (e.g. a PeerTube entry without any), the player is embedded as beforestatic/clickToPlay.jsreplaces the preview by the usual player once clicked, withautoplay=1(andallow="autoplay") so a single click starts the video. Control/command/shift/middle clicks keep the default link behaviour, e.g. to open the video in a new tabclass="youtube-plugin-videoinstead of<iframe class="youtube-plugin-video", so it also matches the preview (and the responsive player, which it did not match before)Fixes #236
Validation
End-to-end with FreshRSS
edge(PHP 8.4, SQLite), the extension enabled, and a local feed containing a YouTube video with amedia:groupthumbnail, a Short without a thumbnail, and a PeerTube video without a thumbnail:main(iframes)i.ytimg.comfallback for the Short) and the PeerTube entry the iframe. In headless Chromium, a click replaces the preview by<iframe class="youtube-plugin-video" width="640" height="480" src="https://www.youtube.com/embed/aqz-KE-bpKQ?autoplay=1" …>without leaving the page, and a Control+click opens the video in a new tab and keeps the preview&or<are encoded once in thealtattribute of the thumbnailphp-lint,phtml-lint,phpcs,phpstan(with../FreshRSS),eslint,stylelintandmarkdownlint