-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
46 lines (38 loc) · 1.17 KB
/
index.js
File metadata and controls
46 lines (38 loc) · 1.17 KB
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
let currentTabID = -1;
let volumeSlider = document.getElementById("volumeSlider");
volumeSlider.oninput = setVolume;
let volumeText = document.getElementById("volumeText");
getVolume();
function getVolume() {
browser.tabs.query({ active: true, currentWindow: true }, async (tab) => {
if (tab.length != 1) return;
currentTabID = tab[0].id;
let val = 1.0;
await browser.tabs
.sendMessage(currentTabID, {
extension: "volumeControl",
action: "getVolume"
})
.then((resp) => { val = resp.response; })
.catch((error) => { console.log(error); });
if (volumeSlider != null) volumeSlider.value = val * 100.0;
updateVolumeText();
});
}
function setVolume() {
if (volumeSlider == null) return;
if (currentTabID == -1) return;
browser.tabs
.sendMessage(currentTabID, {
extension: "volumeControl",
action: "setVolume",
value: (volumeSlider.value / 100.0).toFixed(3)
})
.catch((error) => { console.log(error); });
updateVolumeText();
}
function updateVolumeText() {
if (volumeText == null) return;
if (volumeSlider == null) return;
volumeText.textContent = "Volume: " + volumeSlider.value + "%";
}