-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserExtension.js
68 lines (60 loc) · 2.28 KB
/
browserExtension.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
javascript: (function () {
try {
console.log("window.mutify", window.mutify);
if (window.mutify) {
alert("already observing......");
return;
}
const nextSongBtn = document.querySelector(
"[data-testid='control-button-skip-forward']"
);
console.log("Select the node that will be observed for mutations",nextSongBtn);
const config = { attributes: true };
console.log("Options for the observer (which mutations to observe)", config);
console.log("Callback function to execute when mutations are observed");
const callback = function (mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === "attributes") {
const isNextSongBtnDisabled = nextSongBtn.hasAttribute("disabled");
const volumeIcon = document.getElementsByClassName(
"volume-bar__icon-button"
)[0];
let isMuted = volumeIcon.getAttribute("aria-label") === "Unmute";
console.log(
`isNextSongBtnDisabled`,
nextSongBtn,
isNextSongBtnDisabled
);
console.log(`isMuted`, volumeIcon, isMuted);
if (isNextSongBtnDisabled && !isMuted) {
console.log("mute audio..........");
volumeIcon.click();
} else if (!isNextSongBtnDisabled && isMuted) {
console.log("unmute audio..........");
volumeIcon.click();
}
}
}
};
console.log("Create an observer instance linked to the callback function");
const spotifyObserver = new MutationObserver(callback);
if (nextSongBtn) {
console.log("Start observing the target node for configured mutations");
spotifyObserver.observe(nextSongBtn, config);
window.mutify = true;
console.log("observing...........");
const isNextSongBtnDisabled = nextSongBtn.hasAttribute("disabled");
const volumeIcon = document.getElementsByClassName(
"volume-bar__icon-button"
)[0];
let isMuted = volumeIcon.getAttribute("aria-label") === "Unmute";
if (isNextSongBtnDisabled && !isMuted) {
console.log("intialize mute audio..........");
volumeIcon.click();
}
alert("Mutify started !!");
}
} catch (err) {
console.log("oopss....", err);
}
})();