Skip to content

Commit

Permalink
Update player.js screenshot respecting removed default player_screens…
Browse files Browse the repository at this point in the history
…hot_save_as

fixed embed_subtitle setting - it wasnt working with default embed_subtitle.value: true
  • Loading branch information
raszpl committed Apr 29, 2024
1 parent 14863f2 commit 4abaeeb
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,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 @@ -625,27 +625,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

0 comments on commit 4abaeeb

Please sign in to comment.