-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathding-on-checked.js
More file actions
25 lines (22 loc) · 821 Bytes
/
ding-on-checked.js
File metadata and controls
25 lines (22 loc) · 821 Bytes
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
const url = chrome.runtime.getURL("assets/ding.wav");
const getNonLinearVolumeLevel = (volume) => {
const volumeBetween0and1 = volume / 10;
const EXP_SCALE_FACTOR = 4;
return (
Math.exp(EXP_SCALE_FACTOR * volumeBetween0and1) / Math.exp(EXP_SCALE_FACTOR)
);
};
document.addEventListener("click", (event) => {
const path = event.composedPath()
const checkbox = path.find(element => element.matches("input[type=checkbox]"))
const isCheckboxClick = !!checkbox;
const isUnchecked = checkbox.parentElement.getElementsByClassName('check').length === 0
if (isCheckboxClick && isUnchecked) {
chrome.storage.sync.get(["volume"], ({ volume }) => {
if (volume === 0) return;
const ding = new Audio(url);
ding.volume = getNonLinearVolumeLevel(volume);
ding.play();
});
}
});