From 7baef59129d2fddda564d6e6bb9cfa1e48cefcb3 Mon Sep 17 00:00:00 2001 From: fruworg Date: Tue, 1 Aug 2023 00:04:36 +0600 Subject: [PATCH] js (ua) --- static/js/agent.js | 58 ++++++++++++++++++++++++++++++++++++++++++---- static/js/ip.js | 1 + 2 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 static/js/ip.js diff --git a/static/js/agent.js b/static/js/agent.js index a5779f6..99d17bd 100644 --- a/static/js/agent.js +++ b/static/js/agent.js @@ -1,4 +1,54 @@ -const userAgent = window.navigator.userAgent; -const platform = window.navigator.platform; -document.getElementById("wb").textContent = "Браузер: " + userAgent; -document.getElementById("os").textContent = "ОС: " + platform; \ No newline at end of file +// Получаем информацию о браузере и операционной системе пользователя +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}`; \ No newline at end of file diff --git a/static/js/ip.js b/static/js/ip.js new file mode 100644 index 0000000..0519ecb --- /dev/null +++ b/static/js/ip.js @@ -0,0 +1 @@ + \ No newline at end of file