-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
25 lines (20 loc) · 920 Bytes
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const PLAYER_SELECTOR = "div[data-a-target='video-player']";
const CONTROLS_SELECTOR = "div[data-a-target='player-controls']";
const PAUSE_BTN_SELECTOR = "button[data-a-target='player-play-pause-button']";
function addPauseEventListener(player, controls, pauseButton) {
const pauseVideo = () => pauseButton.click();
player.addEventListener("click", (event) => {
controls.contains(event.target) || pauseVideo();
});
}
function observePlayerAndButton() {
const player = document.querySelector(PLAYER_SELECTOR);
const controls = document.querySelector(CONTROLS_SELECTOR);
const pauseButton = document.querySelector(PAUSE_BTN_SELECTOR);
if (player && controls && pauseButton) {
observer.disconnect();
addPauseEventListener(player, controls, pauseButton);
}
}
const observer = new MutationObserver(observePlayerAndButton);
observer.observe(document.body, { childList: true, subtree: true });