YouTube Thumbnail Downloader
body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; justify-content: center; align-items: center; height: 100vh; background-color: #f2f2f2; } #thumbnailDownloaderForm { background-color: #fff; padding: 20px; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); text-align: center; max-width: 400px; width: 100%; } #result { margin-top: 20px; } button { background-color: #4caf50; color: white; padding: 10px 20px; font-size: 16px; border: none; border-radius: 4px; cursor: pointer; } button:hover { background-color: #45a049; } input { width: 80%; padding: 10px; margin: 8px 0; display: inline-block; border: 1px solid #ccc; box-sizing: border-box; border-radius: 4px; } img { max-width: 100%; height: auto; margin-top: 10px; }
function downloadThumbnail() { const videoUrlInput = document.getElementById('videoUrl'); const resultDiv = document.getElementById('result'); const videoUrl = videoUrlInput.value.trim(); // Use crossorigin.me as a proxy to fetch YouTube video details const proxyUrl = 'https://cors-anywhere.herokuapp.com/'; const apiUrl = `${proxyUrl}https://www.youtube.com/oembed?url=${videoUrl}&format=json`; fetch(apiUrl) .then(response => response.json()) .then(data => { if (data.thumbnail_url) { const thumbnailUrl = data.thumbnail_url; resultDiv.innerHTML = `
Thumbnail not found.
'; } }) .catch(error => { console.error('Error fetching data:', error); resultDiv.innerHTML = 'An error occurred. Please try again later.
'; }); }