forked from fkei/sua.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsua.min.js
6 lines (6 loc) · 4 KB
/
sua.min.js
1
2
3
4
5
6
/**
* @name sua.min.js
* @version 0.9.8
* @overview Simple user agent detection library.
*/
!function(i){"use strict";var s={VERSION:"0.9.8"};s.setup=function(s){if(!s&&i&&i.navigator&&i.navigator.userAgent&&(s=i.navigator.userAgent),!s)throw new Error("useragent setup error. useragent not found.");if(this.webkit=s.match(/WebKit\/([\d.]+)/),this.android=s.match(/(Android)\s+([\d.]+)/),this.android23=s.match(/(Android)\s+(2\.3)([\d.]+)/),this.android4=s.match(/(Android)\s+(4)([\d.]+)/),this.android5=s.match(/(Android)\s+(5)([\d.]+)/),this.ipad=s.match(/(iPad).*OS\s([\d_]+)/),this.iphone=!this.ipad&&s.match(/(iPhone\sOS)\s([\d_]+)/),this.webos=s.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),this.touchpad=this.webos&&s.match(/TouchPad/),this.kindle=s.match(/(Kindle)/),this.silk=s.match(/(Silk)/),this.blackberry=s.match(/(BlackBerry).*/),this.bb10=s.match(/(BB10).*Version\/([\d.]+)/),this.rimtabletos=s.match(/(RIM\sTablet\sOS)\s([\d.]+)/),this.playbook=s.match(/PlayBook/),this.chrome=s.match(/Chrome\/([\d.]+)/)||s.match(/CriOS\/([\d.]+)/),this.firefox=s.match(/Firefox\/([\d.]+)/),this.wii=s.match(/Nintendo (Wii);/),this.ds=s.match(/Nintendo (DS|3DS|DSi);/),this.ps3=s.match(/PLAYSTATION 3/),this.psp=s.match(/(PlayStation Portable)/),this.psvita=s.match(/(PlayStation Vita)/),this.windowsphone=s.match(/(Windows Phone |Windows Phone OS )([\d.]+)/),this.safari=s.match(/(Version)\/([0-9\.]+).*Safari\/([0-9\.]+)/),this.trident=s.match(/Trident\/([\d\.]+)/),this.xbox=s.match(/Xbox/),this.ie=!!(s.indexOf("MSIE")>=0||s.indexOf("Trident")>=0),this.iphone5=!("undefined"!=typeof module&&module.exports)&&this.iphone&&screen&&320===screen.width&&568===screen.height,this.iphone3=this.iphone&&1===i.devicePixelRatio?!0:!1,this.browser={locale:void 0,lang:void 0,country:void 0},this.os={},this.webkit&&(this.browser.webkit=!0,this.browser.version=this.webkit[1]),this.trident&&(this.browser.trident=!0,this.browser.version=this.trident[1]),this.android){this.os.android=!0,this.os.version=this.android[2];try{this.browser.locale=s.match(/(Android)\s(.+);\s([^;]+);/)[3],this.browser.lang=this.browser.locale.substring(0,2),this.browser.country=this.browser.locale.substring(3)}catch(t){}}if(this.iphone&&(this.os.ios=this.os.iphone=!0,this.os.version=this.iphone[2].replace(/_/g,".")),this.ipad&&(this.os.ios=this.os.ipad=!0,this.os.version=this.ipad[2].replace(/_/g,".")),this.os.ios){var h=null;this.os.version&&(h=this.os.version.substring(0,1));for(var o=3;10>o;o++)this["ios"+o]=h===""+o}this.webos&&(this.os.webos=!0,this.os.version=this.webos[2]),this.touchpad&&(this.os.touchpad=!0),this.blackberry&&(this.os.blackberry=!0),this.bb10&&(this.os.bb10=!0,this.os.version=this.bb10[2]),this.rimtabletos&&(this.os.rimtabletos=!0,this.os.version=this.rimtabletos[2]),this.playbook&&(this.browser.playbook=!0),this.kindle&&(this.os.kindle=!0),this.silk&&(this.browser.silk=!0),!this.silk&&this.os.android&&s.match(/Kindle Fire/)&&(this.browser.silk=!0),this.chrome&&(this.browser.chrome=!0,this.browser.version=this.chrome[1]),this.firefox&&(this.browser.firefox=!0,this.browser.version=this.firefox[1],s.match(/Android/)&&(this.android=["Android","Android",""])),(this.wii||this.ds)&&(this.os.nintendo=!0),this.windowsphone&&(this.browser.windowsphone=!0,this.browser.version=this.windowsphone[2]),this.safari&&(this.browser.safari=!0,this.browser.version=this.safari[2]),this.ie&&(this.browser.ie=/(MSIE|rv:?)\s?([\d\.]+)/.exec(s),this.windowsphone||(this.browser.version=this.browser.ie?this.browser.ie[2]:"")),this.os.tablet=!!(this.ipad||this.kindle||this.playbook||this.android&&!s.match(/Mobile/)||this.firefox&&s.match(/Tablet/)),this.os.phone=!(this.os.tablet||!(this.android||this.iphone||this.webos||this.blackberry||this.bb10||this.chrome&&s.match(/Android/)||this.chrome&&s.match(/CriOS\/([\d.]+)/)||this.firefox&&s.match(/Mobile/)||this.windowsphone&&s.match(/IEMobile/))),this.mobile=!(!this.os.tablet&&!this.os.phone),this.webview={},s.match(/Twitter/)&&(this.webview.twitter=!0)},"undefined"!=typeof module&&module.exports&&(module.exports=s),i.sua||(i.sua={},i.sua=s)}(this);