4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

YouTubeの動画をスクショするブックマークレット

4
Last updated at Posted at 2018-01-26

作りました!!

ブックマークレット

javascript:(()=>{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()})();

ソースコード

(() => {
  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()
})();
4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?