-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
55 lines (51 loc) · 1.28 KB
/
index.html
File metadata and controls
55 lines (51 loc) · 1.28 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>YouTube Loader</title>
<style>
body {
font-family: sans-serif;
text-align: center;
padding: 20px;
}
input {
padding: 10px;
width: 300px;
}
button {
padding: 10px 20px;
margin-left: 10px;
}
iframe {
margin-top: 20px;
width: 560px;
height: 315px;
}
</style>
</head>
<body>
<h2>YouTube Video Loader</h2>
<input type="text" id="ytLink" placeholder="Paste YouTube link here">
<button onclick="loadVideo()">Load Video</button>
<div id="videoPlayer"></div>
<script>
function getVideoId(url) {
const regex = /(?:youtube\.com\/watch\?v=|youtu\.be\/)([^\&\?\/]+)/;
const match = url.match(regex);
return match ? match[1] : null;
}
function loadVideo() {
const link = document.getElementById("ytLink").value;
const videoId = getVideoId(link);
if (videoId) {
document.getElementById("videoPlayer").innerHTML =
`<iframe src="https://www.youtube.com/embed/${videoId}" frameborder="0" allowfullscreen></iframe>`;
} else {
alert("Invalid YouTube link!");
}
}
</script>
</body>
</html>