-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
38 lines (34 loc) · 977 Bytes
/
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
let ipVpn = "";
let ipAtual = "";
async function obterIP() {
try {
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
return data.ip;
} catch (error) {
console.error('Erro ao obter o IP:', error);
return null;
}
}
// chrome.runtime.onStartup.addListener(function () {
// ipAtual = obterIP();
// });
chrome.webNavigation.onCompleted.addListener(async function (details) {
chrome.storage.sync.get(["updateIPAutomatically"], async function (result) {
if (result.updateIPAutomatically) {
ipAtual = await obterIP();
}
else if (ipAtual === "") {
ipAtual = await obterIP();
}
chrome.storage.sync.get(["ipVpn"], function (result) {
ipVpn = result.ipVpn || "";
verificarVPN(ipAtual, ipVpn, details);
});
});
});
function verificarVPN(ip, ipVpn, details) {
if (ip != ipVpn) {
chrome.tabs.sendMessage(details.tabId, { vpnActivated: true });
}
}