Skip to content

armgit / my-yt

Public Imported from GitHub
0

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

JavaScript

feat: handle toggle show-thumbnails

Christian Feiddeae8e02fd8
diff --git a/client/components/add-channel-form.js b/client/components/add-channel-form.js
index 56128c0..9008053 100644
--- a/client/components/add-channel-form.js
+++ b/client/components/add-channel-form.js
@@ -17,7 +17,7 @@ class AddChannelForm extends HTMLElement {
}
render () {
this.innerHTML = /*html*/`
- <form id="add-channel-form" class="p-1 border-light">
+ <form id="add-channel-form">
<div class="flex space-between">
<label for="channel-name">Add a new channel</label>
<input type="text" id="channel-name" placeholder="Channel Name" required>
diff --git a/client/index.html b/client/index.html
index 3368ad1..9705597 100644
--- a/client/index.html
+++ b/client/index.html
@@ -46,16 +46,14 @@
<br>
<add-channel-form></add-channel-form>
<br>
- <!--
<form>
<label for="show-thumbnails">
Show video thumbnails
</label>
<input type="checkbox" id="show-thumbnails"/>
</form>
- <br>
- -->
<!--
+ <br>
<div>
<input type="text" id="add-ignored-term"/>
<ul id="ignored-terms"></ul>
diff --git a/client/main.js b/client/main.js
index b2671ff..cef3a7a 100644
--- a/client/main.js
+++ b/client/main.js
@@ -56,9 +56,21 @@ const routes = {
return acc
}, []).join(',')
document.querySelector('channels-list').dataset['list'] = channelsList
+
+ applyShowThumbnails(store.get(store.showThumbnailsKey))
+
} },
'/settings': { template: document.getElementById('settings-template'), title: 'My YT - Settings', async initialize () {
console.log('initalize /settings')
+
+
+ const $showThumbnails = document.getElementById('show-thumbnails')
+ store.get(store.showThumbnailsKey) ? $showThumbnails.setAttribute('checked', 'true') : $showThumbnails.removeAttribute('checked')
+
+ $showThumbnails.addEventListener('click', (event) => {
+ store.toggle(store.showThumbnailsKey)
+ applyShowThumbnails(store.get(store.showThumbnailsKey))
+ })
} },
'/404': { template: document.getElementById('not-found-template'), title: 'Not Found' }
}
@@ -176,12 +188,6 @@ function createVideoElement (video) {
}
// settings ui
-// const $showThumbnails = document.getElementById('show-thumbnails')
-// $showThumbnails.addEventListener('click', (event) => {
-// event.preventDefault()
-// store.toggle(store.showThumbnailsKey)
-// applyShowThumbnails(store.get(store.showThumbnailsKey))
-// })
// const $addIgnoredTerm = document.getElementById('add-ignored-term')
// $addIgnoredTerm.addEventListener('keyup', (event) => {
// event.preventDefault()
@@ -204,16 +210,15 @@ function createVideoElement (video) {
// }
-// applyShowThumbnails(store.get(store.showThumbnailsKey))
// applyIgnoredTerms(store.get(store.ignoreTermsKey))
-// function applyShowThumbnails(showThumbnails) {
-// if (showThumbnails) {
-// document.body.classList.remove('hide-thumbnails')
-// } else {
-// document.body.classList.add('hide-thumbnails')
-// }
-// const $showThumbnailsCheckbox = document.getElementById('show-thumbnails')
-// if ($showThumbnailsCheckbox) $showThumbnailsCheckbox.checked = showThumbnails
-// }
\ No newline at end of file
+function applyShowThumbnails(showThumbnails) {
+ if (showThumbnails) {
+ document.body.classList.remove('hide-thumbnails')
+ } else {
+ document.body.classList.add('hide-thumbnails')
+ }
+ const $showThumbnailsCheckbox = document.getElementById('show-thumbnails')
+ if ($showThumbnailsCheckbox) $showThumbnailsCheckbox.checked = showThumbnails
+}
\ No newline at end of file