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

Special 'satus_remove' value signaling default option, remove instead of storing #2220

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6b56ee0
Update satus.js special key signalling default option, remove instead…
raszpl Apr 28, 2024
5680053
Update satus.js removing check already performed above
raszpl Apr 29, 2024
2a02ed4
Update satus.js default switch to off, removes need for defining ever…
raszpl Apr 29, 2024
36131ca
Update satus.js switch.flip only saves active option, removes when di…
raszpl Apr 29, 2024
277f681
Update player.js use new special 'satus_remove' value for default option
raszpl Apr 29, 2024
68f9df2
Update player.js switch.flip defaults to value:false, no need for exp…
raszpl Apr 29, 2024
1bdc819
Update player.js subtitles_language dont store default option
raszpl Apr 29, 2024
b2fd294
Update player.js more concise subtitlesLanguage
raszpl Apr 29, 2024
3408c25
Update player.js subtitles_font_family 'Proportional Sans-Serif' is Y…
raszpl Apr 29, 2024
ab95846
Update player.js more concise subtitlesFontFamily
raszpl Apr 29, 2024
defabdc
satus.js select selectElement value is either stored value, or one wi…
raszpl Apr 29, 2024
52a9b9f
Update player.js more default 'satus_remove' switches
raszpl Apr 29, 2024
14863f2
Update player.js player_screenshot_save_as default
raszpl Apr 29, 2024
4abaeeb
Update player.js screenshot respecting removed default player_screens…
raszpl Apr 29, 2024
15277d4
Update player.js single subtitlesUserSettings function, fixed for def…
raszpl Apr 29, 2024
9c45f39
Update functions.js subtitles* functions combined into subtitlesUserS…
raszpl Apr 29, 2024
373b035
Update core.js handler for subtitlesUserSettings settings change
raszpl Apr 29, 2024
9e785b9
Update player.js optimizing down, confirm.modal cancels are optional
raszpl Apr 29, 2024
13b4494
Update satus.js make sliders remove default value
raszpl Apr 29, 2024
0238a7e
Update satus.js nicer looking
raszpl Apr 29, 2024
d18cea6
Update player.js reworking component: 'switch' from "custom: true" to…
raszpl Apr 30, 2024
3342afc
Update satus.js switch variant: 'manual' instead of custom: true
raszpl Apr 30, 2024
1253b9e
Update satus.js checkbox respects storage:false and value:true, autom…
raszpl Apr 30, 2024
2cf132f
Update satus.js more comments explaining functionality, simplifying code
raszpl May 1, 2024
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
12 changes: 12 additions & 0 deletions js&css/web-accessible/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,18 @@ document.addEventListener('it-message-from-extension', function () {
case 'blocklistActivate':
if (ImprovedTube.storage.blocklist_activate === true) {document.querySelectorAll('.it-add-to-blocklist').forEach(e => e.remove());}
break

case 'subtitlesFontFamily':
case 'subtitlesFontColor':
case 'subtitlesFontSize':
case 'subtitlesBackgroundColor':
case 'subtitlesWindowColor':
case 'subtitlesWindowOpacity':
case 'subtitlesCharacterEdgeStyle':
case 'subtitlesFontOpacity':
case 'subtitlesBackgroundOpacity':
ImprovedTube.subtitlesUserSettings();
break
}

if (ImprovedTube[camelized_key]) {
Expand Down
10 changes: 1 addition & 9 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,7 @@ ImprovedTube.initPlayer = function () {
ImprovedTube.playerPlaybackSpeed();
ImprovedTube.subtitles();
ImprovedTube.subtitlesLanguage();
ImprovedTube.subtitlesFontFamily();
ImprovedTube.subtitlesFontColor();
ImprovedTube.subtitlesFontSize();
ImprovedTube.subtitlesBackgroundColor();
ImprovedTube.subtitlesWindowColor();
ImprovedTube.subtitlesWindowOpacity();
ImprovedTube.subtitlesCharacterEdgeStyle();
ImprovedTube.subtitlesFontOpacity();
ImprovedTube.subtitlesBackgroundOpacity();
ImprovedTube.subtitlesUserSettings();
ImprovedTube.subtitlesDisableLyrics();
ImprovedTube.playerQuality();
ImprovedTube.playerVolume();
Expand Down
275 changes: 68 additions & 207 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,216 +203,76 @@ ImprovedTube.subtitles = function () {
SUBTITLES LANGUAGE
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesLanguage = function () {
var option = this.storage.subtitles_language;
if (this.isset(option) && option !== 'default') {
var player = this.elements.player,
button = this.elements.player_subtitles_button;
const option = this.storage.subtitles_language,
player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getOption && button && button.getAttribute('aria-pressed') === 'true') {
var tracklist = this.elements.player.getOption('captions', 'tracklist', {
includeAsr: true
});
if (option && player && player.getOption && button && button.getAttribute('aria-pressed') === 'true') {
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));

var matchTrack = false;
for (var i =0, l = tracklist.length; i<l; i++){
if (tracklist[i].languageCode.includes(option)) {
if( false === tracklist[i].vss_id.includes("a.") || true === this.storage.auto_generate){
this.elements.player.setOption('captions', 'track', tracklist[i]);
matchTrack = true; break;
}
}
}
// if (!matchTrack){ player.toggleSubtitles(); }
if (matchedTrack) {
player.setOption('captions', 'track', matchedTrack);
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES FONT FAMILY
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesFontFamily = function () {
var option = this.storage.subtitles_font_family;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.fontFamily = Number(option);

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES FONT COLOR
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesFontColor = function () {
var option = this.storage.subtitles_font_color;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.color = option;

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES FONT SIZE
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesFontSize = function () {
var option = this.storage.subtitles_font_size;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.fontSizeIncrement = Number(option);

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES BACKGROUND COLOR
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesBackgroundColor = function () {
var option = this.storage.subtitles_background_color;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.background = option;

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES BACKGROUND OPACITY
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesBackgroundOpacity = function () {
var option = this.storage.subtitles_background_opacity;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.backgroundOpacity = option / 100;

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES WINDOW COLOR
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesWindowColor = function () {
var option = this.storage.subtitles_window_color;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.windowColor = option;

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES WINDOW OPACITY
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesWindowOpacity = function () {
var option = this.storage.subtitles_window_opacity;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.windowOpacity = Number(option) / 100;

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES CHARACTER EDGE STYLE
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesCharacterEdgeStyle = function () {
var option = this.storage.subtitles_character_edge_style;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.charEdgeStyle = Number(option);

player.updateSubtitlesUserSettings(settings);
}
}
}
};
/*------------------------------------------------------------------------------
SUBTITLES FONT OPACITY
default = {
"fontFamily": 4,
"color": "#fff",
"fontSizeIncrement": 0,
"background": "#080808",
"backgroundOpacity": 0.75,
"windowColor": "#080808",
"windowOpacity": 0,
"charEdgeStyle": 0,
"textOpacity": 1,
},
------------------------------------------------------------------------------*/
ImprovedTube.subtitlesFontOpacity = function () {
var option = this.storage.subtitles_font_opacity;

if (this.isset(option)) {
var player = this.elements.player,
button = this.elements.player_subtitles_button;

if (player && player.getSubtitlesUserSettings && button && button.getAttribute('aria-pressed') === 'true') {
var settings = player.getSubtitlesUserSettings();

if (settings) {
settings.textOpacity = option / 100;

player.updateSubtitlesUserSettings(settings);
ImprovedTube.subtitlesUserSettings = function () {
const ourSettings = [
['fontFamily', 'number', this.storage.subtitles_font_family],
['color', 'color', this.storage.subtitles_font_color],
['fontSizeIncrement', 'number', this.storage.subtitles_font_size],
['background', 'color', this.storage.subtitles_background_color],
['backgroundOpacity', 'fraction', this.storage.subtitles_background_opacity],
['windowColor', 'color', this.storage.subtitles_window_color],
['windowOpacity', 'fraction', this.storage.subtitles_window_opacity],
['charEdgeStyle', 'number', this.storage.subtitles_character_edge_style],
['textOpacity', 'fraction', this.storage.subtitles_font_opacity]
],
option = ourSettings.filter(element => element[2]),
player = this.elements.player,
button = this.elements.player_subtitles_button;

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

for (const value of option) {
switch(value[1]) {
case 'number':
settings[value[0]] = Number(value[2]);
break;

case 'color':
settings[value[0]] = value[2];
break;

case 'fraction':
settings[value[0]] = Number(option) / 100;
break;
}
}
player.updateSubtitlesUserSettings(settings);
}
};
/*------------------------------------------------------------------------------
Expand Down Expand Up @@ -625,7 +485,7 @@ ImprovedTube.playerLoudnessNormalization = function () {
SCREENSHOT
------------------------------------------------------------------------------*/
ImprovedTube.screenshot = function () {
var video = ImprovedTube.elements.video,
const video = ImprovedTube.elements.video,
style = document.createElement('style'),
cvs = document.createElement('canvas'),
ctx = cvs.getContext('2d');
Expand All @@ -639,27 +499,28 @@ ImprovedTube.screenshot = function () {

setTimeout(function () {
ctx.drawImage(video, 0, 0, cvs.width, cvs.height);
var subText = '';
var captionElements = document.querySelectorAll('.captions-text .ytp-caption-segment');
captionElements.forEach(function (caption) {subText += caption.textContent.trim() + ' ';});

if(ImprovedTube.storage.embed_subtitle === true){ImprovedTube.renderSubtitle(ctx,captionElements);}

cvs.toBlob(function (blob) {
if (ImprovedTube.storage.player_screenshot_save_as !== 'clipboard') {
var a = document.createElement('a');
a.href = URL.createObjectURL(blob); console.log("screeeeeeenshot tada!");
let subText = '',
captionElements = document.querySelectorAll('.captions-text .ytp-caption-segment');

captionElements.forEach(function (caption) {subText += caption.textContent.trim() + ' ';});

a.download = (ImprovedTube.videoId() || location.href.match) + ' ' + new Date(ImprovedTube.elements.player.getCurrentTime() * 1000).toISOString().substr(11, 8).replace(/:/g, '-') + ' ' + ImprovedTube.videoTitle() + (subText ? ' - ' + subText.trim() : '') + '.png';
if (ImprovedTube.storage.embed_subtitle != false) {
ImprovedTube.renderSubtitle(ctx,captionElements);
}

a.click();
} else {
cvs.toBlob(function (blob) {
if (ImprovedTube.storage.player_screenshot_save_as == 'clipboard') {
navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
]);
} else {
let a = document.createElement('a');
a.href = URL.createObjectURL(blob);
console.log("screeeeeeenshot tada!");
a.download = (ImprovedTube.videoId() || location.href.match) + ' ' + new Date(ImprovedTube.elements.player.getCurrentTime() * 1000).toISOString().substr(11, 8).replace(/:/g, '-') + ' ' + ImprovedTube.videoTitle() + (subText ? ' - ' + subText.trim() : '') + '.png';
a.click();
}
});

Expand Down Expand Up @@ -1442,4 +1303,4 @@ ImprovedTube.miniPlayer = function () {
window.removeEventListener('scroll', this.miniPlayer_scroll);
window.removeEventListener('mousemove', this.miniPlayer_cursorUpdate);
}
};
};
Loading