-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
36 lines (30 loc) · 1.09 KB
/
Copy pathpopup.js
File metadata and controls
36 lines (30 loc) · 1.09 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
const CONFIG = {
storageName: "ixjb94_leverage_popup",
}
document.addEventListener("DOMContentLoaded", () => {
const maxLossInput = document.getElementById("maxLoss");
const feeInput = document.getElementById("fee");
const saveButton = document.getElementById("saveButton");
// Load localStorage
chrome.storage.local.get([CONFIG.storageName]).then((value) => {
if (typeof value == "object") {
const { fee, maxLoss } = value[CONFIG.storageName]
maxLossInput.value = maxLoss
feeInput.value = fee
}
})
// Save localStorage --- Send Data
saveButton.addEventListener("click", () => {
const value = {
maxLoss: maxLossInput.value,
fee: feeInput.value,
};
chrome.storage.local.set({ [CONFIG.storageName]: value })
// Send -> content.js
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs[0]?.id) {
chrome.tabs.sendMessage(tabs[0].id, { message: value });
}
});
});
});