Skip to content

Commit

Permalink
Merge pull request #2373 from raszpl/patch-5
Browse files Browse the repository at this point in the history
Update player.js ClipboardItem still not supported in FF
  • Loading branch information
ImprovedTube committed Jun 15, 2024
2 parents ae021ae + 2803bf1 commit 85bf124
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 37 deletions.
55 changes: 26 additions & 29 deletions js&css/web-accessible/www.youtube.com/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -540,45 +540,42 @@ SCREENSHOT
------------------------------------------------------------------------------*/
ImprovedTube.screenshot = function () {
const video = ImprovedTube.elements.video,
style = document.createElement('style'),
cvs = document.createElement('canvas'),
ctx = cvs.getContext('2d');

style.textContent = 'video{width:' + video.videoWidth + 'px !important;height:' + video.videoHeight + 'px !important}';
let subText = '';

cvs.width = video.videoWidth;
cvs.height = video.videoHeight;

document.body.appendChild(style);

setTimeout(function () {
ctx.drawImage(video, 0, 0, cvs.width, cvs.height);
let subText = '',
captionElements = document.querySelectorAll('.captions-text .ytp-caption-segment');
ctx.drawImage(video, 0, 0, cvs.width, cvs.height);

if (ImprovedTube.storage.embed_subtitle != false) {
let captionElements = document.querySelectorAll('.captions-text .ytp-caption-segment');
captionElements.forEach(function (caption) {subText += caption.textContent.trim() + ' ';});

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

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();
}
});
ImprovedTube.renderSubtitle(ctx,captionElements);
}

style.remove();
cvs.toBlob(function (blob) {
if (ImprovedTube.storage.player_screenshot_save_as == 'clipboard') {
window.focus();
navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
])
.then(function () { console.log("ImprovedTube: Screeeeeeenshot tada!"); })
.catch(function (error) {
console.log('ImprovedTube screenshot: ', error);
alert('ImprovedTube Screenshot to Clipboard error. Details in Debug Console.');
});
} else {
let a = document.createElement('a');
a.href = URL.createObjectURL(blob);
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();
console.log("ImprovedTube: Screeeeeeenshot tada!");
}
});
};

Expand Down
2 changes: 1 addition & 1 deletion js&css/web-accessible/www.youtube.com/shortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ ImprovedTube.shortcutDecreaseVolume = function () {
/*------------------------------------------------------------------------------
4.7.15 SCREENSHOT
------------------------------------------------------------------------------*/
ImprovedTube.shortcutScreenshot = function () { this.screenshot();};
ImprovedTube.shortcutScreenshot = ImprovedTube.screenshot;

/*------------------------------------------------------------------------------
4.7.16 INCREASE PLAYBACK SPEED
Expand Down
20 changes: 13 additions & 7 deletions menu/skeleton-parts/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1034,13 +1034,19 @@ extension.skeleton.main.layers.section.player.on.click = {
player_screenshot_save_as: {
component: 'select',
text: 'saveAs',
options: [{
text: 'file',
value: 'file'
}, {
text: 'clipboard',
value: 'clipboard'
}]
options: function () {
let options = [{
text: 'file',
value: 'file'
}];
if (typeof ClipboardItem == 'function') {
options.push({
text: 'clipboard',
value: 'clipboard'
});
}
return options;
}
},
player_fit_to_win_button: {
component: 'switch',
Expand Down

0 comments on commit 85bf124

Please sign in to comment.