-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
58 lines (52 loc) · 1.58 KB
/
background.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
/*
* 更新icon
*/
function updateIcon(_enabled) {
browser.browserAction.setIcon({
path: _enabled ? {
16: "icons/page-16-colored.png",
32: "icons/page-32-colored.png"
} : {
16: "icons/page-16.png",
32: "icons/page-32.png"
}
});
browser.browserAction.setTitle({
title: _enabled ? 'disable WASD' : 'enable WASD'
});
}
/*
* Enable/Disable WASD
*/
function toggleWASD() {
browser.storage.local.get('wasd-enabled').then( enabled => {
let _enabled;
if (enabled.hasOwnProperty('wasd-enabled')) {
_enabled = enabled['wasd-enabled'] ? true:false;
} else if (enabled.hasOwnProperty(0) && enabled[0].hasOwnProperty('wasd-enabled')) {
sites = enabled[0]['sites'] ? true:false;
} else {
_enabled = true;
}
_enabled = !_enabled;
browser.storage.local.set({
'wasd-enabled' : _enabled
});
updateIcon(_enabled);
});
}
function initialWASD() {
browser.storage.local.get('wasd-enabled').then( enabled => {
let _enabled;
if (enabled.hasOwnProperty('wasd-enabled')) {
_enabled = enabled['wasd-enabled'] ? true:false;
} else if (enabled.hasOwnProperty(0) && enabled[0].hasOwnProperty('wasd-enabled')) {
sites = enabled[0]['sites'] ? true:false;
} else {
_enabled = true;
}
updateIcon(_enabled);
});
}
initialWASD();
browser.browserAction.onClicked.addListener(toggleWASD);