/
background.js
38 lines (35 loc) · 1.25 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
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if ("getOptions" == request.message) {
if ("undefined" != typeof localStorage) {
chrome.tabs.query({
"active": true,
"currentWindow": true
},
function(tabs) {
if ("undefined" != typeof tabs[0].id && tabs[0].id) {
var showOccurrences = localStorage.getItem("showOccurrences");
showOccurrences = "true" == showOccurrences || null == showOccurrences;
chrome.tabs.sendMessage(tabs[0].id, {
"message": "returnOptions",
"remove": request.remove,
"keywords": localStorage.getItem("keywords"),
"foreground": localStorage.getItem("foreground") || "#000000",
"background": localStorage.getItem("background") || "#ffff00",
"showOccurrences": showOccurrences
});
}
}
);
}
}
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if ("showOccurrences" == request.message) {
var showOccurrences = localStorage.getItem("showOccurrences");
showOccurrences = "true" == showOccurrences || null == showOccurrences;
chrome.browserAction.setBadgeText({
"text": showOccurrences && request.occurrences ? String(request.occurrences) : "",
"tabId": sender.tab.id
});
}
});