Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <input type="text" id="videoId" placeholder="Youtube Video ID">
  <button type="button">Get Largest thumbnail</button>
  
  <div class="wrap"></div>
</body>
</html>
 
// getLargestYoutubeThumbnail by @ReallyGoodTeam, MIT
/* Sample youtube IDs
teYZM0Aft0A
wr1fa3ZaNYY
8e-BsJoaS20 - doesn't have maxresdefault
*/
function getLargestYoutubeThumbnail(youtubeId) {
  var def = $.Deferred();
  var img = new Image();
  img.onload = function() {
    if (this.width < 720) {
      def.resolve(img.src.replace('maxres', 'hq'));
    } else {
      def.resolve(img.src)
    }
  };
  img.src = 'https://img.youtube.com/vi/' + youtubeId + '/maxresdefault.jpg'
  
  return def.promise();
}
// example usage
$('button').click(function() {
  getLargestYoutubeThumbnail( $('#videoId').val() ).then(function(url) {
    console.log('got', arguments)
    $('.wrap').html('<img src="' + url + '">')
  });;
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
RonnyOpro
0viewers