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