function sortVideos() { videos.sort((a, b) => b.likes - a.likes); displayVideos(); } function likeVideo(index) { videos[index].likes++; localStorage.setItem('videos', JSON.stringify(videos)); displayVideos(); } function dislikeVideo(index) { videos[index].dislikes++; localStorage.setItem('videos', JSON.stringify(videos)); displayVideos(); } function commentVideo(index) { const commentInput = document.getElementById(`comment-input-${index}`); if (commentInput.style.display === 'none' || commentInput.style.display === '') { commentInput.style.display = 'block'; } else { commentInput.style.display = 'none'; } } function addComment(index) { const commentText = document.getElementById(`comment-input-${index}`).value.trim(); if (commentText) { videos[index].comments.push({ text: commentText, user: tempUser ? tempUser.nick : 'Гость' }); localStorage.setItem('videos', JSON.stringify(videos)); displayComments(index); document.getElementById(`comment-input-${index}`).value = ''; } } function displayComments(index) { const commentsContainer = document.getElementById(`comments-${index}`); commentsContainer.innerHTML = ''; videos[index].comments.forEach((comment) => { const commentItem = document.createElement('p'); commentItem.textContent = `${comment.user}: ${comment.text}`; commentsContainer.appendChild(commentItem); }); } function deleteVideo(index) { videos.splice(index, 1); localStorage.setItem('videos', JSON.stringify(videos)); displayVideos(); } function editVideo(index) { const newTitle = prompt('Введите новое название видео:', videos[index].title); if (newTitle) { videos[index].title = newTitle; localStorage.setItem('videos', JSON.stringify(videos)); displayVideos(); } } function createChannel() { const channelName = document.getElementById('channel-name').value.trim(); if (!channelName) { alert('Пожалуйста, введите название канала.'); return; } if (channels.find(channel => channel.name === channelName)) { alert('Канал с таким названием уже существует.'); return; } const newChannel = { name: channelName, user: tempUser ? tempUser.nick : 'Гость', videos: [] }; channels.push(newChannel); localStorage.setItem('channels', JSON.stringify(channels)); displayChannelInfo(newChannel); document.getElementById('channel-name').value = ''; } function displayChannelInfo(channel) { const channelInfo = document.getElementById('channel-info'); channelInfo.textContent = `Канал "${channel.name}" создан. Пользователь: ${channel.user}.`; } function showAllVideos() { displayVideos(); } document.addEventListener('DOMContentLoaded', displayVideos);