-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (22 loc) · 864 Bytes
/
script.js
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
function getVideoId(youtubeUrl) {
if (youtubeUrl.startsWith("https://youtu.be/")) {
var urlParts = youtubeUrl.split("/");
return urlParts[urlParts.length - 1];
}
var videoId1 = youtubeUrl.split("v=")[1];
return videoId1.split("&")[0];
}
function playVideo() {
var youtubeUrl = document.getElementById("youtube-url").value;
var videoId = getVideoId(youtubeUrl);
var iframe = document.createElement("iframe");
iframe.src = "https://www.youtube.com/embed/" + videoId + "?autoplay=1";
iframe.width = "100%";
iframe.height = 540;
var player = document.getElementById("player");
player.innerHTML = "";
player.appendChild(iframe);
player.style.display = "block";
var searchContainer = document.getElementById("search-container");
searchContainer.style.transform = "translateY(0)";
}