-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
47 lines (42 loc) · 1.61 KB
/
popup.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
let btn = document.querySelector("#btn");
btn.checked = !!localStorage.getItem("working");
btn.checked ? chrome.browserAction.setIcon({path: "images/abiIcon.png"}) : chrome.browserAction.setIcon({path: "images/abiIconGray.png"});
let meter = document.querySelector("meter");
meter.value = -100;
chrome.runtime.onMessage.addListener(function (req) {
if (req.match(/Current decibels:/) !== null) {
if (btn.checked) {
meter.value = req.match(/-?\d+/g)[0];
}
}
});
let decibelsRangeView = document.querySelector("#decibels");
let decibelsValueView = document.querySelector("#decibelsValue");
if (localStorage.getItem("decibelsThreshold") === null) {
decibelsRangeView.value = -25;
} else {
decibelsRangeView.value = localStorage.getItem("decibelsThreshold");
}
decibelsValueView.innerHTML = decibelsRangeView.value;
document.addEventListener("DOMContentLoaded", function () {
btn.addEventListener("change", () => {
chrome.runtime.sendMessage({
action: "Allow record?",
value: btn.checked
});
if (btn.checked) {
chrome.browserAction.setIcon({path: "images/abiIcon.png"});
} else {
chrome.browserAction.setIcon({path: "images/abiIconGray.png"});
meter.value = -100;
}
});
decibelsRangeView.oninput = () => {
localStorage.setItem("decibelsThreshold", decibelsRangeView.value)
decibelsValueView.innerHTML = decibelsRangeView.value;
chrome.runtime.sendMessage({
action: "Decibels threshold:",
value: decibelsRangeView.value
});
};
});