A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
ignore video
Christian Fei3a06dd167927
diff --git a/client/components/video-element.js b/client/components/video-element.jsindex eadce2a..d0b5921 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -25,6 +25,7 @@ class VideoElement extends HTMLElement {}render () {if (!this.video) return+ if (store.includes(store.ignoreVideoKey, this.video.id)) return this.remove()this.classList.add('video')this.dataset['videoId'] = this.video.idthis.innerHTML = /*html*/`@@ -37,6 +38,7 @@ class VideoElement extends HTMLElement {</p></video>`: /*html*/`<img loading="lazy" src="${this.video.thumbnail}"/>`}+ <span class="action ignore">ignore</span><div class="info"><span class="channel-name">${this.video.channelName}</span><br>@@ -62,6 +64,7 @@ class VideoElement extends HTMLElement {handleClick(this.querySelector('.action.download'), this.downloadVideoHandler.bind(this))handleClick(this.querySelector('.action.summarize'), this.summarizeVideoHandler.bind(this))handleClick(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))+ handleClick(this.querySelector('.action.ignore'), this.ignoreVideoHandler.bind(this))handleClick(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))function handleClick ($el, handler) {@@ -74,6 +77,7 @@ class VideoElement extends HTMLElement {handleClick(this.querySelector('.action.download'), this.downloadVideoHandler.bind(this))handleClick(this.querySelector('.action.summarize'), this.summarizeVideoHandler.bind(this))handleClick(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))+ handleClick(this.querySelector('.action.ignore'), this.ignoreVideoHandler.bind(this))handleClick(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))function handleClick ($el, handler) {@@ -122,6 +126,11 @@ class VideoElement extends HTMLElement {`}}+ ignoreVideoHandler (event) {+ event.preventDefault()+ store.push(store.ignoreVideoKey, this.video.id)+ this.render()+ }filterByChannelHandler (event) {// find search input, set value to channelnameconst $searchInput = document.querySelector('#search')diff --git a/client/lib/store.js b/client/lib/store.jsindex 5a45570..de66165 100644--- a/client/lib/store.js+++ b/client/lib/store.js@@ -1,10 +1,12 @@export default class Store {showThumbnailsKey = 'showThumbnails'lastVideosKey = 'lastVideos'+ ignoreVideoKeyKey = 'ignoreVideoKey'constructor() {if (!localStorage.getItem(this.showThumbnailsKey)) localStorage.setItem(this.showThumbnailsKey, 'true')if (!localStorage.getItem(this.lastVideosKey)) localStorage.setItem(this.lastVideosKey, '{}')+ if (!localStorage.getItem(this.ignoreVideoKey)) localStorage.setItem(this.ignoreVideoKey, '[]')}toggle (key) {@@ -12,7 +14,7 @@ export default class Store {localStorage.setItem(key, localStorage.getItem(key) === 'true' ? 'false' : 'true')}get(key) {- if (![this.showThumbnailsKey, this.lastVideosKey].includes(key)) return console.error('invalid key', key)+ if (![this.showThumbnailsKey, this.lastVideosKey, this.ignoreVideoKey].includes(key)) return console.error('invalid key', key)return JSON.parse(localStorage.getItem(key))}set(key, value) {@@ -22,11 +24,17 @@ export default class Store {localStorage.setItem(key, JSON.stringify(value))}}- // push(key, item) {- // if (![this.ignoreVideoKey].includes(key)) return console.error('invalid key', key)- // const list = this.get(key)- // list.push(item)- // this.set(key, list)- // return item- // }+ push(key, item) {+ if (![this.ignoreVideoKey].includes(key)) return console.error('invalid key', key)+ const list = this.get(key)+ list.push(item)+ this.set(key, list)+ return item+ }+ includes(key, item) {+ if (![this.ignoreVideoKey].includes(key)) return console.error('invalid key', key)+ const list = this.get(key)+ return list.includes(item)++ }}\ No newline at end of filediff --git a/client/main.css b/client/main.cssindex 6d9ade6..9b3edca 100644--- a/client/main.css+++ b/client/main.css@@ -72,6 +72,7 @@ form {margin: 0;}.video {+ position: relative;width: 280px;max-height: 300px;text-align: left;@@ -82,6 +83,15 @@ form {/* background-color: #f0f0f0; */margin: 5px;}+.video .action.ignore {+ position: absolute;+ top: 0;+ right: 0;+ z-index: 1000;+ background-color: #f0f0f0;+ color: black;+ padding: 0.25rem;+}.video .title {margin-top: 5px;margin-bottom: 5px;@@ -138,9 +148,6 @@ form {---#open-settings {display: block;border-radius: 4px;diff --git a/client/main.js b/client/main.jsindex 54eb53b..8407c79 100644--- a/client/main.js+++ b/client/main.js@@ -1,5 +1,6 @@import Store from '/lib/store.js'const store = new Store()+window.store = store// app: sse updates and rendersconst eventSource = new window.EventSource('/')@@ -26,6 +27,9 @@ eventSource.onmessage = (message) => {$videosContainer.innerHTML = ''const allVideos = Object.entries(data.videos).reduce((acc, curr) => acc.concat(curr[1]), [])allVideos+ .filter(video => {+ return !window.store.includes(window.store.ignoreVideoKey, video.id)+ }).sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt)).forEach(video => {$videosContainer.appendChild(createVideoElement(video))