This repository has been archived by the owner on Jul 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathbackground.js
56 lines (52 loc) · 2.09 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
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
console.log(tab);
if (changeInfo.status === 'loading' && tab.url.indexOf("qiandao.today") != -1) {
if (!chrome.runtime.onConnect.hasListeners()) {
chrome.runtime.onConnect.addListener(function(port) {
console.assert(port.name == "get_cookie");
port.onMessage.addListener(function(request) {
console.log(request);
if (request.do == "get_cookie") {
var option = {};
if (request.site) {
option["url"] = request.site;
}
if (request.name != null) {
option["name"] = request.name;
}
if (request.domain) {
option["domain"] = request.domain;
}
chrome.cookies.getAll(option, function(cookies) {
var obj = {};
for (var i in cookies) {
var cookie = cookies[i];
obj[cookie.name] = cookie.value;
}
port.postMessage(obj);
console.log(obj);
});
}
});
});
}
}
});
// if (cookie) {
// var data = cookies.name + "=" + cookies.value;
// port.postMessage({"cookie": data});
// console.log(data);
// }
// chrome.runtime.onMessage.addListener(
// function(request, sender, sendResponse) {
// if (request.do == "get_cookie") {
// var data="";
// chrome.cookies.get({"url": request.domain, "name": request.name}, function(cookies) {
// if(cookies){
// data = cookies.name + "=" + cookies.value;
// }
// });
// sendResponse({"cookie": data});
// console.log(data);
// }
// });