-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbackground.js
49 lines (39 loc) · 908 Bytes
/
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
var config = {
enable : 0,
total : 0
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.action == "set"){
config.enable = request.enable;
if(config.enable) { config.total = 0; }
send_enable();
return;
}
if(request.action == "get"){
var message = {action: "set",
enable: config.enable,
total:config.total};
sendResponse(message);
return;
}
if(request.action == "inc"){
config.total = config.total+request.value;
sendResponse({total:config.total});
return;
}
if(request.action == "log"){
console.log(request.log);
return;
}
});
function send_enable(){
chrome.tabs.query({}, function(tabs) {
var message = {action: "set",
enable: config.enable,
total:config.total};
for (var i=0; i<tabs.length; ++i) {
chrome.tabs.sendMessage(tabs[i].id, message);
}
});
}