@@ -52,8 +52,8 @@ class VideoElement extends HTMLElement {
52
52
else this . dataset [ 'ignored' ] = "false"
53
53
this . innerHTML = /*html*/ `
54
54
${ this . video . downloaded
55
- ? /*html*/ `<div class="play- video-placeholder" style="background-image: url(${ this . video . thumbnail } )"><div class="play-icon"></div></div>`
56
- : /*html*/ `<img loading="lazy" src=" ${ this . video . thumbnail } "/ >` }
55
+ ? /*html*/ `<div class="play video-placeholder" style="background-image: url(${ this . video . thumbnail } )"><div class="play-icon"></div></div>`
56
+ : /*html*/ `<div class="download video-placeholder" style="background-image: url( ${ this . video . thumbnail } )"><div class="download-icon"></div></div >` }
57
57
<span class="action ignore" tabindex="0">ignore</span>
58
58
<div class="info">
59
59
<span class="channel-name">${ this . video . channelName } </span>
@@ -84,7 +84,8 @@ class VideoElement extends HTMLElement {
84
84
handleClickAddListener ( this . querySelector ( '.action.show-summary' ) , this . showSummaryHandler . bind ( this ) )
85
85
handleClickAddListener ( this . querySelector ( '.action.ignore' ) , this . toggleIgnoreVideoHandler . bind ( this ) )
86
86
handleClickAddListener ( this . querySelector ( '.channel-name' ) , this . filterByChannelHandler . bind ( this ) )
87
- handleClickAddListener ( this . querySelector ( '.play-video-placeholder' ) , this . watchVideoHandler . bind ( this ) )
87
+ handleClickAddListener ( this . querySelector ( '.play.video-placeholder' ) , this . watchVideoHandler . bind ( this ) )
88
+ handleClickAddListener ( this . querySelector ( '.download.video-placeholder' ) , this . downloadVideoHandler . bind ( this ) )
88
89
}
89
90
unregisterEvents ( ) {
90
91
handleClickRemoveListener ( this . querySelector ( '.action.download' ) , this . downloadVideoHandler . bind ( this ) )
@@ -93,11 +94,13 @@ class VideoElement extends HTMLElement {
93
94
handleClickRemoveListener ( this . querySelector ( '.action.show-summary' ) , this . showSummaryHandler . bind ( this ) )
94
95
handleClickRemoveListener ( this . querySelector ( '.action.ignore' ) , this . toggleIgnoreVideoHandler . bind ( this ) )
95
96
handleClickRemoveListener ( this . querySelector ( '.channel-name' ) , this . filterByChannelHandler . bind ( this ) )
97
+ handleClickRemoveListener ( this . querySelector ( '.play.video-placeholder' ) , this . watchVideoHandler . bind ( this ) )
98
+ handleClickRemoveListener ( this . querySelector ( '.download.video-placeholder' ) , this . downloadVideoHandler . bind ( this ) )
96
99
this . querySelector ( 'video' ) && this . unregisterVideoEvents ( this . querySelector ( 'video' ) )
97
100
}
98
101
watchVideoHandler ( event ) {
99
102
event . preventDefault ( )
100
- this . querySelector ( '.play- video-placeholder' ) . outerHTML = /*html*/ `<video controls width="400">
103
+ this . querySelector ( '.play. video-placeholder' ) . outerHTML = /*html*/ `<video controls width="400">
101
104
<source src="/videos/${ this . video . id } " type="video/mp4" />
102
105
<track
103
106
default
@@ -115,9 +118,14 @@ class VideoElement extends HTMLElement {
115
118
}
116
119
downloadVideoHandler ( event ) {
117
120
event . preventDefault ( )
121
+
118
122
const downloadStartedText = '⚡️ Download started'
119
- if ( event . target . innerText === downloadStartedText ) return console . log ( 'already downloading' )
120
- event . target . innerText = downloadStartedText
123
+ let $downloadButton = event . target . classList . contains ( '.action' ) ? event . target : this . querySelector ( '.action.download' )
124
+ if ( $downloadButton . innerText === downloadStartedText ) return console . log ( 'already downloading' )
125
+ else $downloadButton . innerText = downloadStartedText
126
+
127
+ this . classList . add ( 'downloading' )
128
+
121
129
fetch ( '/api/download-video' , {
122
130
method : 'POST' ,
123
131
headers : { 'Content-Type' : 'application/json' } ,
@@ -137,6 +145,7 @@ class VideoElement extends HTMLElement {
137
145
. then ( ( ) => {
138
146
console . log ( 'Video deleted' )
139
147
this . video . downloaded = false
148
+ this . classList . remove ( 'downloading' )
140
149
this . render ( )
141
150
} )
142
151
. catch ( ( error ) => console . error ( 'Error deleting video:' , error ) )
0 commit comments