-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcb_simulator.js
31 lines (27 loc) · 1.13 KB
/
cb_simulator.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
var enableCBSimulatorCheckbox = document.getElementById("enableSimulator");
// On init update the UI checkbox based on storage
chrome.storage.sync.get('cb_enabled', function(data) {
enableCBSimulatorCheckbox.checked = data.cb_enabled;
});
// Pass init or remove message to content script
enableCBSimulatorCheckbox.onchange = function(element) {
let value = this.checked;
// Update the extension storage value
chrome.storage.sync.set({"cb_enabled": value}, function() {
console.log("The value is: " + 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", cb_enabled: 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", cb_enabled: value}, function(response) {
console.log(response.result);
});
});
}
}