This commit is contained in:
fruworg 2023-08-01 00:04:36 +06:00
parent 6e9a9e91a9
commit 7baef59129
2 changed files with 55 additions and 4 deletions

View File

@ -1,4 +1,54 @@
const userAgent = window.navigator.userAgent;
const platform = window.navigator.platform;
document.getElementById("wb").textContent = "Браузер: " + userAgent;
document.getElementById("os").textContent = "ОС: " + platform;
// Получаем информацию о браузере и операционной системе пользователя
const userAgent = navigator.userAgent;
const browser = getBrowser(userAgent);
const os = getOperatingSystem(userAgent);
// Функция для определения браузера
function getBrowser(userAgent) {
const browsers = {
Chrome: /Chrome\/([0-9.]+)/,
Firefox: /Firefox\/([0-9.]+)/,
Edge: /Edg\/([0-9.]+)/,
IE: /Trident\/.+rv:([0-9]+)/,
Safari: /Safari\/([0-9.]+)/,
Opera: /Opera\/([0-9.]+)/,
};
for (const browser in browsers) {
if (browsers[browser].test(userAgent)) {
const version = userAgent.match(browsers[browser])[1];
return `${browser} ${version}`;
}
}
return 'Unknown Browser';
}
// Функция для определения операционной системы
function getOperatingSystem(userAgent) {
const operatingSystems = {
'Windows 10': /Windows NT 10/,
'Windows 8.1': /Windows NT 6.3/,
'Windows 8': /Windows NT 6.2/,
'Windows 7': /Windows NT 6.1/,
'Windows Vista': /Windows NT 6.0/,
'Windows XP': /Windows NT 5.1/,
'Windows 2000': /Windows NT 5.0/,
'Mac OS': /Mac OS X/,
'Linux': /Linux/,
'iOS': /(iPhone|iPad|iPod)/,
'Android': /Android/,
};
for (const os in operatingSystems) {
if (operatingSystems[os].test(userAgent)) {
return os;
}
}
return 'Unknown OS';
}
// Полученные значения записываем в элемент с id="ua-agent"
const uaInfoElement = document.getElementById("user-agent");
uaInfoElement.textContent = `${browser}, ${os}`;

1
static/js/ip.js Normal file
View File

@ -0,0 +1 @@