diff --git a/xExtension-YouTube/README.md b/xExtension-YouTube/README.md
index 6da2f57a..dcb710ab 100644
--- a/xExtension-YouTube/README.md
+++ b/xExtension-YouTube/README.md
@@ -8,6 +8,7 @@ To use it, upload the ```xExtension-YouTube``` directory to the FreshRSS `./exte
- Embeds Youtube videos directly in FreshRSS, instead of linking to the Youtube page
- Simplifies the subscription to channel URLs by automatically detecting the channels feed URL
+- Optionally shows only the video thumbnail, and loads the player once it is clicked, so that the pages load faster and the players do not contact YouTube until you decide to watch a video
You can simply add Youtube video subscriptions by pasting URLs like:
- `https://www.youtube.com/channel/UCwbjxO5qQTMkSZVueqKwxuw`
@@ -23,6 +24,9 @@ With activated Youtube extension:
## Changelog
+1.5.0:
+- Added an option to only load the player once the video thumbnail is clicked
+
1.4.1:
- Fixed the original thumbnail, description and enclosures of the feed being appended below the video
diff --git a/xExtension-YouTube/configure.phtml b/xExtension-YouTube/configure.phtml
index 247800e2..153f1902 100644
--- a/xExtension-YouTube/configure.phtml
+++ b/xExtension-YouTube/configure.phtml
@@ -51,6 +51,13 @@ declare(strict_types=1);
+
+
+
+
diff --git a/xExtension-YouTube/extension.php b/xExtension-YouTube/extension.php
index 95b71a76..5c912187 100644
--- a/xExtension-YouTube/extension.php
+++ b/xExtension-YouTube/extension.php
@@ -37,6 +37,10 @@ final class YouTubeExtension extends Minz_Extension
* Switch to enable the Youtube No-Cookie domain
*/
private bool $useNoCookie = false;
+ /**
+ * Whether a preview of the video is displayed instead of the player, which is only loaded once the preview is clicked
+ */
+ private bool $clickToPlay = false;
/**
* Initialize this extension
@@ -44,6 +48,7 @@ final class YouTubeExtension extends Minz_Extension
#[\Override]
public function init(): void {
Minz_View::appendStyle($this->getFileUrl('style.css'));
+ Minz_View::appendScript($this->getFileUrl('clickToPlay.js'));
$this->registerHook('entry_before_display', $this->embedYouTubeVideo(...));
$this->registerHook('check_url_before_add', self::convertYoutubeFeedUrl(...));
$this->registerHook('custom_favicon_hash', $this->iconHashParams(...));
@@ -355,6 +360,11 @@ public function loadConfigValues(): void {
if ($noCookie !== null) {
$this->useNoCookie = $noCookie;
}
+
+ $clickToPlay = FreshRSS_Context::userConf()->attributeBool('yt_click_to_play');
+ if ($clickToPlay !== null) {
+ $this->clickToPlay = $clickToPlay;
+ }
}
/**
@@ -413,6 +423,14 @@ public function isUseNoCookieDomain(): bool {
return $this->useNoCookie;
}
+ /**
+ * Returns whether a preview of the video is displayed instead of the player, until it is clicked.
+ * You have to call loadConfigValues() before this one, otherwise you get default values.
+ */
+ public function isClickToPlay(): bool {
+ return $this->clickToPlay;
+ }
+
/**
* Inserts the YouTube video iframe into the content of an entry, if the entries link points to a YouTube watch URL.
* @throws FreshRSS_Context_Exception
@@ -434,7 +452,8 @@ public function embedYouTubeVideo(FreshRSS_Entry $entry): FreshRSS_Entry {
return $entry;
}
- if (stripos($entry->content(), '