From aad0c15198e68794148c682699c501781f3c001d Mon Sep 17 00:00:00 2001 From: ThomSipkens Date: Tue, 2 Apr 2024 10:27:29 +0200 Subject: [PATCH] Add option to automatically disable captions in lyrics/karaoke videos --- _locales/en/messages.json | 3 +++ js&css/web-accessible/functions.js | 1 + .../web-accessible/www.youtube.com/player.js | 18 ++++++++++++++++++ menu/skeleton-parts/player.js | 4 ++++ 4 files changed, 26 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 87bcc79dc..6273bd0dc 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1148,6 +1148,9 @@ "subtitles": { "message": "Subtitles" }, + "RemoveSubtitlesForLyrics": { + "message": "Remove subtitles for lyrics" + }, "sunset": { "message": "Sunset" }, diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index d8360f406..69f968b89 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -366,6 +366,7 @@ ImprovedTube.initPlayer = function () { ImprovedTube.subtitlesCharacterEdgeStyle(); ImprovedTube.subtitlesFontOpacity(); ImprovedTube.subtitlesBackgroundOpacity(); + ImprovedTube.subtitlesDisableLyrics(); ImprovedTube.playerQuality(); ImprovedTube.playerVolume(); if (this.storage.player_always_repeat === true) { ImprovedTube.playerRepeat(); } diff --git a/js&css/web-accessible/www.youtube.com/player.js b/js&css/web-accessible/www.youtube.com/player.js index 8e4a1f9d2..7f90c2384 100644 --- a/js&css/web-accessible/www.youtube.com/player.js +++ b/js&css/web-accessible/www.youtube.com/player.js @@ -416,6 +416,24 @@ ImprovedTube.subtitlesFontOpacity = function () { } }; /*------------------------------------------------------------------------------ +SUBTITLES DISABLE SUBTILES FOR LYRICS +------------------------------------------------------------------------------*/ +ImprovedTube.subtitlesDisableLyrics = function () { + if (this.storage.subtitles_disable_lyrics === true) { + var player = this.elements.player, + button = this.elements.player_subtitles_button; + + if (player && player.toggleSubtitles && button && button.getAttribute('aria-pressed') === 'true') { + // Music detection only uses 3 identifiers for Lyrics: lyrics, sing-along, karaoke. + // Easier to simply use those here. Can replace with music detection later. + const terms = ["sing?along", "karaoke", "lyric"]; + if (terms.some(term => ImprovedTube.videoTitle().toLowerCase().includes(term))) { + player.toggleSubtitles(); + } + } + } +}; +/*------------------------------------------------------------------------------ UP NEXT AUTOPLAY ------------------------------------------------------------------------------*/ ImprovedTube.upNextAutoplay = function () { diff --git a/menu/skeleton-parts/player.js b/menu/skeleton-parts/player.js index cab4c27fb..20414c485 100644 --- a/menu/skeleton-parts/player.js +++ b/menu/skeleton-parts/player.js @@ -680,6 +680,10 @@ extension.skeleton.main.layers.section.player.on.click = { min: 0, max: 100, step: 1 + }, + subtitles_disable_lyrics: { + component: 'switch', + text: 'RemoveSubtitlesForLyrics' } } }