-
Notifications
You must be signed in to change notification settings - Fork 13
/
background.js
65 lines (61 loc) · 1.79 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
59
60
61
62
63
64
65
chrome.browserAction.onClicked.addListener(ppcMain.inlineToggle);
chrome.tabs.onSelectionChanged.addListener(ppcMain.onTabSelect);
chrome.extension.onRequest.addListener(
function(request, sender, response) {
switch(request.type) {
case 'enable?':
console.log('enable?');
ppcMain.onTabSelect(sender.tab.id);
break;
case 'xsearch':
console.log('xsearch');
var e = ppcMain.search(request.text, request.showmode);
response(e);
break;
case 'translate':
console.log('translate');
var e = ppcMain.dict.translate(request.title);
response(e);
break;
case 'makehtml':
console.log('makehtml');
var html = ppcMain.dict.makeHtml(request.entry);
response(html);
break;
default:
console.log(request);
}
});
if(initStorage("v0.9", true)) {
// v0.7
initStorage("popupcolor", "charcoal");
initStorage("highlight", "yes");
initStorage("docolors", "yes");
initStorage("showhanzi", "boths");
initStorage("pinyin", "tonemarks");
// v0.8
// No changes to options
}
/**
* Initializes the localStorage for the given key.
* If the given key is already initialized, nothing happens.
*
* @author Teo (GD API Guru)
* @param key The key for which to initialize
* @param initialValue Initial value of localStorage on the given key
* @return true if a value is assigned or false if nothing happens
*/
function initStorage(key, initialValue) {
var currentValue = localStorage[key];
if (!currentValue) {
localStorage[key] = initialValue;
return true;
}
return false;
}
ppcMain.config = {};
ppcMain.config.css = localStorage["popupcolor"];
ppcMain.config.highlight = localStorage["highlight"];
ppcMain.config.showhanzi = localStorage["showhanzi"];
ppcMain.config.docolors = localStorage["docolors"];
ppcMain.config.pinyin = localStorage["pinyin"];