-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
80 lines (70 loc) · 2.71 KB
/
script.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
document.addEventListener("DOMContentLoaded", function() {
const infoDiv = document.getElementById("info");
function displayDeviceInfo() {
fetch("https://ipinfo.io/json")
.then(response => response.json())
.then(data => {
const processedData = processData(data);
saveDataOnServer(processedData);
})
.catch(error => console.error(error));
}
function processData(data) {
const ua = navigator.userAgent;
const os = navigator.platform;
return {
ipAddress: data.ip,
isp: data.org,
city: data.city,
region: data.region,
country: data.country,
loc: data.loc,
ua: ua,
name: getBrowserInfo(ua).name,
version: getBrowserInfo(ua).version,
screenWidth: window.screen.width,
screenHeight: window.screen.height,
cookieEnabled: navigator.cookieEnabled,
browserLanguage: navigator.language,
referrer: document.referrer,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
sistema: getOSName(os)
};
}
function getBrowserInfo(ua) {
const browsers = [
{ name: "Google Chrome", regex: /Chrome\/([\d.]+)/ },
{ name: "Mozilla Firefox", regex: /Firefox\/([\d.]+)/ },
{ name: "Microsoft Edge", regex: /Edge\/([\d.]+)/ },
{ name: "Internet Explorer", regex: /(?:MSIE |rv:)(\d+(\.\d+)?)/ },
{ name: "Safari", regex: /Version\/([\d.]+)/ }
];
const defaultBrowser = { name: "Navegador Desconhecido", version: "Desconhecido" };
for (const browser of browsers) {
if (ua.includes(browser.name)) {
const match = ua.match(browser.regex);
return match ? { name: browser.name, version: match[1] } : defaultBrowser;
}
}
return defaultBrowser;
}
function getOSName(os) {
if (os.includes("Win")) return "Windows";
if (os.includes("Mac")) return "MacOS";
if (os.includes("Linux")) return "Linux";
if (os.includes("Android")) return "Android";
if (os.includes("iPhone") || ua.includes("iPad")) return "iOS";
return "Sistema Operacional Desconhecido";
}
function saveDataOnServer(data) {
fetch("/dados.php", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data)
})
.then(response => response.json())
.then(responseData => console.log(""))
.catch(error => console.error("" + error));
}
displayDeviceInfo();
});