From 601137b31d6a4653f78eca93c81da9130033994c Mon Sep 17 00:00:00 2001 From: ugackMiner Date: Sat, 10 Feb 2024 22:43:32 -0500 Subject: [PATCH 1/2] Added "disable video on hover" option to settings and playback. --- _locales/en/messages.json | 1 + js&css/extension/init.js | 1 + .../www.youtube.com/general/general.js | 18 ++++++++++++++++++ menu/skeleton-parts/general.js | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index b37e59825..6753475dc 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -131,6 +131,7 @@ "device":{"message":"Device"}, "dim":{"message":"Dim"}, "disabled":{"message":"Disabled"}, +"disableHoverVideo":{"message":"Disable video playback on hover"}, "dislike":{"message":"Dislike"}, "displayDayOfTheWeak":{"message":"Display day of the week"}, "doNotChange":{"message":"Don't change"}, diff --git a/js&css/extension/init.js b/js&css/extension/init.js index feabe4242..20783c574 100644 --- a/js&css/extension/init.js +++ b/js&css/extension/init.js @@ -39,6 +39,7 @@ extension.events.on('init', function () { extension.features.confirmationBeforeClosing(); extension.features.defaultContentCountry(); extension.features.popupWindowButtons(); + extension.features.disableHoverVideo(); extension.features.markWatchedVideos(); extension.features.relatedVideos(); extension.features.comments(); diff --git a/js&css/extension/www.youtube.com/general/general.js b/js&css/extension/www.youtube.com/general/general.js index 79f859fba..a1f9d6510 100644 --- a/js&css/extension/www.youtube.com/general/general.js +++ b/js&css/extension/www.youtube.com/general/general.js @@ -512,6 +512,24 @@ extension.features.thumbnailsQuality = function (anything) { } }; +/*-------------------------------------------------------------- +# DISABLE VIDEO PLAYBACK ON HOVER +--------------------------------------------------------------*/ +extension.features.disableHoverVideo = function (event) { + if (event instanceof Event) { + if (extension.storage.get('disable_thumbnail_playback') === true && + event.composedPath().some(elem => (elem.matches != null ? elem.matches("#content ytd-rich-item-renderer") : false) + )) { + event.stopImmediatePropagation(); + } + } else { + if (extension.storage.get('disable_thumbnail_playback') === true) { + window.addEventListener('mouseenter', this.disableHoverVideo, true); + } else { + window.removeEventListener('mouseenter', this.disableHoverVideo, true); + } + } +}; /*-------------------------------------------------------------- # OPEN VIDEOS IN A NEW TAB diff --git a/menu/skeleton-parts/general.js b/menu/skeleton-parts/general.js index 31b123eb6..45e2bb933 100644 --- a/menu/skeleton-parts/general.js +++ b/menu/skeleton-parts/general.js @@ -176,6 +176,10 @@ extension.skeleton.main.layers.section.general = { text: 'hideAnimatedThumbnails', tags: 'preview' }, + disable_thumbnail_playback: { + component: 'switch', + text: 'disableHoverVideo', + }, popup_window_buttons: { component: 'switch', text: 'popupWindowButtons', From 5c7543bbe65190693c8f40405a5e8ca8f1ca17cf Mon Sep 17 00:00:00 2001 From: ugackMiner Date: Sun, 11 Feb 2024 00:48:12 -0500 Subject: [PATCH 2/2] Standardized name to fix "simple" issue The setting would require a reload in order to work because the name "disable_thumbnail_playback" was different than disableHoverVideo. Everything is now "disableThumbnailPlayback" and seems to work. --- _locales/en/messages.json | 2 +- js&css/extension/init.js | 2 +- js&css/extension/www.youtube.com/general/general.js | 9 ++++----- menu/skeleton-parts/general.js | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6753475dc..ce44d89c3 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -131,7 +131,7 @@ "device":{"message":"Device"}, "dim":{"message":"Dim"}, "disabled":{"message":"Disabled"}, -"disableHoverVideo":{"message":"Disable video playback on hover"}, +"disableThumbnailPlayback":{"message":"Disable video playback on hover"}, "dislike":{"message":"Dislike"}, "displayDayOfTheWeak":{"message":"Display day of the week"}, "doNotChange":{"message":"Don't change"}, diff --git a/js&css/extension/init.js b/js&css/extension/init.js index 20783c574..bd08ec575 100644 --- a/js&css/extension/init.js +++ b/js&css/extension/init.js @@ -39,7 +39,7 @@ extension.events.on('init', function () { extension.features.confirmationBeforeClosing(); extension.features.defaultContentCountry(); extension.features.popupWindowButtons(); - extension.features.disableHoverVideo(); + extension.features.disableThumbnailPlayback(); extension.features.markWatchedVideos(); extension.features.relatedVideos(); extension.features.comments(); diff --git a/js&css/extension/www.youtube.com/general/general.js b/js&css/extension/www.youtube.com/general/general.js index a1f9d6510..266a68d0e 100644 --- a/js&css/extension/www.youtube.com/general/general.js +++ b/js&css/extension/www.youtube.com/general/general.js @@ -515,18 +515,17 @@ extension.features.thumbnailsQuality = function (anything) { /*-------------------------------------------------------------- # DISABLE VIDEO PLAYBACK ON HOVER --------------------------------------------------------------*/ -extension.features.disableHoverVideo = function (event) { +extension.features.disableThumbnailPlayback = function (event) { if (event instanceof Event) { - if (extension.storage.get('disable_thumbnail_playback') === true && - event.composedPath().some(elem => (elem.matches != null ? elem.matches("#content ytd-rich-item-renderer") : false) + if (event.composedPath().some(elem => (elem.matches != null ? elem.matches("#content ytd-rich-item-renderer") : false) )) { event.stopImmediatePropagation(); } } else { if (extension.storage.get('disable_thumbnail_playback') === true) { - window.addEventListener('mouseenter', this.disableHoverVideo, true); + window.addEventListener('mouseenter', this.disableThumbnailPlayback, true); } else { - window.removeEventListener('mouseenter', this.disableHoverVideo, true); + window.removeEventListener('mouseenter', this.disableThumbnailPlayback, true); } } }; diff --git a/menu/skeleton-parts/general.js b/menu/skeleton-parts/general.js index 45e2bb933..26a9c38ae 100644 --- a/menu/skeleton-parts/general.js +++ b/menu/skeleton-parts/general.js @@ -178,7 +178,7 @@ extension.skeleton.main.layers.section.general = { }, disable_thumbnail_playback: { component: 'switch', - text: 'disableHoverVideo', + text: 'disableThumbnailPlayback', }, popup_window_buttons: { component: 'switch',