-
Notifications
You must be signed in to change notification settings - Fork 15
/
cssreloader.background.js
59 lines (49 loc) · 1.43 KB
/
cssreloader.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
59
;(function () {
var storageKey = 'shortcutOptions'
var defaultShortcutOptions = {
'keyIdentifier': 'F9',
'altKeySelected': false,
'controlKeySelected': false,
'shiftKeySelected': false,
'blacklist': []
}
function initialize () {
browser.contextMenus.create({'title': 'Reload CSS', 'type': 'normal', 'onclick': onContextMenuClicked})
browser.runtime.onMessage.addListener(onExtensionMessage)
}
function onExtensionMessage (request, sender, callback) {
if (request.action == 'getSettings') {
return Promise.resolve(getSettings())
}
if (request.action == 'saveSettings') {
saveSettings(request.data)
}
}
function onContextMenuClicked (info, tab) {
browser.tabs.sendMessage(tab.id, {action: 'reload'})
}
function saveSettings (settings) {
if (settings) {
localStorage[storageKey] = JSON.stringify(settings)
}
}
function getSettings () {
var storedObject = localStorage[storageKey]
var settings
if (storedObject) {
settings = JSON.parse(storedObject)
// new blacklist setting needs to be added by hand
// if it's not in the localStorage settings
if (! ('blacklist' in settings)) {
settings['blacklist'] = []
saveSettings(settings)
}
} else {
// Going for default settings
settings = defaultShortcutOptions
saveSettings(settings)
}
return settings
}
initialize()
})()