forked from ledudu/LiWuChromePlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.html
78 lines (73 loc) · 1.93 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
72
73
74
75
76
77
78
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="jquery.js" charset="utf-8"></script>
<script>
var result="";
var selfname= "";
var rports={};
var lports={};
var bgtabid=0;
var robjs={};
var lobjs ={};
chrome.extension.onConnect.addListener(dealPort);
function dealPort(port) {
bgtabid = port.sender.tab.id;
if(port.name =="left"){
lports[bgtabid] = port;
port.onMessage.addListener(function(msg){
selfname = msg.selfname;
lobjs[bgtabid] = msg.result;
showPopup({},port.sender.tab.id);
});
}else{
rports[bgtabid] = port;
port.onMessage.addListener(function(msg){
robjs[bgtabid] = msg;
result = msg;
showPopup({},port.sender.tab.id);
});
}
}
function onRequest(request,sender,response){
if(request.ask=="right"){
rports[bgtabid].postMessage(request.request);
}else if(request.ask=="left"){
for(var i in lports){
lports[i].postMessage(request.request);
}
}else if(request.ask=="getResult"){
var rp = function(rpp){result=rpp.result};
chrome.tabs.sendRequest(bgtabid,{ask:"getResult"},rp);
}else if(request.ask=="rtime"){
for(var i in rports){
rports[i].postMessage(request.request);
}
}else if(request.ask=="niming"){
for(var i in rports){
rports[i].postMessage(request.request);
}
}
}
chrome.extension.onRequest.addListener(onRequest);
chrome.tabs.onSelectionChanged.addListener(function(id,obj){
chrome.tabs.sendRequest(id,{ask:"getResult"},function(response){
bgtabid = id;
//p(id+":in background");
result = response.result;
});
});
function showPopup(re,id){
chrome.pageAction.show(id);
}
function p(obj){
console.log(obj);
alert(obj);
}
</script>
</head>
<body>
</body>
</html>