-
Notifications
You must be signed in to change notification settings - Fork 0
/
toggle.js
39 lines (37 loc) · 1.04 KB
/
toggle.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
var enabled = false;
// Set ext_enabled variable in storage to be used in hover.js
chrome.storage.local.set({ext_enabled: true}, function() {
console.log('Enabled extension');
enabled = true;
});
// Runs toggleExtension function when extension button in toolbar is clicked
chrome.browserAction.onClicked.addListener(toggleExtension);
function toggleExtension() {
console.log("Toggling...")
if(enabled) {
chrome.storage.local.set({ext_enabled: false}, function() {
console.log('Disabled extension');
enabled = false;
// Changes extension icon in toolbar
chrome.browserAction.setIcon({
path: {
"32":"images/hand_faded-32.png"
}
});
});
} else {
chrome.storage.local.set({ext_enabled: true}, function() {
console.log('Enabled extension');
enabled = true;
chrome.browserAction.setIcon({
path: {
"32":"images/hand-32.png"
}
});
});
}
// Refresh required to apply changes
chrome.tabs.query({active: true, currentWindow: true}, function (arrayOfTabs) {
chrome.tabs.reload(arrayOfTabs[0].id);
});
}