-
Notifications
You must be signed in to change notification settings - Fork 3
/
admute.js
53 lines (44 loc) · 1.31 KB
/
admute.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
function getElement(query) {
return new Promise(async (resolve) => {
let element = document.querySelector(query);
if(element) {
resolve(element);
} else {
await sleep(2000);
getElement(query).then(resolve);
}
});
}
const config = { attributes: true };
let muteState = 1; // 1 = unmuted, 0 = muted
let adMute = 0; // to keep track if the player was muted by the extension or the user
let muteBtn;
let nextBtn;
Promise.all([
getElement('.player-controls__right'),
getElement('.volume-bar')
])
.then((elements) => {
[playerControls, volumeBar] = elements;
nextBtn = playerControls.children[0];
muteBtn = volumeBar.children[0];
muteBtn.addEventListener('click', function() {
muteState = 1-muteState;
});
let observer = new MutationObserver(function(mutations) {
if(nextBtn.hasAttribute('disabled')) {
if(muteState === 1) {
muteBtn.click();
adMute = 1;
}
} else if(adMute === 1 && muteState === 0) { // unmute only if muted by extension
muteBtn.click();
adMute = 0;
} else {
}
});
observer.observe(nextBtn, config);
});