Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

refactor: remove unwatched filter and watched video toggle features

Christian Feifeae50554d6f
diff --git a/client/components/search-videos.js b/client/components/search-videos.js
index 9bb4271..78365ae 100644
--- a/client/components/search-videos.js
+++ b/client/components/search-videos.js
@@ -20,7 +20,6 @@ class SearchVideos extends HTMLElement {
const ignored = searchParams.get('ignored') || ''
const downloaded = searchParams.get('downloaded') || ''
const summarized = searchParams.get('summarized') || ''
- const unwatched = searchParams.get('unwatched') || ''
const bookmarked = searchParams.get('bookmarked') || ''
const searchTerm = searchParams.get('filter') || ''
this.querySelector('#search').value = searchTerm
@@ -28,7 +27,7 @@ class SearchVideos extends HTMLElement {
this.querySelector('#ignored').checked = ignored === 'true'
this.querySelector('#downloaded').checked = downloaded === 'true'
this.querySelector('#summarized').checked = summarized === 'true'
- this.querySelector('#unwatched').checked = unwatched === 'true'
+
this.querySelector('#bookmarked').checked = bookmarked === 'true'
}
@@ -42,7 +41,7 @@ class SearchVideos extends HTMLElement {
this.querySelector('#ignored').addEventListener('change', this.searchHandler.bind(this))
this.querySelector('#downloaded').addEventListener('change', this.searchHandler.bind(this))
this.querySelector('#summarized').addEventListener('change', this.searchHandler.bind(this))
- this.querySelector('#unwatched').addEventListener('change', this.searchHandler.bind(this))
+
this.querySelector('#bookmarked').addEventListener('change', this.searchHandler.bind(this))
}
@@ -52,7 +51,7 @@ class SearchVideos extends HTMLElement {
this.querySelector('#ignored').removeEventListener('change', this.searchHandler.bind(this))
this.querySelector('#downloaded').removeEventListener('change', this.searchHandler.bind(this))
this.querySelector('#summarized').removeEventListener('change', this.searchHandler.bind(this))
- this.querySelector('#unwatched').removeEventListener('change', this.searchHandler.bind(this))
+
this.querySelector('#bookmarked').removeEventListener('change', this.searchHandler.bind(this))
}
@@ -79,10 +78,6 @@ class SearchVideos extends HTMLElement {
<input type="checkbox" id="excluded"/>
<label for="excluded">excluded</label>
</div>
- <div class="flex-1">
- <input type="checkbox" id="unwatched"/>
- <label for="unwatched">unwatched</label>
- </div>
<div class="flex-1">
<input type="checkbox" id="bookmarked"/>
<label for="bookmarked">πŸ”– bookmarked</label>
@@ -121,7 +116,6 @@ class SearchVideos extends HTMLElement {
const ignored = this.querySelector('#ignored').checked
const downloaded = this.querySelector('#downloaded').checked
const summarized = this.querySelector('#summarized').checked
- const unwatched = this.querySelector('#unwatched').checked
const bookmarked = this.querySelector('#bookmarked').checked
if (excluded) {
@@ -135,7 +129,7 @@ class SearchVideos extends HTMLElement {
this.querySelector('#excluded').disabled = false
}
- const query = `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}${unwatched ? '&unwatched=true' : ''}${bookmarked ? '&bookmarked=true' : ''}`
+ const query = `?filter=${encodeURIComponent(searchTerm)}${excluded ? '&excluded=true' : ''}${downloaded ? '&downloaded=true' : ''}${ignored ? '&ignored=true' : ''}${summarized ? '&summarized=true' : ''}${bookmarked ? '&bookmarked=true' : ''}`
window.history.pushState({}, '', query)
fetch(ENDPOINTS.VIDEOS + query)
diff --git a/client/components/video-element.js b/client/components/video-element.js
index 372a794..dd86090 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -96,7 +96,6 @@ class VideoElement extends HTMLElement {
? /* html */`<span tabindex="0" class="action summarize" data-video-id="${this.video.id}">πŸ“– Summarize</span>`
: /* html */`<span tabindex="0" class="action show-summary" data-video-id="${this.video.id}">πŸ“– Summary</span>`}
<a href="https://www.youtube.com/watch?v=${this.video.id}" class="action open-externally" target="_blank">πŸ“Ί external</a>
- <span tabindex="0" class="action watched" data-video-id="${this.video.id}">${store.isWatched(this.video.id) ? 'βœ… Watched' : '❌ Unwatched'}</span>
<span tabindex="0" class="action bookmark" data-video-id="${this.video.id}">πŸ”– Bookmark</span>
</div>
`
@@ -162,7 +161,6 @@ class VideoElement extends HTMLElement {
addClickListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))
addClickListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))
addClickListener(this.querySelector('.action.open-externally'), this.openExternallyHandler.bind(this))
- addClickListener(this.querySelector('.action.watched'), this.toggleWatchedVideoHandler.bind(this))
addClickListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))
addClickListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))
addClickListener(this.querySelector('.action.bookmark'), this.toggleBookmarkDialog.bind(this))
@@ -185,7 +183,6 @@ class VideoElement extends HTMLElement {
removeClickListener(this.querySelector('.action.show-summary'), this.showSummaryHandler.bind(this))
removeClickListener(this.querySelector('.action.ignore'), this.toggleIgnoreVideoHandler.bind(this))
removeClickListener(this.querySelector('.action.open-externally'), this.openExternallyHandler.bind(this))
- removeClickListener(this.querySelector('.action.watched'), this.toggleWatchedVideoHandler.bind(this))
removeClickListener(this.querySelector('.channel-name'), this.filterByChannelHandler.bind(this))
removeClickListener(this.querySelector('.play.video-placeholder'), this.watchVideoHandler.bind(this))
removeClickListener(this.querySelector('.action.bookmark'), this.toggleBookmarkDialog.bind(this))
@@ -313,21 +310,6 @@ class VideoElement extends HTMLElement {
this.querySelector('video') && this.querySelector('video').pause()
}
- toggleWatchedVideoHandler (event) {
- event.preventDefault()
-
- fetch(ENDPOINTS.WATCHED_VIDEO, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify({ id: this.video.id })
- })
- .then(() => {
- store.toggleWatched(this.video.id)
- this.render()
- })
- .catch((error) => console.error('Error toggling watched status:', error))
- }
-
filterByChannelHandler (event) {
const $searchInput = document.querySelector('#search')
if (!$searchInput) return
diff --git a/client/lib/api.js b/client/lib/api.js
index a227bca..629f19b 100644
--- a/client/lib/api.js
+++ b/client/lib/api.js
@@ -13,7 +13,6 @@ export const ENDPOINTS = {
RECLAIM_DISK_SPACE: '/api/reclaim-disk-space',
TRANSCODE_VIDEOS: '/api/transcode-videos',
EXCLUDED_TERMS: '/api/excluded-terms',
- WATCHED_VIDEO: '/api/watched-video',
BOOKMARKS: '/api/bookmarks',
GET_BOOKMARKS: '/api/bookmarks/:id',
DELETE_BOOKMARK: '/api/delete-bookmark'
diff --git a/client/lib/store.js b/client/lib/store.js
index 3541f6e..2bd32fe 100644
--- a/client/lib/store.js
+++ b/client/lib/store.js
@@ -7,7 +7,6 @@ export default class Store {
useTLDWTubeKey = 'useTLDWTube'
lastVideosKey = 'lastVideos'
ignoreTermsKey = 'ignoreTerms'
- watchedVideosKey = 'watchedVideos'
constructor () {
if (!localStorage.getItem(this.showThumbnailsKey)) localStorage.setItem(this.showThumbnailsKey, 'true')
@@ -17,7 +16,6 @@ export default class Store {
if (!localStorage.getItem(this.useTLDWTubeKey)) localStorage.setItem(this.useTLDWTubeKey, 'false')
if (!localStorage.getItem(this.lastVideosKey)) localStorage.setItem(this.lastVideosKey, '{}')
if (!localStorage.getItem(this.ignoreTermsKey)) localStorage.setItem(this.ignoreTermsKey, '[]')
- if (!localStorage.getItem(this.watchedVideosKey)) localStorage.setItem(this.watchedVideosKey, '[]')
}
toggle (key) {
@@ -26,7 +24,7 @@ export default class Store {
}
get (key) {
- if (![this.showThumbnailsKey, this.showBigPlayerKey, this.showOriginalThumbnailKey, this.showCaptionsKey, this.useTLDWTubeKey, this.lastVideosKey, this.ignoreTermsKey, this.watchedVideosKey].includes(key)) return console.error('invalid key', key)
+ if (![this.showThumbnailsKey, this.showBigPlayerKey, this.showOriginalThumbnailKey, this.showCaptionsKey, this.useTLDWTubeKey, this.lastVideosKey, this.ignoreTermsKey].includes(key)) return console.error('invalid key', key)
return JSON.parse(localStorage.getItem(key))
}
@@ -39,7 +37,7 @@ export default class Store {
}
push (key, item) {
- if (![this.ignoreTermsKey, this.watchedVideosKey].includes(key)) return console.error('invalid key', key)
+ if (![this.ignoreTermsKey].includes(key)) return console.error('invalid key', key)
const list = this.get(key)
list.push(item)
this.set(key, list)
@@ -47,7 +45,7 @@ export default class Store {
}
remove (key, item) {
- if (![this.ignoreTermsKey, this.watchedVideosKey].includes(key)) return console.error('invalid key', key)
+ if (![this.ignoreTermsKey].includes(key)) return console.error('invalid key', key)
let list = this.get(key)
list = list.filter(i => i !== item)
this.set(key, list)
@@ -55,20 +53,8 @@ export default class Store {
}
includes (key, item) {
- if (![this.ignoreTermsKey, this.watchedVideosKey].includes(key)) return console.error('invalid key', key)
+ if (![this.ignoreTermsKey].includes(key)) return console.error('invalid key', key)
const list = this.get(key)
return list.includes(item)
}
-
- isWatched (videoId) {
- return this.get(this.watchedVideosKey).includes(videoId)
- }
-
- toggleWatched (videoId) {
- if (this.isWatched(videoId)) {
- this.remove(this.watchedVideosKey, videoId)
- } else {
- this.push(this.watchedVideosKey, videoId)
- }
- }
}
diff --git a/client/main.js b/client/main.js
index e406ae4..b5795d0 100644
--- a/client/main.js
+++ b/client/main.js
@@ -1,7 +1,4 @@
/* global EventSource, MutationObserver */
-import Store from './lib/store.js'
-
-const store = new Store()
window.state = {
downloading: {},
@@ -115,14 +112,6 @@ window.eventSource.onmessage = (message) => {
})
return
}
- if (data.type === 'watched' && data.videoId) {
- store.toggleWatched(data.videoId)
- ;[...document.querySelectorAll(`[data-video-id="${data.videoId}"]`)].forEach($video => {
- if (!$video.dataset.data) return
- $video.render()
- })
- return
- }
if (data.type === 'bookmark-added' && data.videoId) {
;[...document.querySelectorAll(`[data-video-id="${data.videoId}"]`)].forEach($video => {
if (!$video.dataset.data) return
diff --git a/lib/repository.js b/lib/repository.js
index e9c2e94..7b39aac 100644
--- a/lib/repository.js
+++ b/lib/repository.js
@@ -22,8 +22,7 @@ export default class Repository {
fs.writeFileSync(this.paths.settings, JSON.stringify({
videoQuality: 720,
transcodeVideos: true,
- excludedTerms: [],
- watchedVideos: []
+ excludedTerms: []
}, null, 2))
}
@@ -39,11 +38,6 @@ export default class Repository {
this.settings.excludedTerms = []
this.saveSettings()
}
- if (this.settings.watchedVideos === undefined) {
- this.settings.watchedVideos = []
- this.saveSettings()
- }
-
fs.readdirSync(`${this.basePath}/videos`).forEach(file => {
const format = file.substring(file.lastIndexOf('.') + 1)
if (!['mp4', 'webm'].includes(format)) return
@@ -125,10 +119,7 @@ export default class Repository {
videos = videos.filter(v => v.bookmarks && v.bookmarks.length > 0)
}
- const watchedVideos = this.getWatchedVideos()
- if (query.unwatched === 'true') {
- videos = videos.filter(v => !watchedVideos.includes(v.id))
- } else if (filterKeys.length === 0) {
+ if (filterKeys.length === 0) {
videos = videos.filter(v => !v.ignored)
}
@@ -270,25 +261,6 @@ export default class Repository {
}
}
- getWatchedVideos () {
- return (this.settings.watchedVideos || [])
- }
-
- isWatched (videoId) {
- return this.getWatchedVideos().includes(videoId)
- }
-
- toggleWatched (videoId) {
- const watched = this.getWatchedVideos()
- if (watched.includes(videoId)) {
- watched.splice(watched.indexOf(videoId), 1)
- } else {
- watched.push(videoId)
- }
- this.settings.watchedVideos = watched
- this.saveSettings()
- }
-
getVideoBookmarks (videoId) {
const video = this.getVideo(videoId)
return (video && video.bookmarks) || []
diff --git a/server/router/handlers/settings.js b/server/router/handlers/settings.js
index f1a806c..a1304c9 100644
--- a/server/router/handlers/settings.js
+++ b/server/router/handlers/settings.js
@@ -1,4 +1,4 @@
-import { parseBody, broadcastMessage } from '../_helpers.js'
+import { parseBody } from '../_helpers.js'
import { getRepository } from '../../service-container.js'
export function getVideoQualityHandler (req, res, connections = [], state = {}) {
@@ -68,19 +68,4 @@ export async function removeExcludedTermHandler (req, res) {
res.end()
}
-export async function toggleWatchedVideoHandler (req, res, connections = [], state = {}) {
- const repo = getRepository()
- const parsed = await parseBody(req, res)
- if (parsed === null) return
- const videoId = parsed.id
- repo.toggleWatched(videoId)
-
- // Broadcast SSE to update all connected clients
- const updated = repo.isWatched(videoId)
- broadcastMessage('watched', { videoId, watched: updated }, connections)
-
- res.writeHead(200)
- res.end()
-}
-
-export default { getVideoQualityHandler, setVideoQualityHandler, getTranscodeVideosHandler, setTranscodeVideosHandler, getExcludedTermsHandler, addExcludedTermHandler, removeExcludedTermHandler, toggleWatchedVideoHandler }
+export default { getVideoQualityHandler, setVideoQualityHandler, getTranscodeVideosHandler, setTranscodeVideosHandler, getExcludedTermsHandler, addExcludedTermHandler, removeExcludedTermHandler }
diff --git a/server/router/index.js b/server/router/index.js
index 66562a9..335ae50 100644
--- a/server/router/index.js
+++ b/server/router/index.js
@@ -47,9 +47,6 @@ const routeMap = {
'POST /api/excluded-terms': settings.addExcludedTermHandler,
'DELETE /api/excluded-terms': settings.removeExcludedTermHandler,
- // Watched videos: POST
- 'POST /api/watched-video': settings.toggleWatchedVideoHandler,
-
// Scraper health: GET
'GET /api/scraper-status': scraperStatusHandler,