|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>YouTube Thumbnail Viewer</title> |
| 7 | + <style> |
| 8 | + body { |
| 9 | + font-family: Arial, sans-serif; |
| 10 | + margin: 20px; |
| 11 | + max-width: 800px; |
| 12 | + margin: 0 auto; |
| 13 | + padding: 1em; |
| 14 | + } |
| 15 | + input { |
| 16 | + width: 100%; |
| 17 | + padding: 10px; |
| 18 | + font-size: 18px; |
| 19 | + margin-bottom: 20px; |
| 20 | + box-sizing: border-box; |
| 21 | + } |
| 22 | + .thumbnail-container { |
| 23 | + display: flex; |
| 24 | + flex-direction: column; |
| 25 | + gap: 20px; |
| 26 | + } |
| 27 | + .thumbnail { |
| 28 | + text-align: center; |
| 29 | + } |
| 30 | + .thumbnail img { |
| 31 | + max-width: 90%; |
| 32 | + width: auto; |
| 33 | + height: auto; |
| 34 | + border: 1px solid #ddd; |
| 35 | + padding: 5px; |
| 36 | + transition: max-width 0.3s ease; |
| 37 | + } |
| 38 | + .thumbnail img.expanded { |
| 39 | + max-width: none; |
| 40 | + } |
| 41 | + .thumbnail p { |
| 42 | + margin-top: 5px; |
| 43 | + font-size: 14px; |
| 44 | + word-break: break-all; |
| 45 | + } |
| 46 | + .thumbnail-url { |
| 47 | + background-color: #f9f9f9; |
| 48 | + padding: 5px; |
| 49 | + border-radius: 5px; |
| 50 | + display: flex; |
| 51 | + align-items: center; |
| 52 | + justify-content: center; |
| 53 | + } |
| 54 | + .copy-icon { |
| 55 | + margin-left: 5px; |
| 56 | + cursor: pointer; |
| 57 | + } |
| 58 | + </style> |
| 59 | +</head> |
| 60 | +<body> |
| 61 | + |
| 62 | + <h1>YouTube Thumbnail Viewer</h1> |
| 63 | + <p>Enter a YouTube URL or Video ID:</p> |
| 64 | + <input type="text" id="videoInput" placeholder="Paste YouTube URL or video ID here" oninput="updateThumbnails()"> |
| 65 | + |
| 66 | + <div id="thumbnails" class="thumbnail-container"></div> |
| 67 | + |
| 68 | + <script> |
| 69 | + function extractVideoID(url) { |
| 70 | + const regex = /(?:https?:\/\/(?:www\.)?youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|embed)\/|.*[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/; |
| 71 | + const match = url.match(regex); |
| 72 | + return match ? match[1] : url; |
| 73 | + } |
| 74 | + |
| 75 | + function updateThumbnails() { |
| 76 | + const input = document.getElementById("videoInput").value.trim(); |
| 77 | + const videoID = extractVideoID(input); |
| 78 | + if (videoID.length === 11) { |
| 79 | + const imageTypes = ['default', 'hqdefault', 'mqdefault', 'sddefault', 'maxresdefault', '0', '1', '2', '3']; |
| 80 | + const container = document.getElementById("thumbnails"); |
| 81 | + container.innerHTML = ''; |
| 82 | + |
| 83 | + imageTypes.forEach(type => { |
| 84 | + const imageUrl = `https://img.youtube.com/vi/${videoID}/${type}.jpg`; |
| 85 | + const thumbnailHTML = ` |
| 86 | + <div class="thumbnail"> |
| 87 | + <img src="${imageUrl}" alt="Thumbnail ${type}" onclick="toggleExpand(this)"> |
| 88 | + <p class="image-size"></p> |
| 89 | + <div class="thumbnail-url"> |
| 90 | + <span>${imageUrl}</span> |
| 91 | + <span class="copy-icon" onclick="copyText('${imageUrl}')">📋</span> |
| 92 | + </div> |
| 93 | + </div> |
| 94 | + `; |
| 95 | + container.innerHTML += thumbnailHTML; |
| 96 | + }); |
| 97 | + |
| 98 | + // Get actual image sizes after they've loaded |
| 99 | + document.querySelectorAll('.thumbnail img').forEach(img => { |
| 100 | + img.onload = function() { |
| 101 | + this.nextElementSibling.textContent = `Width: ${this.naturalWidth}px`; |
| 102 | + } |
| 103 | + }); |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + function toggleExpand(img) { |
| 108 | + img.classList.toggle('expanded'); |
| 109 | + } |
| 110 | + |
| 111 | + function copyText(text) { |
| 112 | + navigator.clipboard.writeText(text).then(() => { |
| 113 | + console.log('Copied to clipboard'); |
| 114 | + }).catch(err => { |
| 115 | + console.error('Failed to copy: ', err); |
| 116 | + }); |
| 117 | + } |
| 118 | + </script> |
| 119 | + |
| 120 | +</body> |
| 121 | +</html> |
0 commit comments