let videoDetails = {};
let comments = [];
async function loadVideoData() {
try {
const response = await fetch('src/video.json');
const data = await response.json();
videoDetails = {};
data.videos.forEach(video => {
videoDetails[video.id] = video;
});
comments = data.comments;
} catch (error) {
console.error('Failed to load video data:', error);
}
}
function getVideoIdFromUrl() {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get('id');
}
function loadVideoInfo() {
const videoId = getVideoIdFromUrl();
const videoInfo = videoDetails[videoId];
if (videoInfo) {
document.getElementById('videoTitle').textContent = videoInfo.title;
document.getElementById('channelName').textContent = videoInfo.channel;
document.getElementById('channelSubscribers').textContent = videoInfo.subscribers;
document.getElementById('likeCount').textContent = videoInfo.likes;
document.getElementById('videoViews').textContent = videoInfo.views + ' views';
document.getElementById('videoUploadDate').textContent = videoInfo.uploadDate;
document.getElementById('videoDescription').textContent = videoInfo.description;
const channelAvatar = document.getElementById('channelAvatar');
if (videoInfo.channelAvatar && videoInfo.channelAvatar !== 'img/avatar/default.jpg') {
channelAvatar.innerHTML = ``;
}
document.title = videoInfo.title + ' - YouTube Revived';
}
renderComments();
}
function renderComments() {
const commentsList = document.getElementById('commentsList');
const commentsCount = document.getElementById('commentsCount');
commentsCount.textContent = comments.length + ' Comments';
commentsList.innerHTML = '';
comments.forEach(comment => {
const commentElement = document.createElement('div');
commentElement.className = 'comment-item';
commentElement.innerHTML = `
${comment.content}