File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed
injected/src/features/duckplayer-native Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -29,3 +29,41 @@ export function stopVideoFromPlaying(videoSelector) {
29
29
}
30
30
} ;
31
31
}
32
+
33
+ const MUTE_ELEMENTS_QUERY = 'audio, video' ;
34
+
35
+ /**
36
+ * Mute all audio and video elements
37
+ *
38
+ * @returns {() => void } A function that allows the elements to be unmuted
39
+ */
40
+ export function muteAllElements ( ) {
41
+ /**
42
+ * Set up the interval
43
+ */
44
+ const int = setInterval ( ( ) => {
45
+ /** @type {(HTMLAudioElement | HTMLVideoElement)[] } */
46
+ const elements = Array . from ( document . querySelectorAll ( MUTE_ELEMENTS_QUERY ) ) ;
47
+ elements . forEach ( ( element ) => {
48
+ if ( element ?. isConnected ) {
49
+ element . muted = true ;
50
+ }
51
+ } ) ;
52
+ } , 10 ) ;
53
+
54
+ /**
55
+ * To clean up, we need to stop the interval
56
+ * and then call .play() on the original element, if it's still connected
57
+ */
58
+ return ( ) => {
59
+ clearInterval ( int ) ;
60
+
61
+ /** @type {(HTMLAudioElement | HTMLVideoElement)[] } */
62
+ const elements = Array . from ( document . querySelectorAll ( MUTE_ELEMENTS_QUERY ) ) ;
63
+ elements . forEach ( ( element ) => {
64
+ if ( element ?. isConnected ) {
65
+ element . muted = false ;
66
+ }
67
+ } ) ;
68
+ } ;
69
+ }
Original file line number Diff line number Diff line change 1
1
import { Logger , SideEffects } from '../../duckplayer/util.js' ;
2
2
import { muteAudio } from '../mute-audio.js' ;
3
3
import { pollTimestamp } from '../get-current-timestamp.js' ;
4
- import { stopVideoFromPlaying } from '../pause-video.js' ;
4
+ import { stopVideoFromPlaying , muteAllElements } from '../pause-video.js' ;
5
5
import { showThumbnailOverlay } from '../overlays/thumbnail-overlay.js' ;
6
6
7
7
/**
@@ -86,6 +86,7 @@ export class DuckPlayerNativeYoutube {
86
86
87
87
if ( pause ) {
88
88
this . sideEffects . add ( 'stopping video from playing' , ( ) => stopVideoFromPlaying ( videoElement ) ) ;
89
+ this . sideEffects . add ( 'muting all elements' , ( ) => muteAllElements ( ) ) ;
89
90
this . sideEffects . add ( 'appending thumbnail' , ( ) => {
90
91
const clickHandler = ( ) => {
91
92
this . messages . notifyOverlayDismissed ( ) ;
@@ -95,6 +96,7 @@ export class DuckPlayerNativeYoutube {
95
96
} ) ;
96
97
} else {
97
98
this . sideEffects . destroy ( 'stopping video from playing' ) ;
99
+ this . sideEffects . destroy ( 'muting all elements' ) ;
98
100
this . sideEffects . destroy ( 'appending thumbnail' ) ;
99
101
}
100
102
}
You can’t perform that action at this time.
0 commit comments