-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOS-Detect.min.js
1 lines (1 loc) · 5.06 KB
/
OS-Detect.min.js
1
String.prototype.replaceAll||(String.prototype.replaceAll=function(a,b){return a instanceof RegExp?this.replace(a,b):this.replace(new RegExp(a,"g"),b)}),window.osd={},window.osd.detectOS=async function(a){function b(a,b){return a.split(b)[1].split(".")[0].trim()||""}function c(a){const c=["Opera/","OPR/"];for(const d of c)if(a.includes(d))return`Opera ${b(a,d)}`;return""}function d(a){return a.includes("Edg")||a.includes("Edge")?a.includes("Ocean/")?b(a,"Ocean/"):a.includes("Edg/")?`${b(a,"Edg/")}`:`${b(a,"Edge/")}`:a.includes("BracketBrowser/")?a.split("BracketBrowser/")[1].split(" ")[0].trim()||"":a.includes("Puffin")?b(a,"Puffin/"):a.includes("CriOS")?b(a,"CriOS/"):a.includes("CrOS")?b(a,"Chrome/"):a.includes("Chromium")?b(a,"Chromium/"):b(a,"Chrome/")}const e=navigator.userAgent;let f=OS=Type=ConsoleType=version="Unknown",g=IOS=win11detect=debug=!1;"undefined"==typeof a?a={debug:!1}:"undefined"!=typeof a.debug&&(debug=a.debug),g=!!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(e);const{browserName:h,browserVersion:i}=function e(a){let g="",h="";return a.includes("Silk/")?(g="SilkBrowser",h=b(a,"Silk/")):a.includes("UCBrowser/")?(g="UCBrowser",h=b(a,"UCBrowser/")):a.includes("OculusBrowser/")?(g="OculusBrowser",h=b(a,"OculusBrowser/")):a.includes("SamsungBrowser/")?(g="SamsungBrowser",h=b(a,"SamsungBrowser/")):a.includes("Opera")||a.includes("OPR")?(g="Opera",h=c(a)):a.includes("Firefox/")?(g="Firefox",h=b(a,"Firefox/")):a.includes("FxiOS")?(g="Firefox",h=b(a,"FxiOS/")):a.includes("trident/")?(g="Internet Explorer",h=b(a,"trident/")):"PlayStation OS"==f?(g=`PlayStation ${version} Browser`,ConsoleType="PlayStation"):a.includes("Chrom")?(g=a.includes("Edg")||a.includes("Edge")?a.includes("Ocean")?"OceanBrowser (EdgeWebview2)":"Edge (chromium)":a.includes("BracketBrowser")||a.includes("BracketBrowser")?"BracketBrowser (electron)":a.includes("Chromium")?"Chromium":"Chrome",h=d(a)):a.includes("CriOS")?(g="Chrome",h=d(a)):a.includes("CrOS")?(g="Chrome",h=d(a)):a.includes("Safari")&&(g="Safari",h=b(a,"Safari/")),{browserName:g,browserVersion:h}}(e);if(e.includes("Win")){if(e.includes("Windows Phone")?(versionstring=e.split("Phone")[1].split(";")[0].trim(),f=`Windows Phone OS`,Type="WindowsPhone"):(versionstring=e.split("NT")[1].split(";")[0].trim(),f=`Windows OS`,Type="Windows"),"undefined"==typeof navigator.userAgentData){var j="https:"===location.protocol?"https":"http";"https"==j?console.warn("Unable to detect for windows 11 and later, browser does not support navigator.userAgentData"):console.warn("Unable to detect for windows 11 and later, navigator.userAgentData requires the page to be hosted over HTTPS which this page is not.")}else{win11detect=!0;try{const a=await navigator.userAgentData.getHighEntropyValues(["platformVersion"]);if("Windows"===navigator.userAgentData.platform){var k=parseInt(a.platformVersion.split(".")[0]);13<=k&&(versionstring="11.0")}}catch(a){console.warn("Unable to detect for windows 11 and later:",a.message)}}version="11.0"===versionstring?"11":"10.0"===versionstring?"10":"6.3"===versionstring?"8.1":"6.2"===versionstring?"8":"6.1"===versionstring?"7":"6.0"===versionstring?"vista":"5.2"===versionstring||"5.1"===versionstring?"XP":"5.0"===versionstring?"2000":"4.0"===versionstring?"NT 4.0":"3.51"===versionstring?"NT 3.51":"3.5"===versionstring?"NT 3.5":"3.1"===versionstring?"NT 3.1":"unknown"}return e.includes("Mac")&&(e.includes("iPad")?(f=`iPad OS`,IOS=!0,Type="Mobile"):e.includes("iPhone")?(f=`iPhone OS`,IOS=!0,Type="Mobile"):e.includes("iPod")?(f=`iPod OS`,IOS=!0,Type="Mobile"):(f=`Mac OS`,Type="Mac",e.includes("OS X")?version=e.split("OS X")[1].split(")")[0].trim().replace("OS X","").replace(" ","").split("_").join("."):e.includes("Mac_PowerPC")&&(version=`9`)),!0==IOS&&(Type="IOS",e.includes("iPhone")||e.includes("iPad")||e.includes("iPod")?(version=e.split("OS")[1].split("Mac")[0].trim().replace("like","").replace(" ","").split("_").join("."),IOS=!0):navigator.appVersion.match("iPhone OS")||navigator.appVersion.match("iPad OS")||navigator.appVersion.match("iPod OS")?(version=e.split("OS")[1].split("like")[0].trim().replace("_","."),IOS=!0):e.includes("Version/")&&(version=e.split("Version/")[1].split("Gecko")[0].split("Mobile/")[0].trim()))),e.match(/BlackBerry|BB|PlayBook/i)&&(f=`BlackBerry OS`),e.includes("Linux")&&(/Android/.test(e)?(version=e.split("Android")[1].split(";")[0].trim(),f="Android OS",Type="Android"):e.includes("Quest")?(f="Quest OS (android)",Type="AndroidVR"):(f="Linux OS",Type="Linux")),e.includes("CrOS")&&(f="Chrome OS",Type="Linux"),e.includes("ubuntu")&&(f="Ubuntu OS",Type="Linux"),e.includes("PlayStation")&&(version=e.split("PlayStation")[1].split(".")[0].trim().replace("PlayStation","").replace(" ",""),f="PlayStation OS",Type="PlayStation"),OS={name:f,browser:{name:h,version:i,combined:`${h} ${i}`},userAgent:e,version:version,isIOS:IOS,isMobile:g,type:Type,win11support:win11detect},"function"==typeof osd.bi&&(OS.browser.icon=osd.bi(OS.browser.name)),!0==debug&&(console.info("Debug set to true, printing OS info"),console.log(`OS: ${OS.name}\nBrowser: ${OS.browser.combined}\nUserAgent: ${OS.userAgent}`)),OS};