-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
62 lines (50 loc) · 1.49 KB
/
Copy pathbackground.js
File metadata and controls
62 lines (50 loc) · 1.49 KB
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
// main_frame,sub_frame, beacon,xmlhttprequest,csp_report,font,other,image
// in cache responseDetails.fromCache NO IP
function addIPtoTitle(responseDetails) {
const tabId = responseDetails.tabId ;
if (responseDetails.type === "image"){
return ;
}
if (tabId){
if (! ipData[tabId]) ipData[tabId] = {} ;
if(responseDetails.type === "main_frame"){
ipData[tabId] = {};
}
if (tabId !== -1 && responseDetails.ip) {
add_ips(responseDetails, tabId);
}
}
}
function add_ips(responseDetails, tabId) {
let parser;
if (responseDetails.ip) { // not from cache
parser = document.createElement('a');
parser.href = responseDetails.url;
let hostname = parser.hostname
let ip = responseDetails.ip;
//if (!ipData[tabId][ip]) ipData[tabId][ip] = {};
if (!ipData[tabId][ip]) {
ipData[tabId][ip] = {
"type": [responseDetails.type],
"hostname": hostname
}
} else {
if (!ipData[tabId][ip]['type'].includes(responseDetails.type)) {
ipData[tabId][ip]['type'].push(responseDetails.type)
}
}
}
}
// define variables
var ipData = {};
chrome.tabs.onUpdated.addListener((tabId, changeInfo) => {
if (changeInfo.status === "complete") {
chrome.pageAction.setTitle({
tabId: tabId,title:"Show ASN"
});
chrome.pageAction.show(tabId);
var popup = chrome.pageAction.setPopup({tabId: tabId,popup:"popup.html#"+tabId});
}
});
// for every webRequest get the hostname and ip
chrome.webRequest.onCompleted.addListener( addIPtoTitle, { urls: ["<all_urls>"] });