Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update functions.js subtitles by button turned out dead end #2402

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading