-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbandcamp_volume_control.user.js
64 lines (55 loc) · 1.82 KB
/
bandcamp_volume_control.user.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
// ==UserScript==
// @name Bandcamp volume control
// @description Adds volume control in Bandcamp
// @version 0.1.0
// @match https://*.bandcamp.com/*
// @run-at document-idle
// ==/UserScript==
let volume_control = document.createElement("div");
volume_control.id = "volume_control";
volume_control.style.cssText = `
display: flex;
align-items: center;
justify-content: space-between;
padding: 0px 0px 10px 0px;
`;
let bandcamp_player = document.getElementsByClassName("inline_player")[0];
bandcamp_player.parentNode.insertBefore(volume_control, bandcamp_player.nextSibling);
volume_control.innerHTML = `
<div>Volume:</div>
<input id="volume_slider" type="range" min="0" value="50" max="100" step="1">
<input id="mute_button" type="button" value="Mute">
`;
let bandcamp_audio = document.getElementsByTagName("audio");
let volume_slider = document.getElementById("volume_slider");
let mute_button = document.getElementById("mute_button");
mute_button.style.width = "80px";
volume_slider.value = bandcamp_audio[0].volume * 100;
function mute_audio() {
for (var i = 0; i < bandcamp_audio.length; i++) {
bandcamp_audio[i].muted = true;
}
mute_button.value = "Unmute";
}
function unmute_audio() {
for (var i = 0; i < bandcamp_audio.length; i++) {
bandcamp_audio[i].muted = false;
}
mute_button.value = "Mute";
}
volume_slider.oninput = function () {
if (bandcamp_audio[0].muted === true) {
unmute_audio();
}
for (var i = 0; i < bandcamp_audio.length; i++) {
bandcamp_audio[i].volume = parseInt(volume_slider.value) / 100;
}
};
mute_button.onclick = function () {
if (bandcamp_audio[0].muted === true) {
unmute_audio();
}
else if (bandcamp_audio[0].muted === false) {
mute_audio();
}
};