@@ -15,6 +15,11 @@ export class VideoOverlayManager {
15
15
/** @type {import("./video-player-icon").VideoPlayerIcon | null } */
16
16
videoPlayerIcon = null
17
17
18
+ selectors = {
19
+ videoElement : '#player video' ,
20
+ container : '#player .html5-video-player'
21
+ }
22
+
18
23
/**
19
24
* @param {import("../duck-player.js").UserValues } userValues
20
25
* @param {import("./overlays.js").Environment } environment
@@ -80,7 +85,7 @@ export class VideoOverlayManager {
80
85
* @param {import("./util").VideoParams } params
81
86
*/
82
87
addSmallDaxOverlay ( params ) {
83
- const containerElement = document . querySelector ( '#player .html5-video-player' )
88
+ const containerElement = document . querySelector ( this . selectors . container )
84
89
if ( ! containerElement ) {
85
90
console . error ( 'no container element' )
86
91
return
@@ -117,17 +122,11 @@ export class VideoOverlayManager {
117
122
]
118
123
119
124
if ( conditions . some ( Boolean ) ) {
120
- const playerElement = document . querySelector ( '#player' )
121
-
122
- if ( ! playerElement ) {
123
- return null
124
- }
125
-
126
125
/**
127
126
* Don't continue until we've been able to find the HTML elements that we inject into
128
127
*/
129
- const videoElement = playerElement . querySelector ( 'video' )
130
- const playerContainer = playerElement . querySelector ( '.html5-video-player' )
128
+ const videoElement = document . querySelector ( this . selectors . videoElement )
129
+ const playerContainer = document . querySelector ( this . selectors . container )
131
130
if ( ! videoElement || ! playerContainer ) {
132
131
return null
133
132
}
@@ -152,7 +151,7 @@ export class VideoOverlayManager {
152
151
if ( 'alwaysAsk' in userValues . privatePlayerMode ) {
153
152
if ( ! userValues . overlayInteracted ) {
154
153
if ( ! this . environment . hasOneTimeOverride ( ) ) {
155
- this . stopVideoFromPlaying ( videoElement )
154
+ this . stopVideoFromPlaying ( )
156
155
this . appendOverlayToPage ( playerContainer , params )
157
156
}
158
157
} else {
@@ -187,15 +186,16 @@ export class VideoOverlayManager {
187
186
/**
188
187
* Just brute-force calling video.pause() for as long as the user is seeing the overlay.
189
188
*/
190
- stopVideoFromPlaying ( videoElement ) {
191
- this . sideEffect ( ' pausing the <video> element' , ( ) => {
189
+ stopVideoFromPlaying ( ) {
190
+ this . sideEffect ( ` pausing the <video> element with selector ' ${ this . selectors . videoElement } '` , ( ) => {
192
191
/**
193
192
* Set up the interval - keep calling .pause() to prevent
194
193
* the video from playing
195
194
*/
196
195
const int = setInterval ( ( ) => {
197
- if ( videoElement instanceof HTMLVideoElement && videoElement . isConnected ) {
198
- videoElement . pause ( )
196
+ const video = /** @type {HTMLVideoElement } */ ( document . querySelector ( this . selectors . videoElement ) )
197
+ if ( video ?. isConnected ) {
198
+ video . pause ( )
199
199
}
200
200
} , 10 )
201
201
@@ -206,13 +206,9 @@ export class VideoOverlayManager {
206
206
return ( ) => {
207
207
clearInterval ( int )
208
208
209
- if ( videoElement ?. isConnected ) {
210
- videoElement . play ( )
211
- } else {
212
- const video = document . querySelector ( '#player video' )
213
- if ( video instanceof HTMLVideoElement ) {
214
- video . play ( )
215
- }
209
+ const video = /** @type {HTMLVideoElement } */ ( document . querySelector ( this . selectors . videoElement ) )
210
+ if ( video ?. isConnected ) {
211
+ video . play ( )
216
212
}
217
213
}
218
214
} )
0 commit comments