@@ -4,6 +4,7 @@ import { t } from '@/i18n';
4
4
import { createPlugin } from '@/utils' ;
5
5
import { menu } from './menu' ;
6
6
import { AmbientModePluginConfig } from './types' ;
7
+ import { waitForElement } from '@/utils/wait-for-element' ;
7
8
8
9
const defaultConfig : AmbientModePluginConfig = {
9
10
enabled : false ,
@@ -36,7 +37,7 @@ export default createPlugin({
36
37
unregister : null as ( ( ) => void ) | null ,
37
38
update : null as ( ( ) => void ) | null ,
38
39
interval : null as NodeJS . Timeout | null ,
39
- lastMediaType : null as " video" | " image" | null ,
40
+ lastMediaType : null as ' video' | ' image' | null ,
40
41
lastVideoSource : null as string | null ,
41
42
lastImageSource : null as string | null ,
42
43
@@ -53,7 +54,8 @@ export default createPlugin({
53
54
const songImage = document . querySelector < HTMLImageElement > ( '#song-image' ) ;
54
55
const songVideo = document . querySelector < HTMLDivElement > ( '#song-video' ) ;
55
56
const image = songImage ?. querySelector < HTMLImageElement > ( 'yt-img-shadow > img' ) ;
56
- const video = songVideo ?. querySelector < HTMLVideoElement > ( '.html5-video-container > video' ) ;
57
+ const video = await waitForElement < HTMLVideoElement > ( '.html5-video-container > video' ) ;
58
+
57
59
const videoWrapper = document . querySelector ( '#song-video > .player-wrapper' ) ;
58
60
59
61
const injectBlurImage = ( ) => {
@@ -179,12 +181,12 @@ export default createPlugin({
179
181
const isVideoMode = ( ) => {
180
182
const songVideo = document . querySelector < HTMLDivElement > ( '#song-video' ) ;
181
183
if ( ! songVideo ) {
182
- this . lastMediaType = " image" ;
184
+ this . lastMediaType = ' image' ;
183
185
return false ;
184
186
}
185
187
186
188
const isVideo = getComputedStyle ( songVideo ) . display !== 'none' ;
187
- this . lastMediaType = isVideo ? " video" : " image" ;
189
+ this . lastMediaType = isVideo ? ' video' : ' image' ;
188
190
return isVideo ;
189
191
} ;
190
192
@@ -196,16 +198,16 @@ export default createPlugin({
196
198
if ( isPageOpen ) {
197
199
const isVideo = isVideoMode ( ) ;
198
200
if ( ! force ) {
199
- if ( this . lastMediaType === " video" && this . lastVideoSource === video ?. src ) return false ;
200
- if ( this . lastMediaType === " image" && this . lastImageSource === image ?. src ) return false ;
201
+ if ( this . lastMediaType === ' video' && this . lastVideoSource === video ?. src ) return false ;
202
+ if ( this . lastMediaType === ' image' && this . lastImageSource === image ?. src ) return false ;
201
203
}
202
204
this . unregister ?.( ) ;
203
205
this . unregister = ( isVideo ? injectBlurVideo ( ) : injectBlurImage ( ) ) ?? null ;
204
206
} else {
205
207
this . unregister ?.( ) ;
206
208
this . unregister = null ;
207
209
}
208
- }
210
+ } ;
209
211
210
212
/* needed for switching between different views (e.g. miniplayer) */
211
213
const observer = new MutationObserver ( ( mutationsList ) => {
0 commit comments