-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.js
37 lines (33 loc) · 1.13 KB
/
video.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
30
31
32
33
34
35
36
37
document.addEventListener("DOMContentLoaded", function() {
const videoId = getVideoIdFromUrl();
if (videoId) {
fetchVideoData(videoId);
}
});
function getVideoIdFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get("id");
}
function fetchVideoData(videoId) {
fetch("videos.json")
.then(response => response.json())
.then(data => {
const video = data.videos.find(v => v.id === videoId);
if (video) {
displayVideo(video);
} else {
console.error("Video not found");
}
})
.catch(error => console.error(error));
}
function displayVideo(video) {
const videoTitle = document.getElementById("videoTitle");
const videoUploader = document.getElementById("videoUploader");
const videoUploadDate = document.getElementById("videoUploadDate");
const videoDescription = document.getElementById("videoDescription");
videoTitle.textContent = video.title;
videoUploader.textContent = "Uploaded by: " + video.uploader;
videoUploadDate.textContent = "Uploaded on: " + video.upload_date;
videoDescription.textContent = video.description;
}