Skip to content

Commit

Permalink
Merge pull request #2147 from ThomSipkens/master
Browse files Browse the repository at this point in the history
Add option to automatically disable captions in lyrics/karaoke videos #1235
  • Loading branch information
ImprovedTube authored Apr 3, 2024
2 parents c4033e4 + aad0c15 commit 9240c71
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,9 @@
"subtitles": {
"message": "Subtitles"
},
"RemoveSubtitlesForLyrics": {
"message": "Remove subtitles for lyrics"
},
"sunset": {
"message": "Sunset"
},
Expand Down
1 change: 1 addition & 0 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
18 changes: 18 additions & 0 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
4 changes: 4 additions & 0 deletions menu/skeleton-parts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
Expand Down

0 comments on commit 9240c71

Please sign in to comment.