-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
40 lines (34 loc) · 1.14 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
// Initialize domainIPMap with existing data from storage (if any)
let domainIPMap = {};
// Retrieve domainIPMap from storage
chrome.storage.local.get('domainIPMap', function (data) {
if (data.domainIPMap) {
domainIPMap = data.domainIPMap;
}
});
// Message listener to update domainIPMap and respond with updated value
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (request.action === 'updateDomainIPMap') {
const domain = request.domain;
const ipAddress = request.ipAddress;
if (domain in domainIPMap) {
const domainData = domainIPMap[domain];
if (!domainData.ipAddresses.includes(ipAddress)) {
domainData.ipAddresses.push(ipAddress);
domainData.count++;
}
} else {
domainIPMap[domain] = {
ipAddresses: [ipAddress],
count: 1
};
}
// Save updated domainIPMap to storage
chrome.storage.local.set({ 'domainIPMap': domainIPMap }, function () {
// Send back the updated domainIPMap
sendResponse(domainIPMap);
});
// Return true to indicate that the response will be sent asynchronously
return true;
}
});