A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
toggle ignore video
Christian Fei48e356286f6d
diff --git a/client/components/video-element.js b/client/components/video-element.jsindex 8d91b0e..3e9e76d 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -17,7 +17,6 @@ class VideoElement extends HTMLElement {connectedCallback () {this.video = JSON.parse(this.dataset['data'])this.render()- this.registerEvents()}disconnectedCallback () {this.unregisterEvents()@@ -29,13 +28,12 @@ class VideoElement extends HTMLElement {attributeChangedCallback(name, _, newValue) {if (name === 'data-data') {this.video = JSON.parse(this.dataset['data'])- this.unregisterEvents()this.render()- this.registerEvents()}}render () {if (!this.video) return+ this.unregisterEvents()this.classList.add('video')this.dataset['videoId'] = this.video.idthis.dataset['date'] = this.video.publishedAt@@ -43,6 +41,8 @@ class VideoElement extends HTMLElement {else this.dataset['summarized'] = "false"if (this.video.downloaded) this.dataset['downloaded'] = "true"else this.dataset['downloaded'] = "false"+ if (this.video.ignored) this.dataset['ignored'] = "true"+ else this.dataset['ignored'] = "false"this.innerHTML = /*html*/`${this.video.downloaded? /*html*/`<div class="play-video-placeholder" style="background-image: url(${this.video.thumbnail})"><div class="play-icon"></div></div>`@@ -68,22 +68,22 @@ class VideoElement extends HTMLElement {<a href="https://www.youtube.com/watch?v=${this.video.id}" target="_blank">📺 external</a></div>`+ this.registerEvents()}registerEvents () {handleClickAddListener(this.querySelector('.action.download'), this.downloadVideoHandler.bind(this))handleClickAddListener(this.querySelector('.action.summarize'), this.summarizeVideoHandler.bind(this))handleClickAddListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))- handleClickAddListener(this.querySelector('.action.ignore'), this.ignoreVideoHandler.bind(this))+ handleClickAddListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))handleClickAddListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))handleClickAddListener(this.querySelector('.play-video-placeholder'), this.watchVideoHandler.bind(this))- // handleDoubleClick(this.querySelector('img'), this.ignoreVideoHandler.bind(this))this.querySelector('video') && this.registerVideoEvents(this.querySelector('video'))}unregisterEvents () {handleClickRemoveListener(this.querySelector('.action.download'), this.downloadVideoHandler.bind(this))handleClickRemoveListener(this.querySelector('.action.summarize'), this.summarizeVideoHandler.bind(this))handleClickRemoveListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))- handleClickRemoveListener(this.querySelector('.action.ignore'), this.ignoreVideoHandler.bind(this))+ handleClickRemoveListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))handleClickRemoveListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))this.querySelector('video') && this.unregisterVideoEvents(this.querySelector('video'))}@@ -139,7 +139,7 @@ class VideoElement extends HTMLElement {`}}- ignoreVideoHandler (event) {+ toggleIgnoreVideoHandler (event) {event.preventDefault()fetch('/ignore-video', {@@ -147,7 +147,12 @@ class VideoElement extends HTMLElement {headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ id: this.video.id }),})- .then(() => this.remove())+ .then(res => res.json())+ .then((ignored) => {+ console.log({ignored})+ this.video.ignored = ignored+ this.render()+ }).catch((error) => {console.error('Error ignoring summary:', error)this.render()diff --git a/client/index.html b/client/index.htmlindex c6981f3..ad38175 100644--- a/client/index.html+++ b/client/index.html@@ -19,6 +19,7 @@<div class="flex space-around"><button id="show-downloaded-videos">Downloaded videos</button><button id="show-summarized-videos">Summarized videos</button>+ <button id="show-ignored-videos">Ignored videos</button></div><div class="main-videos-container"></div><details class="download-log">diff --git a/client/main.css b/client/main.cssindex 38f1920..55604e9 100644--- a/client/main.css+++ b/client/main.css@@ -244,9 +244,6 @@ details {justify-content: space-around;margin-top: 0.3em;}-#show-summarized-videos.active, #show-downloaded-videos.active {- background-color: #e2ffd8;-}.play-video-placeholder {height: 157px;@@ -276,9 +273,23 @@ details {border-bottom: 20px solid transparent;border-left: 30px solid rgb(255, 255, 255);}++[data-ignored="true"] {+ display: none;+}++#show-summarized-videos.active, #show-downloaded-videos.active, #show-ignored-videos.active {+ background-color: #e2ffd8;+}.show-downloaded-videos [data-downloaded="false"] {display: none;}.show-summarized-videos [data-summarized="false"] {display: none;+}+.show-ignored-videos [data-ignored="false"] {+ display: none;+}+.show-ignored-videos [data-ignored="true"] {+ display: block;}\ No newline at end of filediff --git a/client/main.js b/client/main.jsindex 6f9c799..7cd4749 100644--- a/client/main.js+++ b/client/main.js@@ -128,6 +128,11 @@ handleClick($showSummarizedVideos, (event) => {event.target.classList.toggle('active')document.body.classList.toggle('show-summarized-videos')})+const $showIgnoredVideos = document.getElementById('show-ignored-videos')+handleClick($showIgnoredVideos, (event) => {+ event.target.classList.toggle('active')+ document.body.classList.toggle('show-ignored-videos')+})// apply settingsapplyShowThumbnails(store.get(store.showThumbnailsKey))diff --git a/lib/repository.js b/lib/repository.jsindex deca5d6..694ceb9 100644--- a/lib/repository.js+++ b/lib/repository.js@@ -33,7 +33,7 @@ export default class Repository {}getVideos () {return this.videos- .filter(v => !v.ignored)+ // .filter(v => !v.ignored).sort((a, b) => +new Date(b.publishedAt) - +new Date(a.publishedAt)).filter((_, i) => i < 100)}@@ -57,12 +57,14 @@ export default class Repository {saveVideos() {fs.writeFileSync(this.paths.videos, JSON.stringify(this.videos, null, 2))}- ignoreVideo(id) {+ toggleIgnoreVideo(id) {const index = this.videos.findIndex(v => v.id === id)+ let ignored = falseif (index !== -1) {- this.videos[index].ignored = true+ ignored = this.videos[index].ignored = !this.videos[index].ignored}this.saveVideos()+ return ignored}setVideoTranscript(id, transcript = '') {this.videos = this.videos.map(v => {diff --git a/lib/server.js b/lib/server.jsindex d33c37f..e4f1b07 100644--- a/lib/server.js+++ b/lib/server.js@@ -216,9 +216,8 @@ export function createServer ({repo, connections = []}) {async function ignoreVideoHandler(req, res) {const body = await getBody(req)let { id } = JSON.parse(body)- repo.ignoreVideo(id)- res.writeHead(200)- return res.end()+ res.writeHead(200, { 'Content-Type': 'application/json' })+ return res.end(JSON.stringify(repo.toggleIgnoreVideo(id)))}}