Skip to content

Instantly share code, notes, and snippets.

@dwighthouse
Last active February 12, 2020 20:45
Show Gist options
  • Save dwighthouse/fbc175803d439a68e274bc3b666f7421 to your computer and use it in GitHub Desktop.
Save dwighthouse/fbc175803d439a68e274bc3b666f7421 to your computer and use it in GitHub Desktop.
Download YouTube Screenshot by running this in the console
(() => {
const youtubeVideoSelector = 'video';
const video = document.querySelector(youtubeVideoSelector);
const width = video.videoWidth;
const height = video.videoHeight;
const canvas = document.createElement('canvas');
const context = canvas.getContext('2d');
canvas.width = width;
canvas.height = height;
context.fillRect(0, 0, width, height);
context.drawImage(video, 0, 0, width, height);
canvas.toBlob((blob) => {
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
// Take advantage of known US English format
const parts = new Intl.DateTimeFormat('en-us', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
}).formatToParts(new Date());
a.download = `YouTube-Screenshot_${parts[4].value}-${parts[0].value}-${parts[2].value}`;
a.click();
setTimeout(() => {
URL.revokeObjectURL(a.href);
}, 1000);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment