Skip to content

Commit

Permalink
Merge pull request #2385 from raszpl/patch-15
Browse files Browse the repository at this point in the history
Captions rename for live updating, add option to force disable
  • Loading branch information
ImprovedTube authored Jun 17, 2024
2 parents 9b17645 + 8a09081 commit 2e850c8
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
51 changes: 31 additions & 20 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,19 @@ function getRandomInvidiousInstance() { return invidiousInstances[Math.floor(Mat
/*------------------------------------------------------------------------------
SUBTITLES
------------------------------------------------------------------------------*/
ImprovedTube.subtitles = function () {
if (this.storage.player_subtitles === true) {
var player = this.elements.player;

if (player && player.toggleSubtitlesOn) {
player.toggleSubtitlesOn();
ImprovedTube.playerSubtitles = function () {
const player = this.elements.player;

if (player && player.isSubtitlesOn && player.toggleSubtitles && player.toggleSubtitlesOn) {
switch(this.storage.player_subtitles) {
case true:
case 'enabled':
player.toggleSubtitlesOn();
break

case 'disabled':
if (player.isSubtitlesOn()) { player.toggleSubtitles(); }
break
}
}
};
Expand All @@ -226,13 +233,17 @@ ImprovedTube.subtitlesLanguage = function () {
const option = this.storage.subtitles_language,
player = this.elements.player,
button = this.elements.player_subtitles_button;
let subtitlesState;

if (option && player && player.getOption && button && button.getAttribute('aria-pressed') === 'true') {
if (option && player && player.getOption && player.isSubtitlesOn && player.toggleSubtitles && button && !button.title.includes('unavailable')) {
const tracklists = player.getOption('captions', 'tracklist', {includeAsr: true}),
matchedTrack = tracklists.find(element => element.languageCode.includes(option) && (!element.vss_id.includes("a.") || this.storage.auto_generate));

if (matchedTrack) {
subtitlesState = player.isSubtitlesOn();
player.setOption('captions', 'track', matchedTrack);
// setOption forces Subtitles ON, restore state from before calling it.
if (!subtitlesState) { player.toggleSubtitles(); }
}
}
};
Expand All @@ -247,15 +258,15 @@ SUBTITLES WINDOW OPACITY
SUBTITLES CHARACTER EDGE STYLE
SUBTITLES FONT OPACITY
default = {
"fontFamily": 4,
"color": "#fff",
"fontSizeIncrement": 0,
"background": "#080808",
"backgroundOpacity": 0.75,
"windowColor": "#080808",
"windowOpacity": 0,
"charEdgeStyle": 0,
"textOpacity": 1,
"fontFamily": 4,
"color": "#fff",
"fontSizeIncrement": 0,
"background": "#080808",
"backgroundOpacity": 0.75,
"windowColor": "#080808",
"windowOpacity": 0,
"charEdgeStyle": 0,
"textOpacity": 1,
},
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesUserSettings = function () {
Expand All @@ -274,7 +285,7 @@ ImprovedTube.subtitlesUserSettings = function () {
player = this.elements.player,
button = this.elements.player_subtitles_button;

if (option.length && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
if (option.length && player.getSubtitlesUserSettings && button && !button.title.includes('unavailable')) {
let settings = player.getSubtitlesUserSettings();

for (const value of option) {
Expand All @@ -299,11 +310,11 @@ ImprovedTube.subtitlesUserSettings = function () {
SUBTITLES DISABLE SUBTILES FOR LYRICS
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesDisableLyrics = function () {
if (this.storage.subtitles_disable_lyrics === true) {
if (this.storage.subtitles_disable_lyrics) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.toggleSubtitles && button && button.getAttribute('aria-pressed') === 'true') {
if (player && player.toggleSubtitles && button && !button.title.includes('unavailable')) {
// 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 Expand Up @@ -563,7 +574,7 @@ ImprovedTube.screenshot = function () {

cvs.toBlob(function (blob) {
if (ImprovedTube.storage.player_screenshot_save_as == 'clipboard') {
window.focus();
window.focus();
navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
Expand Down
14 changes: 12 additions & 2 deletions menu/skeleton-parts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,18 @@ extension.skeleton.main.layers.section.player.on.click = {
variant: 'card',

player_subtitles: {
component: 'switch',
text: 'subtitles'
component: 'select',
text: 'subtitles',
options: [{
value: 'auto',
text: 'auto'
}, {
value: 'enabled',
text: 'enabled'
}, {
value: 'disabled',
text: 'disabled'
}]
},
subtitles_language: {
component: 'select',
Expand Down

0 comments on commit 2e850c8

Please sign in to comment.