Skip to content

Commit

Permalink
New implementation of OS/Platform data query
Browse files Browse the repository at this point in the history
  • Loading branch information
ddasutein committed Oct 24, 2021
1 parent 6944b85 commit 1d539cb
Showing 1 changed file with 61 additions and 75 deletions.
136 changes: 61 additions & 75 deletions js/Configuration/QuerySystemInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** MIT License
*
* Copyright (c) 2020 Dasutein
* Copyright (c) 2021 Dasutein
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
Expand All @@ -10,9 +10,23 @@
*
* See more: https://github.com/ddasutein/AutoRename/blob/master/LICENSE
*
* REFERENCES:
*
* Detecting Microsoft Edge from your website (also includes info to query Windows 11 devices)
* https://docs.microsoft.com/en-us/microsoft-edge/web-platform/user-agent-guidance
*
*/

function GetOperatingSystem(){
function GetSystemInfo() {

function isChromium() {
for (brand_version_pair of navigator.userAgentData.brands) {
if (brand_version_pair.brand == "Chromium") {
return true;
}
}
return false;
}

let os = null;
let appVersion = navigator.appVersion;
Expand All @@ -22,85 +36,57 @@ function GetOperatingSystem(){
let windows_nt_6_3 = "Windows NT 6.3";
let macOS = "Macintosh";
let chromeOS = "CrOS";
let browserVersion = "";

if (appVersion.includes(windows_nt_10)){
os = "Windows 10"
}
else if (appVersion.includes(windows_nt_6_1)){
os = "Windows 7"
}
else if (appVersion.includes(windows_nt_6_2)){
os = "Windows 8"
}
else if (appVersion.includes(windows_nt_6_3)){
os = "Windows 8.1"
}
else if (appVersion.includes(macOS)){
let mac_version = appVersion.substring(31, appVersion.lastIndexOf("OS X") + 12);
os = "macOS " + mac_version.replace(/_/gi, ".");
}
else if (appVersion.includes(chromeOS)){
let chrome_os_version = appVersion.substring(31, appVersion.lastIndexOf("CrOS") + 5);
os = "Chrome OS " + chrome_os_version;
}
else {
// If running on unsupported Operating Systems
os = appVersion;
}
if (isChromium() == true) {
navigator.userAgentData.getHighEntropyValues(
["architecture", "model", "platform", "platformVersion", "uaFullVersion"])
.then(ua => {

document.getElementById("system_information_os_value").innerHTML = os;
}
if (!!ua.uaFullVersion){
browserVersion = `(${ua.uaFullVersion})`;
}

function GetPlatform(){
const platform = navigator.platform;
document.getElementById("system_information_platform_value").innerHTML = platform;
}
switch (ua.platformVersion){
case "14.0.0":
os = "Windows 11";
break;

case "10.0.0":
os = "Windows 10";
break;

function GetCurrentLanguage(){
default:
// Fallback to legacy OS query
if (appVersion.includes(windows_nt_10)) {
os = "Windows 10"
} else if (appVersion.includes(windows_nt_6_1)) {
os = "Windows 7"
} else if (appVersion.includes(windows_nt_6_2)) {
os = "Windows 8"
} else if (appVersion.includes(windows_nt_6_3)) {
os = "Windows 8.1"
} else if (appVersion.includes(macOS)) {
let mac_version = appVersion.substring(31, appVersion.lastIndexOf("OS X") + 12);
os = "macOS " + mac_version.replace(/_/gi, ".");
} else if (appVersion.includes(chromeOS)) {
let chrome_os_version = appVersion.substring(31, appVersion.lastIndexOf("CrOS") + 5);
os = "Chrome OS " + chrome_os_version;
} else {
// If running on unsupported Operating Systems
os = appVersion;
}
break;
}

let lang = "";
switch (navigator.language){
case ar:
lang = "Arabic";
break;
case am:
lang = "Amharic";
break;
case bg:
lang = "Bulgarian";
break;
case bn:
lang = "Bengali";
break;
case ca:
lang = "Catalan";
break;
case cs:
lang = "Czech";
break;
case da:
lang = "Danish";
break;
case de:
lang = "German";
break;
case el:
lang = "Greek";
break;
case en:
lang = "English";
break;
case en_GB:
lang = "English (Great Britain)";
break;
case en_US:
lang = "English (United States)";
break;
document.getElementById("system_information_platform_value").innerHTML = ua.platform;
document.getElementById("system_information_os_value").innerHTML = os;
document.getElementById("system_information_browser_value").innerHTML = `${ua.brands[0].brand} ${browserVersion}`;

});
}
document.getElementById("about_lang_info").innerHTML = lang;


}

document.addEventListener("DOMContentLoaded", GetOperatingSystem());
document.addEventListener("DOMContentLoaded", GetPlatform());
document.addEventListener("DOMContentLoaded", GetCurrentLanguage());
document.addEventListener("DOMContentLoaded", GetSystemInfo());

0 comments on commit 1d539cb

Please sign in to comment.