Skip to content

Commit

Permalink
Merge pull request #2402 from raszpl/patch-8
Browse files Browse the repository at this point in the history
Update functions.js subtitles by button turned out dead end
  • Loading branch information
ImprovedTube authored Jun 22, 2024
2 parents 99e0134 + 7581d63 commit 81f6888
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
6 changes: 0 additions & 6 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
14 changes: 8 additions & 6 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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", "الكاريوكي", "караоке", "カラオケ","노래방"];
Expand Down

0 comments on commit 81f6888

Please # to comment.