-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
70 lines (62 loc) · 1.99 KB
/
popup.js
File metadata and controls
70 lines (62 loc) · 1.99 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const qs = (s) => document.querySelector(s);
const enabledEl = qs('#enabled');
const statusEl = qs('#status');
const voiceBoostDb = qs('#voiceBoostDb');
const musicCutDb = qs('#musicCutDb');
const bassCutHz = qs('#bassCutHz');
const sparkleCutHz = qs('#sparkleCutHz');
const resetBtn = qs('#reset');
const labels = {
voiceBoostVal: qs('#voiceBoostVal'),
musicCutVal: qs('#musicCutVal'),
bassCutVal: qs('#bassCutVal'),
sparkleVal: qs('#sparkleVal')
};
function updateLabels() {
labels.voiceBoostVal.textContent = `+${voiceBoostDb.value} dB`;
labels.musicCutVal.textContent = `−${musicCutDb.value} dB`;
labels.bassCutVal.textContent = `${bassCutHz.value} Hz`;
labels.sparkleVal.textContent = `${sparkleCutHz.value} Hz`;
}
async function getActiveTabId() {
return new Promise((resolve) => {
chrome.runtime.sendMessage({ type: 'GET_ACTIVE_TAB_ID' }, (res) => resolve(res?.tabId));
});
}
async function sendToTab(msg) {
const tabId = await getActiveTabId();
if (!tabId) return;
chrome.tabs.sendMessage(tabId, msg, () => void 0);
}
enabledEl.addEventListener('change', async (e) => {
const enabled = e.target.checked;
await sendToTab({ type: 'HUSH_TOGGLE', enabled });
statusEl.textContent = enabled ? 'Running' : 'Idle';
});
[voiceBoostDb, musicCutDb, bassCutHz, sparkleCutHz].forEach((el) => {
el.addEventListener('input', () => {
updateLabels();
const payload = {
voiceBoostDb: Number(voiceBoostDb.value),
musicCutDb: -Math.abs(Number(musicCutDb.value)),
bassCutHz: Number(bassCutHz.value),
sparkleCutHz: Number(sparkleCutHz.value)
};
sendToTab({ type: 'HUSH_UPDATE_SETTINGS', payload });
});
});
resetBtn.addEventListener('click', () => {
voiceBoostDb.value = 6;
musicCutDb.value = 12;
bassCutHz.value = 120;
sparkleCutHz.value = 8000;
updateLabels();
const payload = {
voiceBoostDb: 6,
musicCutDb: -12,
bassCutHz: 120,
sparkleCutHz: 8000
};
sendToTab({ type: 'HUSH_UPDATE_SETTINGS', payload });
});
updateLabels();