-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
69 lines (59 loc) · 2.04 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
document.body.onload = () => { setCheckbox(); calculate(); };
const button = document.getElementById('calc_data');
button.onclick = calculate;
// console.log(button);
const toggle_checkbox = document.getElementById('toggle_data');
toggle_checkbox.onclick = toggle;
async function calculate() {
const popup_div = document.getElementById('custom_data');
// Get current active tab
let currentTab = chrome.tabs.query({ active: true, currentWindow: true });
currentTab.then(tabs => {
// console.log("Current Tab", tabs);
let tab = tabs[0];
chrome.tabs.sendMessage(
tab.id,
{ type: "calculate" },
(response) => {
if (!response) return;
console.log("Got response from content script: ", response);
let { totCrediti, media, mediaPesata } = response;
popup_div.innerHTML =
`<p> Totale: ${totCrediti} crediti</p>
<p> Media: ${media}</p>
<p> Media Pesata: ${mediaPesata}</p>
`;
}
);
});
}
async function toggle() {
let currentTab = chrome.tabs.query({ active: true, currentWindow: true });
currentTab.then(tabs => {
// console.log("Current Tab", tabs);
let tab = tabs[0];
chrome.tabs.sendMessage(
tab.id,
{ type: "toggleData" },
(response) => {
if (!response) return;
console.log("Got response from content script: ", response);
}
);
});
}
async function setCheckbox() {
let currentTab = chrome.tabs.query({ active: true, currentWindow: true });
currentTab.then(tabs => {
// console.log("Current Tab", tabs);
let tab = tabs[0];
chrome.tabs.sendMessage(
tab.id,
{ type: "setCheckbox" },
(response) => {
if (!response) return;
console.log("Got response from content script: ", response);
}
);
});
}