-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathDevice.min.js
More file actions
7 lines (7 loc) · 6.5 KB
/
Device.min.js
File metadata and controls
7 lines (7 loc) · 6.5 KB
1
2
3
4
5
6
7
/*!
* Device.js v1.2.3
* Copyright (c) 2021, Emanuel Rojas Vásquez
* MIT License
* https://github.com/erovas/Device.js
*/
!function(s,o){var i="Device";if(s[i])return console.error(i+".js has already been defined");var e=o.createElement("div"),n=screen,t=100,r=o.documentElement,a=navigator,h=/iP(ad Simulator|hone Simulator|od Simulator|ad|hone|od)/i.test(a.platform)||/Mac/i.test(a.userAgent),d=/XiaoMi|MiuiBrowser/i.test(a.userAgent),g="portrait-primary",u="portrait-secondary",c="landscape-primary",l="landscape-secondary";e.style.cssText="height:10vh;width:10vw;border:0;padding:0",o.head.appendChild(e),s[i]={get isFullScreen(){return(innerHeight>=n.height||innerHeight==n.height-1)&&innerWidth==n.width},get isSafeConnection(){var i=location.protocol;return"https:"==i||"file:"==i},get isMobile(){var i=/Android|webOS|iP(hone|ad|od)|BlackBerry|IEMobile|Opera Mini/i.test(a.userAgent),e=n.availHeight==n.height&&n.availWidth==n.width&&outerHeight-innerHeight==0&&!this.isFullScreen;return i||e},get isTablet(){return this.isMobile&&425<Math.min(n.width,n.height)},get isDesktop(){return!this.isMobile},get isLandscape(){if(h){var i=this.clientViewport;return i.width>i.height}return n.width>n.height},get isPortrait(){return!this.isLandscape},get isTouchScreen(){return"ontouchstart"in r||0<this.touchPoints},get isDarkMode(){return s.matchMedia&&s.matchMedia("(prefers-color-scheme: dark)").matches},get isLightMode(){return!this.isDarkMode},get resolution(){var i=this.pixelRatio,e=this.screenViewport;return{width:e.width*i|0,height:e.height*i|0}},get screenViewport(){return this.isMobile&&this.isLandscape&&h?{width:n.height,height:n.width}:{width:n.width,height:n.height}},get innerViewport(){return this.isMobile?d?this.outerViewport:{width:Math.round(10*parseFloat(getComputedStyle(e).width)),height:Math.round(10*parseFloat(getComputedStyle(e).height))}:{width:innerWidth,height:innerHeight}},get outerViewport(){return{width:outerWidth,height:outerHeight}},get clientViewport(){return{width:r.clientWidth,height:r.clientHeight}},get availViewport(){return this.isMobile&&this.isLandscape&&h?{width:n.availHeight,height:n.availWidth}:{width:n.availWidth,height:n.availHeight}},get vh(){return this.isMobile?this.innerViewport.height/t:innerHeight/t},get vw(){return this.isMobile?this.innerViewport.width/t:innerWidth/t},get addressBar(){var i=this,e=i.isFullScreen,t=i.innerViewport;if(i.isMobile){var r=d||h||/Firefox/i.test(a.userAgent)?t.height-innerHeight:t.height-outerHeight;return{width:i.isLandscape&&h?n.height:n.width,height:e?0:r}}r=n.availHeight,r=outerHeight>r?r:outerHeight;return{width:t.width,height:e?0:r-innerHeight}},get scrollBar(){var i=this.isMobile;return{X:{width:innerWidth,height:i?0:innerHeight-r.clientHeight,position:r.scrollLeft,maxPosition:r.scrollWidth-r.clientWidth},Y:{width:i?0:innerWidth-r.clientWidth,height:innerHeight,position:r.scrollTop,maxPosition:r.scrollHeight-r.clientHeight}}},get orientation(){if(n.orientation)return n.orientation;var i=s.orientation,e=this.isMobile,t={};return void 0!==i?(0===(t.angle=i)?t.type=e?g:c:90===i?t.type=e?c:g:180===i?t.type=e?u:l:(t.type=e?l:u,t.angle=270),t):void 0!==(i=n.msOrientation||n.mozOrientation)?(t.type=i,t.angle=i===g?270:i===u?90:i===c?0:180,t):this.isPortrait?{angle:e?0:90,type:g}:{angle:e?90:0,type:c}},get pixelRatio(){return s.devicePixelRatio||1},get workers(){return a.hardwareConcurrency||(h?4:2)},get touchPoints(){return a.maxTouchPoints||a.msMaxTouchPoints||0},get CPU(){return/WOW64|Win64/i.test(a.userAgent)?64:32},get OS(){var i,e=a.userAgent,t="Windows",r="Mac",n="unknown",s="-",o=[{s:t+" 10",r:/(Windows 10.0|Windows NT 10.0)/},{s:t+" 8.1",r:/(Windows 8.1|Windows NT 6.3)/},{s:t+" 8",r:/(Windows 8|Windows NT 6.2)/},{s:t+" 7",r:/(Windows 7|Windows NT 6.1)/},{s:t+" Vista",r:/Windows NT 6.0/},{s:t+" Server 2003",r:/Windows NT 5.2/},{s:t+" XP",r:/(Windows NT 5.1|Windows XP)/},{s:t+" 2000",r:/(Windows NT 5.0|Windows 2000)/},{s:t+" ME",r:/(Win 9x 4.90|Windows ME)/},{s:t+" 98",r:/(Windows 98|Win98)/},{s:t+" 95",r:/(Windows 95|Win95|Windows_95)/},{s:t+" NT 4.0",r:/(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/},{s:t+" CE",r:/Windows CE/},{s:t+" 3.11",r:/Win16/},{s:"Android",r:/Android/},{s:"Open BSD",r:/OpenBSD/},{s:"Sun OS",r:/SunOS/},{s:"Chrome OS",r:/CrOS/},{s:"Linux",r:/(Linux|X11(?!.*CrOS))/},{s:"iOS",r:/(iP(hone|ad|od))/},{s:r+" OS X",r:/Mac OS X/},{s:r+" OS",r:/(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/},{s:"QNX",r:/QNX/},{s:"UNIX",r:/UNIX/},{s:"BeOS",r:/BeOS/},{s:"OS/2",r:/OS\/2/},{s:"Search Bot",r:/(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/}];for(i in o){var h=o[i];if(h.r.test(e)){n=h.s;break}}switch(/Windows/.test(n)&&(s=/Windows (.*)/.exec(n)[1],n="Windows"),n){case r+" OS":case r+" OS X":case"Android":s=/(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([\.\_\d]+)/.exec(e)[1];break;case"iOS":s=(s=/OS (\d+)_(\d+)_?(\d+)?/.exec(a.appVersion))[1]+"."+s[2]+"."+(0|s[3])}return{name:n,version:s}},get browser(){var i,e=a.userAgent,t="Unknown",r="0.0.0",n=0;return this.isMobile&&h?-1<(i=e.indexOf("OPT"))?(t="Opera",r=e.substring(i+4)):-1<(i=e.indexOf("FxiOS"))?(t="Firefox",r=e.substring(i+6)):-1<(i=e.indexOf("EdgiOS"))?(t="Edge",r=e.substring(i+7)):-1<(i=e.indexOf("CriOS"))?(t="Chrome",r=e.substring(i+6)):-1<(i=e.indexOf("Version"))&&(t="Safari",r=e.substring(i+8)):s.chrome?-1<(i=e.indexOf("EdgA"))?(t="Edge",r=e.substring(i+5)):-1<(i=e.indexOf("Edg"))?(t="Edge",r=e.substring(i+4)):s.opr?(t="Opera",r=e.substring(e.indexOf("OPR")+4)):-1<(i=e.indexOf("Chrome"))&&(t="Chrome",r=e.substring(i+7)):s.opr||s.opera?(t="Opera",r=e.substring(e.indexOf("Opera")+6),-1<(i=e.indexOf("Version"))&&(r=e.substring(i+8))):o.documentMode?(t="Internet Explorer",r=-1<(i=e.indexOf("MSIE"))?e.substring(i+5):e.substring(e.indexOf("rv:")+3)):s.StyleMedia?(t="Edge Legacy",r=e.substring(e.indexOf("Edge")+5)):"undefined"!=typeof InstallTrigger?(t="Firefox",r=e.substring(e.indexOf("Firefox")+8)):-1<(i=e.indexOf("MiuiBrowser"))?(t="Mi Browser",r=e.substring(i+12)):-1<(i=e.indexOf("Mint Browser"))?(t="Mint Browser",r=e.substring(i+13)):!/constructor/i.test(s.HTMLElement)&&"[object SafariRemoteNotification]"!==(!s.safari||"undefined"!=typeof safari&&s.safari.pushNotification).toString()||(t="Safari",r=e.substring(e.indexOf("Safari")+7),-1<(i=e.indexOf("Version"))&&(r=e.substring(i+8))),-1<(i=r.indexOf(";"))&&(r=r.substring(0,i)),-1<(i=r.indexOf(" "))&&(r=r.substring(0,i)),-1<(i=r.indexOf(")"))&&(r=r.substring(0,i)),n=parseInt(""+r,10),isNaN(n)&&(r=+parseFloat(a.appVersion),n=parseInt(a.appVersion,10)),{name:t,version:r,major:n}}}}(window,document);