From 724d7826f22c517205706de5823369197864149b Mon Sep 17 00:00:00 2001 From: Rasz_pl Date: Fri, 21 Jun 2024 01:33:08 +0200 Subject: [PATCH 1/2] Update functions.js subtitles by button turned out dead end --- js&css/web-accessible/functions.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/js&css/web-accessible/functions.js b/js&css/web-accessible/functions.js index d962d5aa5..e7fa681b1 100644 --- a/js&css/web-accessible/functions.js +++ b/js&css/web-accessible/functions.js @@ -654,9 +654,3 @@ ImprovedTube.extractSubscriberCount = function (subscriberCountNode) { ImprovedTube.subscriberCount = subscriberCount; } }; - -// true if any subtitles are available at this moment -// YT doesnt have a function returning status of captions currently loaded, checking button color is the only way I could find :( -ImprovedTube.subtitlesEnabled = function () { - return this.elements.player_subtitles_button?.childNodes?.[0]?.getAttribute('fill-opacity') == 1; -}; From 7581d633c28e05338c8809cb3b734e910a18eb7d Mon Sep 17 00:00:00 2001 From: Rasz_pl Date: Fri, 21 Jun 2024 01:38:58 +0200 Subject: [PATCH 2/2] Update player.js rely on YT player native subtitle functions --- js&css/web-accessible/www.youtube.com/player.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/js&css/web-accessible/www.youtube.com/player.js b/js&css/web-accessible/www.youtube.com/player.js index cf7aec515..083be0422 100644 --- a/js&css/web-accessible/www.youtube.com/player.js +++ b/js&css/web-accessible/www.youtube.com/player.js @@ -203,7 +203,7 @@ SUBTITLES ImprovedTube.playerSubtitles = function () { const player = this.elements.player; - if (player && this.subtitlesEnabled() && player.isSubtitlesOn && player.toggleSubtitles && player.toggleSubtitlesOn) { + if (player && player.isSubtitlesOn && player.toggleSubtitles && player.toggleSubtitlesOn) { switch(this.storage.player_subtitles) { case true: case 'enabled': @@ -224,7 +224,7 @@ ImprovedTube.subtitlesLanguage = function () { player = this.elements.player; let subtitlesState; - if (option && player && this.subtitlesEnabled() && player.getOption && player.setOption && player.isSubtitlesOn && player.toggleSubtitles) { + if (option && player && player.getOption && player.setOption && player.isSubtitlesOn && player.toggleSubtitles) { const matchedTrack = player.getOption('captions', 'tracklist', {includeAsr: true})?.find(track => track.languageCode.includes(option) && (!track.vss_id.includes("a.") || this.storage.auto_generate)); if (matchedTrack) { @@ -272,9 +272,11 @@ ImprovedTube.subtitlesUserSettings = function () { userSettings = Object.keys(ourSettings).filter(e => ourSettings[e]), player = this.elements.player; - if (userSettings.length && player && this.subtitlesEnabled() && player.getSubtitlesUserSettings && player.updateSubtitlesUserSettings) { + if (userSettings.length && player && player.getSubtitlesUserSettings && player.updateSubtitlesUserSettings) { let ytSettings = player.getSubtitlesUserSettings(), setting; + + if (!ytSettings) return; //null SubtitlesUserSettings seem to mean subtitles not available for (const value of userSettings) { setting = null; @@ -298,10 +300,10 @@ ImprovedTube.subtitlesUserSettings = function () { break; } - if (ytSettings?.hasOwnProperty(value) && setting) { + if (ytSettings?.hasOwnProperty(value)) { ytSettings[value] = setting; } else { - console.error('subtitlesUserSettings failed at: ',value, setting); + console.error('subtitlesUserSettings failed at: ', value, setting); } } player.updateSubtitlesUserSettings(ytSettings); @@ -314,7 +316,7 @@ ImprovedTube.subtitlesDisableLyrics = function () { if (this.storage.subtitles_disable_lyrics) { const player = this.elements.player; - if (player && this.subtitlesEnabled() && player.isSubtitlesOn && player.isSubtitlesOn() && player.toggleSubtitles) { + if (player && player.isSubtitlesOn && player.isSubtitlesOn() && player.toggleSubtitles) { // 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", "sing-along", "karaoke", "lyric", "卡拉OK", "卡拉OK", "الكاريوكي", "караоке", "カラオケ","노래방"];