YouTube Thumbnail Downloader
Get Thumbnail
Download Thumbnail
document.getElementById(‘downloadBtn’).addEventListener(‘click’, function() {
const videoUrl = document.getElementById(‘videoUrl’).value;
const videoId = extractVideoId(videoUrl);
if (videoId) {
const thumbnailUrl = `https://img.youtube.com/vi/${videoId}/maxresdefault.jpg`;
const thumbnailImg = document.getElementById(‘thumbnail’);
const downloadLink = document.getElementById(‘downloadLink’);
thumbnailImg.src = thumbnailUrl;
thumbnailImg.style.display = ‘block’;
downloadLink.href = thumbnailUrl;
downloadLink.style.display = ‘inline-block’;
document.getElementById(‘thumbnailContainer’).style.display = ‘block’;
} else {
alert(‘Please enter a valid YouTube video URL.’);
}
});
function extractVideoId(url) {
const regex = /(?:https?://)?(?:www.)?(?:youtube.com/(?:[^/ns]+/S+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu.be/)([a-zA-Z0-9_-]{11})/;
const matches = url.match(regex);
return matches ? matches[1] : null;
}
