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: shos toast when downloading/summarizing video

Christian Fei7267c1cde104
diff --git a/client/components/search-videos.js b/client/components/search-videos.js
index 80536d0..65ef14b 100644
--- a/client/components/search-videos.js
+++ b/client/components/search-videos.js
@@ -1,4 +1,4 @@
-import { createVideoElement } from "/lib/utils.js"
+import { createVideoElement, addToast } from "/lib/utils.js"
import Store from '/lib/store.js'
const store = new Store()
@@ -45,6 +45,7 @@ class SearchVideos extends HTMLElement {
$status.innerText = ''
if (searchTerm.match('https?://')) {
+ addToast('Downloading video...')
fetch('/api/download-video', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
diff --git a/client/components/video-element.js b/client/components/video-element.js
index 35fcb13..60ad4e2 100644
--- a/client/components/video-element.js
+++ b/client/components/video-element.js
@@ -1,5 +1,6 @@
import { addClickListener, removeClickListener } from "/lib/utils.js"
import Store from "/lib/store.js"
+import { addToast } from "/lib/utils.js"
const store = new Store()
class VideoElement extends HTMLElement {
@@ -139,6 +140,8 @@ class VideoElement extends HTMLElement {
let $downloadButton = event.target.classList.contains('.action') ? event.target : this.querySelector('.action.download')
$downloadButton.innerText = this.downloadStartedText
+ addToast('Downloading video...')
+
fetch('/api/download-video', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -171,6 +174,8 @@ class VideoElement extends HTMLElement {
event.target.innerText = this.summaryStartedText
+ addToast('Summarizing video...')
+
fetch('/api/summarize-video', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -195,7 +200,6 @@ class VideoElement extends HTMLElement {
toggleIgnoreVideoHandler (event) {
event.preventDefault()
-
fetch('/api/ignore-video', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
diff --git a/client/index.html b/client/index.html
index efae84a..928f6ed 100644
--- a/client/index.html
+++ b/client/index.html
@@ -21,6 +21,8 @@
</header>
<main></main>
+
+ <aside id="notifications-container"></aside>
<details class="state">
<summary>state & logs <span class="count"></span></summary>
diff --git a/client/lib/utils.js b/client/lib/utils.js
index 4fcce36..a9555da 100644
--- a/client/lib/utils.js
+++ b/client/lib/utils.js
@@ -7,6 +7,19 @@ export function createVideoElement (video, showOriginalThumbnail = false) {
return $video
}
+export function addToast (text) {
+ const $notificationsContainer = document.getElementById('notifications-container')
+ if ($notificationsContainer) {
+ const $toast = document.createElement('div')
+ $toast.classList.add('toast')
+ $toast.textContent = text
+ $notificationsContainer.appendChild($toast)
+ setTimeout(() => {
+ $toast.remove()
+ }, 5000)
+ }
+}
+
export function applyShowThumbnails(showThumbnails) {
if (showThumbnails) {
document.body.classList.remove('hide-thumbnails')
diff --git a/client/main.css b/client/main.css
index 691d9ef..298d0bb 100644
--- a/client/main.css
+++ b/client/main.css
@@ -500,6 +500,20 @@ summary:hover {
color: var(--text-hover);
}
+#notifications-container {
+ position: fixed;
+ bottom: 4em;
+ right: 1em;
+}
+#notifications-container > * {
+ padding: 10px 20px;
+ margin: 0 0 10px;
+ border-radius: 5px;
+ background: rgba(0,0,0,0.95);
+ color: #fff;
+ z-index: 999;
+}
+
#filters-container button {
display: flex;
align-items: center;