-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBrowserDetection.min.js
1 lines (1 loc) · 9.06 KB
/
BrowserDetection.min.js
1
function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i<t.length;i++){var o=t[i];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"==_typeof(e)?e:e+""}function _toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0===i)return("string"===t?String:Number)(e);i=i.call(e,t||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}module.exports=(()=>_createClass(function e(t,i,o){_classCallCheck(this,e),this._name="BrowserDetection.js",this._w=t=void 0===t?{}:t,this._userAgent=i=void 0===i?"":i,this._appName=void 0===o?"":o,this._browserName="",this._isMobile=!1,this._osType="",this._isIE=!1,this._isEdge=!1,this._ieVersion=100,this._lang="en",this._langCode="en-us"},[{key:"isMobile",value:function(){return this._isMobile}},{key:"isIE",value:function(){return this._isIE}},{key:"isEdge",value:function(){return this._isEdge}},{key:"getAppName",value:function(){return this._appName}},{key:"getBrowserName",value:function(){return this._browserName}},{key:"getOsType",value:function(){return this._osType}},{key:"getIeVersion",value:function(){return this._ieVersion}},{key:"getLanguage",value:function(){return this._lang}},{key:"getLanguageCode",value:function(){return this._langCode}},{key:"getUserAgent",value:function(){return this._userAgent}},{key:"getUrlComplete",value:function(){return void 0!==this._w.location&&this._w.location.href||""}},{key:"getUrlHash",value:function(){return void 0!==this._w.location&&this._w.location.hash||""}},{key:"getUrlHost",value:function(){return void 0!==this._w.location&&this._w.location.host||""}},{key:"getUrlHostname",value:function(){return void 0!==this._w.location&&this._w.location.hostname||""}},{key:"getUrlOrigin",value:function(){return void 0!==this._w.location&&this._w.location.origin||""}},{key:"getUrlPathname",value:function(){return void 0!==this._w.location&&this._w.location.pathname||""}},{key:"getUrlPort",value:function(){return void 0!==this._w.location&&this._w.location.port||""}},{key:"getUrlProtocol",value:function(){return void 0!==this._w.location&&this._w.location.protocol||""}},{key:"getUrlSearch",value:function(){return void 0!==this._w.location&&this._w.location.search||""}},{key:"log",value:function(){this.logWindow(),this.logUrl()}},{key:"logWindow",value:function(){console.log(this._name+" | Mobile Device",this.isMobile()),console.log(this._name+" | OS Type",this.getOsType()),console.log(this._name+" | Browser",this.getBrowserName()),console.log(this._name+" | MS IE",this.isIE()),console.log(this._name+" | MS Edge",this.isEdge()),console.log(this._name+" | Language",this.getLanguage()),console.log(this._name+" | Language Code",this.getLanguageCode())}},{key:"logUrl",value:function(){console.log(this._name+" | Complete",this.getUrlComplete()),console.log(this._name+" | Hash",this.getUrlHash()),console.log(this._name+" | Origin",this.getUrlOrigin()),console.log(this._name+" | Search",this.getUrlSearch()),console.log(this._name+" | Host",this.getUrlHost()),console.log(this._name+" | Pathname",this.getUrlPathname()),console.log(this._name+" | Hostname",this.getUrlHostname()),console.log(this._name+" | Port",this.getUrlPort()),console.log(this._name+" | Protocol",this.getUrlProtocol())}},{key:"checkAll",value:function(){this.consoleWrapper(),this.checkOperationSystem(),this.checkLanguage(),this.checkBrowserInternetExplorer(),this.checkAllBrowser()}},{key:"consoleWrapper",value:function(){for(var e,t=["assert","clear","count","debug","dir","dirxml","error","exception","group","groupCollapsed","groupEnd","info","log","markTimeline","profile","profileEnd","table","time","timeEnd","timeline","timelineEnd","timeStamp","trace","warn"],i=t.length,o=this._w.console=this._w.console||{};i--;)o[e=t[i]]||(o[e]=function(){})}},{key:"checkOperationSystem",value:function(){this._isMobile=this.checkAllMobiles(),this._osType="",this.checkMobileDeviceAndroid()&&(this._osType="Android"),this.checkMobileDeviceBlackBerry()&&(this._osType="Black Berry"),this.checkMobileDeviceiOS()&&(this._osType="Apple"),this.checkMobileDeviceOpera()&&(this._osType="Opera"),this.checkMobileDeviceWindows()&&(this._osType="Windows"),""!==this._osType?this._isMobile=!0:(this.checkDesktopDeviceApple()&&(this._osType="Apple"),this.checkDesktopDeviceLinux()&&(this._osType="Linux"),this.checkDesktopDeviceWindows()&&(this._osType="Windows"))}},{key:"checkAllMobiles",value:function(){return/(tablet|ipad|playbook|silk|android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(this._userAgent)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(this._userAgent.substr(0,4))}},{key:"checkMobileDeviceAndroid",value:function(){return!!this._userAgent.match(/Android/i)}},{key:"checkMobileDeviceBlackBerry",value:function(){return!!this._userAgent.match(/BlackBerry/i)}},{key:"checkMobileDeviceiOS",value:function(){return!!this._userAgent.match(/iPhone|iPad|iPod/i)}},{key:"checkMobileDeviceOpera",value:function(){return!!this._userAgent.match(/Opera Mini|Opera Mobi/i)}},{key:"checkMobileDeviceWindows",value:function(){return!!this._userAgent.match(/IEMobile|Windows Phone/i)}},{key:"checkDesktopDeviceApple",value:function(){return!!this._userAgent.match(/Macintosh/i)}},{key:"checkDesktopDeviceLinux",value:function(){return!!this._userAgent.match(/Linux/i)}},{key:"checkDesktopDeviceWindows",value:function(){return!!this._userAgent.match(/Windows NT/i)}},{key:"checkLanguage",value:function(){try{var e=this;t=this._w.navigator.userLanguage||this._w.navigator.language,e._lang=t.substr(0,2).toLowerCase(),e._langCode=t.toLowerCase()}catch(e){this._lang="en",this._langCode="en-us",this._w.console.log(e)}var t}},{key:"checkAllBrowser",value:function(){this.isIE()||this.isEdge()?this._browserName="IE":this.checkBrowserChrome()?this._browserName="Chrome":this.checkBrowserFirefox()?this._browserName="Firefox":this.checkBrowserOpera()?this._browserName="Opera":this.checkBrowserSafari()&&(this._browserName="Safari")}},{key:"checkBrowserChrome",value:function(){return!!this._userAgent.match(/Chrome/i)}},{key:"checkBrowserFirefox",value:function(){return!!this._userAgent.match(/Firefox/i)}},{key:"checkBrowserOpera",value:function(){return!!this._userAgent.match(/Opera/i)}},{key:"checkBrowserSafari",value:function(){return!!this._userAgent.match(/Safari/i)}},{key:"checkBrowserInternetExplorer",value:function(){var t,i=this;function e(e){if(null!==e.exec(i._userAgent)){i._isIE=!0,i._ieVersion=parseInt(RegExp.$1);try{(t=i._w.document.getElementsByTagName("html")[0]).className=t.className||"",t.className+=" ie"+i._ieVersion}catch(e){}return 1}}"Microsoft Internet Explorer"===this._appName?e(new RegExp("MSIE ([0-9][.0-9])")):(e(new RegExp("Trident/.*rv:([0-9][.0-9])")),e(new RegExp("Edge/([0-9][.0-9])"))&&(i._isEdge=!0))}}]))();