A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
downloaded and summarized videos filters
Christian Fei4e3208dd5df8
diff --git a/client/components/video-element.js b/client/components/video-element.jsindex 67cd79f..9de1921 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -29,6 +29,10 @@ class VideoElement extends HTMLElement {this.classList.add('video')this.dataset['videoId'] = this.video.idthis.dataset['date'] = this.video.publishedAt+ if (this.video.summary) this.dataset['summarized'] = "true"+ else this.dataset['summarized'] = "false"+ if (this.video.downloaded) this.dataset['downloaded'] = "true"+ else this.dataset['downloaded'] = "false"this.innerHTML = /*html*/`${this.video.downloaded? /*html*/`<video controls width="280">diff --git a/client/index.html b/client/index.htmlindex 5841111..c6981f3 100644--- a/client/index.html+++ b/client/index.html@@ -16,14 +16,10 @@<main><channels-list></channels-list>- <details class="downloaded-videos-container">- <summary>Downloaded videos</summary>- <div class="videos-container"></div>- </details>- <details class="summarized-videos-container">- <summary>Summarized videos</summary>- <div class="videos-container"></div>- </details>+ <div class="flex space-around">+ <button id="show-downloaded-videos">Downloaded videos</button>+ <button id="show-summarized-videos">Summarized videos</button>+ </div><div class="main-videos-container"></div><details class="download-log"><summary>Download Log</summary>diff --git a/client/main.css b/client/main.cssindex cf5e47b..a10c7b4 100644--- a/client/main.css+++ b/client/main.css@@ -241,6 +241,16 @@ details {.flex {display: flex;- justify-content: space-between;+ justify-content: space-around;margin-top: 0.3em;+}+#show-summarized-videos.active, #show-downloaded-videos.active {+ background-color: #e2ffd8;+}++.show-downloaded-videos [data-downloaded="false"] {+ display: none;+}+.show-summarized-videos [data-summarized="false"] {+ display: none;}\ No newline at end of filediff --git a/client/main.js b/client/main.jsindex 6527b00..92ac463 100644--- a/client/main.js+++ b/client/main.js@@ -35,8 +35,6 @@ eventSource.onmessage = (message) => {allVideos.forEach(video => $videosContainer.appendChild(createVideoElement(video)))- updateDownloadedVideos(allVideos)- updateSummarizedVideos(allVideos)const channelsList = data.videos.reduce((acc, video) => {if (!acc.includes(video.channelName)) acc.push(video.channelName)return acc@@ -44,6 +42,7 @@ eventSource.onmessage = (message) => {document.querySelector('channels-list').dataset['list'] = channelsList}if (data.type === 'channel' && data.name && data.videos) {+ console.warn('unhandled', data)// data.videos.forEach(video => {// for (const $videoElement of $videosContainer.querySelectorAll('video-element')) {// const videoDate = new Date($videoElement.dataset['date'])@@ -64,7 +63,6 @@ eventSource.onmessage = (message) => {const videoData = JSON.parse($video.dataset['data'])Object.assign(videoData, { summary: data.summary, transcript: data.transcript })$video.dataset['data'] = JSON.stringify(videoData)- updateSummarizedVideos([videoData])})}if (data.type === 'downloaded' && data.videoId) {@@ -73,7 +71,6 @@ eventSource.onmessage = (message) => {const videoData = JSON.parse($video.dataset['data'])videoData.downloaded = true$video.dataset['data'] = JSON.stringify(videoData)- updateDownloadedVideos([videoData])})}} catch (err) {@@ -122,6 +119,16 @@ function applyIgnoredTerms (ignoredTerms) {}}+const $showDownloadedVideos = document.getElementById('show-downloaded-videos')+handleClick($showDownloadedVideos, (event) => {+ event.target.classList.toggle('active')+ document.body.classList.toggle('show-downloaded-videos')+})+const $showSummarizedVideos = document.getElementById('show-summarized-videos')+handleClick($showSummarizedVideos, (event) => {+ event.target.classList.toggle('active')+ document.body.classList.toggle('show-summarized-videos')+})// apply settingsapplyShowThumbnails(store.get(store.showThumbnailsKey))@@ -131,6 +138,11 @@ applyIgnoredTerms(store.get(store.ignoreTermsKey))observeDialogOpenPreventScroll($settings)observeDialogOpenPreventScroll($summary)+function handleClick ($el, handler) {+ if (!$el) return+ $el.addEventListener('click', handler)+ $el.addEventListener('keydown', (event) => event.key === 'Enter' && handler(event))+}function observeDialogOpenPreventScroll (dialog) {new MutationObserver((mutationList, observer) => {@@ -157,24 +169,3 @@ function createVideoElement (video) {$video.dataset['videoId'] = video.idreturn $video}--function updateDownloadedVideos (videos = []) {- const $downloadedVideosContainer = document.querySelector('details.downloaded-videos-container')- const $videosContainer = $downloadedVideosContainer.querySelector('.videos-container')- videos.filter(v => v.downloaded).forEach(v => {- const $existing = $downloadedVideosContainer.querySelector(`[data-video-id="${v.id}"]`)- return $existing- ? $existing.replaceWith(createVideoElement(v))- : $videosContainer.appendChild(createVideoElement(v))- })-}-function updateSummarizedVideos (videos = []) {- const $summarizedVideosContainer = document.querySelector('details.summarized-videos-container')- const $videosContainer = $summarizedVideosContainer.querySelector('.videos-container')- videos.filter(v => v.summary).forEach(v => {- const $existing = $summarizedVideosContainer.querySelector(`[data-video-id="${v.id}"]`)- return $existing- ? $existing.replaceWith(createVideoElement(v))- : $videosContainer.appendChild(createVideoElement(v))- })-}