forked from renlijie/rikaikun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.html
71 lines (66 loc) · 2.01 KB
/
background.html
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
66
67
68
69
70
71
<html>
<head>
<script src="data.js"></script>
<script src="rikaichan.js"></script>
<script>
chrome.browserAction.onClicked.addListener(rcxMain.inlineToggle);
chrome.tabs.onSelectionChanged.addListener(rcxMain.onTabSelect);
chrome.extension.onRequest.addListener(
function(request, sender, response) {
switch(request.type) {
case 'enable?':
console.log('enable?');
rcxMain.onTabSelect(sender.tab.id);
break;
case 'xsearch':
console.log('xsearch');
var e = rcxMain.search(request.text, request.showmode);
response(e);
break;
case 'translate':
console.log('translate');
var e = rcxMain.dict.translate(request.title);
response(e);
break;
case 'makehtml':
console.log('makehtml');
var html = rcxMain.dict.makeHtml(request.entry);
response(html);
break;
default:
console.log(request);
}
});
if(initStorage("v0.8.5", true)) {
// v0.7
initStorage("popupcolor", "blue");
initStorage("highlight", "yes");
// v0.8
// No changes to options
// V0.8.5
initStorage("textboxhl", "no");
}
/**
* 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;
}
rcxMain.config = {};
rcxMain.config.css = localStorage["popupcolor"];
rcxMain.config.highlight = localStorage["highlight"];
rcxMain.config.textboxhl = localStorage["textboxhl"];
</script>
</head>
</html>