Last active
October 30, 2018 10:24
-
-
Save musou1500/00572252b5880ec5085a05a3934cedc0 to your computer and use it in GitHub Desktop.
YouTubeの動画エリアをキャプチャして,pngファイルとして保存するブックマークレット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(() => { | |
const parseQueryString = (queryString) => { | |
const params = {}; | |
queryString | |
.split('&') | |
.forEach((str) => { | |
const [k, v] = str.split('='); | |
params[k] = decodeURIComponent(v); | |
}); | |
return params; | |
}; | |
const { v: videoId } = parseQueryString(location.search.substr(1)); | |
const videoElm = document.querySelector('video'); | |
const canvasElm = document.createElement('canvas'); | |
canvasElm.width = parseInt(videoElm.style.width); | |
canvasElm.height = parseInt(videoElm.style.height); | |
canvasElm.getContext('2d').drawImage(videoElm, 0, 0, canvasElm.width, canvasElm.height); | |
const anchorElm = document.createElement('a'); | |
anchorElm.setAttribute('download', `${videoId}.png`); | |
anchorElm.setAttribute('href', canvasElm.toDataURL("image/png").replace("image/png", "image/octet-stream")); | |
anchorElm.click(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment