-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
37 lines (29 loc) · 1008 Bytes
/
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
// Initialize butotn with users's prefered color
let changeColor = document.getElementById("audioRange");
changeColor.addEventListener("change", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
value = document.getElementById("audioRange").value;
chrome.storage.sync.set({audioValue: value });
chrome.scripting.executeScript({
target: { tabId: tab.id },
function: setAudio,
});
});
// The body of this function will be execuetd as a content script inside the
// current page
function setAudio() {
chrome.storage.sync.get("audioValue", ({ audioValue }) => {
var audioTag = document.getElementById("remote-media");
if(audioTag !== null){
audioTag.volume = audioValue;
}
});
}
// set audiocontrol to current audioValue on reopen
window.onload = () => {
chrome.storage.sync.get("audioValue", ({ audioValue }) => {
if(audioValue !== null && changeColor !== null) {
changeColor.value = audioValue;
}
});
}