From 107be77ee6cd505038f2577ca53e99d486c76b99 Mon Sep 17 00:00:00 2001 From: Alexander Farkas Date: Sun, 4 Aug 2019 19:43:13 +0200 Subject: [PATCH] Make yt thumb size configurable (see #681) --- plugins/video-embed/ls.video-embed.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/video-embed/ls.video-embed.js b/plugins/video-embed/ls.video-embed.js index 52c8aa96..fdab5d0d 100644 --- a/plugins/video-embed/ls.video-embed.js +++ b/plugins/video-embed/ls.video-embed.js @@ -25,8 +25,9 @@ ; var idIndex = Date.now(); var regId = /\{\{id}}/; + var regYtImg = /\{\{hqdefault}}/; var regAmp = /^&/; - var youtubeImg = protocol + '//img.youtube.com/vi/{{id}}/hqdefault.jpg'; + var youtubeImg = protocol + '//img.youtube.com/vi/{{id}}/{{hqdefault}}.jpg'; var youtubeIframe = protocol + '//www.youtube.com/embed/{{id}}?autoplay=1'; var vimeoApi = protocol + '//vimeo.com/api/oembed.json?url=https%3A//vimeo.com/{{id}}'; var vimeoIframe = protocol + '//player.vimeo.com/video/{{id}}?autoplay=1'; @@ -77,7 +78,9 @@ } function embedYoutubeImg(id, elem){ - elem.style.backgroundImage = 'url('+ youtubeImg.replace(regId, id) +')'; + var ytImg = elem.getAttribute('data-thumb-size') || lazySizes.cfg.ytThumb || 'hqdefault'; + + elem.style.backgroundImage = 'url('+ youtubeImg.replace(regId, id).replace(regYtImg, ytImg) +')'; elem.addEventListener('click', embedYoutubeIframe); }