A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
filter channel videos
Christian Feif6e8b728ef6c
diff --git a/client/index.html b/client/index.htmlindex 2d6227e..3b1cc9a 100644--- a/client/index.html+++ b/client/index.html@@ -14,7 +14,24 @@</header><button id="open-settings">🔧 Settings</button>-++ <main>+ <details class="downloaded-videos-container">+ <summary>Downloaded videos</summary>+ <div class="videos-container"></div>+ </details>+ <details class="channels-container">+ <summary>Channels</summary>+ <div></div>+ </details>+ <div class="main-videos-container"></div>+ <details class="download-log">+ <summary>Download Log</summary>+ <div class="lines"></div>+ </details>+ </main>++<dialog id="settings"><button id="close">X</button><div>@@ -46,18 +63,6 @@<div></div></dialog>- <main>- <details class="downloaded-videos-container">- <summary>Downloaded videos</summary>- <div class="videos-container"></div>- </details>- <div class="main-videos-container"></div>- <details class="download-log">- <summary>Download Log</summary>- <div class="lines"></div>- </details>- </main>-<script src="/main.js"></script></body></html>diff --git a/client/main.css b/client/main.cssindex 1d1da52..1247e38 100644--- a/client/main.css+++ b/client/main.css@@ -34,6 +34,21 @@ main {+.channels-container div {+ display: flex;+ justify-content: space-around;+ flex-wrap: wrap;+ align-items: center;+ gap: 10px;+ padding: 10px;+}+.channels-container div div {+ cursor: pointer;+ font-weight: bold;+}+.channels-container div div.active {+ color: #3498db;+}.channel-details.has-new-videos {background-color: #aeaeaediff --git a/client/main.js b/client/main.jsindex 485882e..fd63c9a 100644--- a/client/main.js+++ b/client/main.js@@ -178,6 +178,7 @@ eventSource.onmessage = (message) => {})updateDownloadedVideos(allVideos)+ updateChannels(Object.entries(data.videos).map(([channelName, _]) => channelName))window.videos = data.videos}if (data.type === 'summary' && data.videoId && data.summary && data.transcript) {@@ -194,6 +195,7 @@ eventSource.onmessage = (message) => {const videoData = JSON.parse($video.dataset['data'])videoData.downloaded = true$video.dataset['data'] = JSON.stringify(videoData)+ updateDownloadedVideos([data.videoId])}}} catch (err) {@@ -339,7 +341,7 @@ function createVideoElement (video) {return $video}-function updateDownloadedVideos (videos) {+function updateDownloadedVideos (videos = []) {const $downloadedVideosContainer = document.querySelector('details.downloaded-videos-container')const $videosContainer = $downloadedVideosContainer.querySelector('.videos-container')videos.filter(v => v.downloaded).forEach(v => {@@ -348,4 +350,38 @@ function updateDownloadedVideos (videos) {? $existing.replaceWith(createVideoElement(v)): $videosContainer.appendChild(createVideoElement(v))})+}++function updateChannels (channels = []) {+ channels.sort()+ const $channelsContainer = document.querySelector('details.channels-container div')+ channels.forEach(channel => {+ const $existingChannel = $channelsContainer.querySelector(`[data-channel="${channel}"]`)+ if ($existingChannel) {+ $existingChannel.replaceWith(createChannelElement(channel))+ } else {+ $channelsContainer.appendChild(createChannelElement(channel))+ }+ })+}++function createChannelElement (channel = '') {+ const $channel = document.createElement('div')+ $channel.dataset.channel = channel+ $channel.classList.add('channel')+ $channel.innerText = channel+ $channel.addEventListener('click', function (event) {++ const $searchInput = document.querySelector('#search')+ if ($searchInput.value === channel) {+ $searchInput.value = ''+ event.target.classList.remove('active')+ } else {+ $searchInput.value = channel+ event.target.parentNode.querySelector('.active')?.classList.remove('active')+ event.target.classList.add('active')+ }+ $searchInput.dispatchEvent(new Event('keyup'))+ })+ return $channel}\ No newline at end of file