A clean and minimal youtube frontend, without all the ads and whistles
JavaScript
chore: cleanup client
Christian Fei88cc681c1a8c
diff --git a/client/components/add-channel-form.js b/client/components/add-channel-form.jsindex 6c5d3cc..ac6fba9 100644--- a/client/components/add-channel-form.js+++ b/client/components/add-channel-form.js@@ -1,8 +1,5 @@+/* global HTMLElement, customElements, alert */class AddChannelForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()}diff --git a/client/components/channels-list.js b/client/components/channels-list.jsindex 9f1addd..c00b764 100644--- a/client/components/channels-list.js+++ b/client/components/channels-list.js@@ -1,3 +1,4 @@+/* global HTMLElement, customElements */import { addClickListener, removeClickListener } from '../../../../../../lib/utils.js'class ChannelsList extends HTMLElement {constructor () {diff --git a/client/components/empty-state.js b/client/components/empty-state.jsindex a87cad2..e643799 100644--- a/client/components/empty-state.js+++ b/client/components/empty-state.js@@ -1,8 +1,5 @@+/* global HTMLElement, customElements */class EmptyState extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.classList.add('flex')this.classList.add('space-between')diff --git a/client/components/excluded-terms-form.js b/client/components/excluded-terms-form.jsindex e91bce8..3676665 100644--- a/client/components/excluded-terms-form.js+++ b/client/components/excluded-terms-form.js@@ -1,8 +1,5 @@+/* global HTMLElement, customElements, confirm */class ExcludedTermsForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()this.registerEvents()diff --git a/client/components/manage-channels-form.js b/client/components/manage-channels-form.jsindex ef294eb..d330f2e 100644--- a/client/components/manage-channels-form.js+++ b/client/components/manage-channels-form.js@@ -1,9 +1,6 @@+/* global HTMLElement, customElements, alert, confirm */import { addClickListener, removeClickListener } from '../../../../../../lib/utils.js'class ManageChannelsForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()this.fetchData()@@ -64,7 +61,7 @@ class ManageChannelsForm extends HTMLElement {}).catch(error => {console.error('Error deleting channel:', error)- status.innerText = `There was an error deleting the channel ${channelName}, please check your application logs`+ // status.innerText = `There was an error deleting the channel ${channelName}, please check your application logs`})}}diff --git a/client/components/manage-disk-space-form.js b/client/components/manage-disk-space-form.jsindex 6cc671b..70c126d 100644--- a/client/components/manage-disk-space-form.js+++ b/client/components/manage-disk-space-form.js@@ -1,8 +1,5 @@+/* global HTMLElement, customElements, confirm */class ManageDiskSpaceForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()this.registerEvents()diff --git a/client/components/search-videos.js b/client/components/search-videos.jsindex 318a46d..6cfd257 100644--- a/client/components/search-videos.js+++ b/client/components/search-videos.js@@ -1,3 +1,4 @@+/* global HTMLElement, customElements */import { createVideoElement, addToast } from '../../../../../../lib/utils.js'import Store from '../../../../../../lib/store.js'const store = new Store()diff --git a/client/components/transcode-videos-form.js b/client/components/transcode-videos-form.jsindex a696c62..36846e9 100644--- a/client/components/transcode-videos-form.js+++ b/client/components/transcode-videos-form.js@@ -1,8 +1,5 @@+/* global HTMLElement, customElements */class TranscodeVideosForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()this.registerEvents()diff --git a/client/components/video-element.js b/client/components/video-element.jsindex 0908065..084dfc9 100644--- a/client/components/video-element.js+++ b/client/components/video-element.js@@ -1,3 +1,4 @@+/* global HTMLElement, customElements, confirm */import { addClickListener, removeClickListener, addToast } from '../../../../../../lib/utils.js'import Store from '../../../../../../lib/store.js'const store = new Store()@@ -123,9 +124,9 @@ class VideoElement extends HTMLElement {this.querySelector('.play.video-placeholder').outerHTML = /* html */`<video controls playsinline style="user-select: none; width: 400px; width: -webkit-fill-available;"><source src="/api/videos/${this.video.id}.${this.video.format || 'mp4'}" type="video/${this.video.format || 'mp4'}" />- ${store.get(store.showCaptionsKey) ? /* html */`- <track default kind="captions" srclang="en" src="/api/captions/${this.video.id}" />- ` : ''}+ ${store.get(store.showCaptionsKey)+ ? /* html */`<track default kind="captions" srclang="en" src="/api/captions/${this.video.id}" />`+ : ''}<p>Your browser does not support the video tag.Download the video instead <a href="/api/videos/${this.video.id}" target="_blank">here</a>@@ -256,7 +257,7 @@ class VideoElement extends HTMLElement {scrollIntoViewWithOffset (offset, behavior = 'smooth') {const top = this.getBoundingClientRect().top - offset - document.body.getBoundingClientRect().top- scrollTo({ top, behavior })+ window.scrollTo({ top, behavior })}}diff --git a/client/components/video-quality-form.js b/client/components/video-quality-form.jsindex 761f5f8..72f5da7 100644--- a/client/components/video-quality-form.js+++ b/client/components/video-quality-form.js@@ -1,15 +1,14 @@+/* global HTMLElement, customElements */class VideoQualityForm extends HTMLElement {- constructor () {- super()- }-connectedCallback () {this.render()this.registerEvents()fetch('/api/video-quality').then(response => response.json())- .then((videoQuality) => this.querySelector('#video-quality').value = +videoQuality)+ .then((videoQuality) => {+ this.querySelector('#video-quality').value = +videoQuality+ }).catch(error => console.error('Error:', error))}diff --git a/client/lib/router.js b/client/lib/router.jsindex 441c913..2450b27 100644--- a/client/lib/router.js+++ b/client/lib/router.js@@ -1,3 +1,4 @@+/* global MutationObserver, history, PopStateEvent, location, dispatchEvent */import { createVideoElement, applyShowBigPlayer, applyShowThumbnails } from '../../../../../../lib/utils.js'import Store from '../../../../../../lib/store.js'const store = new Store()@@ -29,9 +30,7 @@ const routes = {handleEmptyState()new MutationObserver((mutationList, observer) => {- for (const mutation of mutationList) {- handleEmptyState()- }+ handleEmptyState()}).observe($videosContainer, { attributes: false, childList: true, subtree: true })applyShowThumbnails(store.get(store.showThumbnailsKey))@@ -94,7 +93,7 @@ const routes = {}handleRoute()-addEventListener('popstate', handleRoute)+window.addEventListener('popstate', handleRoute)document.querySelectorAll('[href="/"],[href="/settings"]').forEach(($el) => {$el.addEventListener('click', (event) => {event.preventDefault()diff --git a/client/lib/store.js b/client/lib/store.jsindex e6243a3..2bd32fe 100644--- a/client/lib/store.js+++ b/client/lib/store.js@@ -1,3 +1,4 @@+/* global localStorage */export default class Store {showThumbnailsKey = 'showThumbnails'showBigPlayerKey = 'showBigPlayer'diff --git a/client/main.js b/client/main.jsindex 2ddb29c..bbd0cd3 100644--- a/client/main.js+++ b/client/main.js@@ -1,3 +1,4 @@+/* global EventSource, MutationObserver */import Store from '../../../../../lib/store.js'import { createVideoElement } from '../../../../../lib/utils.js'const store = new Store()@@ -14,7 +15,7 @@ eventSource.onmessage = (message) => {console.log('[sse] message', data)if (data.type === 'state' && data.state) {- Object.assign(state, data.state)+ Object.assign(window.state, data.state)const $state = document.querySelector('.state')if (!$state) { return console.warn('missing $state') }const $count = $state.querySelector('.count')@@ -26,11 +27,11 @@ eventSource.onmessage = (message) => {$summarizing.innerText = `Summarizing: ${summarizingCount}`setTimeout(() => {- Object.keys(data.state.downloading || {}).map((videoId) => {+ Object.keys(data.state.downloading || {}).forEach((videoId) => {const $video = document.querySelector(`video-element[data-video-id="${videoId}"]`)if ($video) $video.dataset.downloading = 'true'})- Object.keys(data.state.summarizing || {}).map((videoId) => {+ Object.keys(data.state.summarizing || {}).forEach((videoId) => {const $video = document.querySelector(`video-element[data-video-id="${videoId}"]`)if ($video) $video.dataset.summarizing = 'true'})diff --git a/test/search.test.js b/test/search.test.jsindex e9920c2..9a0f9fe 100644--- a/test/search.test.js+++ b/test/search.test.js@@ -1,4 +1,4 @@-import { test, describe } from 'node:test'+import { test } from 'node:test'import fs from 'fs'import assert from 'assert'import { searchVideosHandler } from '../lib/router/api.js'