-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
58 lines (51 loc) · 1.43 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
57
58
//var port = browser.runtime.connect();
var urls = [];
var intercept = false;
var selectedType = "all";
browser.runtime.onConnect.addListener(function(p) {
if (intercept) {
p.postMessage({"on": "true"});
} else if (!intercept) {
p.postMessage({"on": "false"});
}
console.log("OnCon" + selectedType);
p.postMessage({"selectedType": selectedType});
if (urls.length > 0) {
for (var u of urls) {
p.postMessage({"req": u});
}
}
});
browser.runtime.onMessage.addListener(function(m) {
console.log(m.msg);
switch (m.msg) {
case "clear":
urls = [];
case "intercept":
intercept = !intercept;
}
if (m.selectedType){
console.log("Selected Typed" + m.selectedType);
selectedType = m.selectedType;
}
});
function logURL(req) {
if (!intercept) {
return;
}
console.log("Selected" + selectedType + req.type);
if (selectedType !== "all" && req.type !== selectedType) {
return;
}
var result = "<li><small>"+ req.method
+ " [<span class=status>" + req.statusCode + "</span>] "
+ " [<span class=type>" + req.type + "</span>] "
+ "</small><br> <a target=_blank href=" + req.url + ">"
+ req.url + "</a><br></li>";
// FIXME: leaves undefined somewhere
urls.push(result);
}
browser.webRequest.onHeadersReceived.addListener(
logURL,
{urls: ["<all_urls>"]}
);