-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpricechecker.js
74 lines (67 loc) · 2.17 KB
/
pricechecker.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
70
71
72
73
74
const togglePriceCheckerEl = document.getElementById('togglePriceChecker');
const togglePriceGraphEl = document.getElementById('togglePriceGraph');
//on init update the UI checkbox based on storage
chrome.storage.sync.get('priceCheckerEnabled', function (data) {
togglePriceCheckerEl.checked = data.priceCheckerEnabled;
});
chrome.storage.sync.get('priceGraphEnabled', function (data) {
togglePriceGraphEl.checked = data.priceGraphEnabled;
});
togglePriceCheckerEl.onchange = function (element) {
let value = this.checked;
//update the extension storage value
chrome.storage.sync.set({ priceCheckerEnabled: value }, function () {
console.log('Price checker status: ' + value);
});
//Pass init or remove message to content script
if (value) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ command: 'init-price-checker', priceCheckerEnabled: value },
function (response) {
console.log(`Init Price Checker Response: ${response?.result}`);
}
);
});
} else {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ command: 'remove-price-checker', priceCheckerEnabled: value },
function (response) {
console.log(`Remove Price Checker Response: ${response?.result}`);
}
);
});
}
};
togglePriceGraphEl.onchange = function (element) {
let value = this.checked;
//update the extension storage value
chrome.storage.sync.set({ priceGraphEnabled: value }, function () {
console.log('Price graph status: ' + value);
});
//Pass init or remove message to content script
if (value) {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ command: 'init-price-graph', priceGraphEnabled: value },
function (response) {
console.log(response.result);
}
);
});
} else {
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
{ command: 'remove-price-graph', priceGraphEnabled: value },
function (response) {
console.log(response.result);
}
);
});
}
};