forked from bowser-js/bowser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bowser.js
155 lines (146 loc) · 5.42 KB
/
bowser.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*!
* Bowser - a browser detector
* https://github.com/ded/bowser
* MIT License | (c) Dustin Diaz 2013
*/
!function (name, definition) {
if (typeof module != 'undefined' && module.exports) module.exports['browser'] = definition()
else if (typeof define == 'function') define(definition)
else this[name] = definition()
}('bowser', function () {
/**
* navigator.userAgent =>
* Chrome: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_7) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.57 Safari/534.24"
* Opera: "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.7; U; en) Presto/2.7.62 Version/11.01"
* Safari: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
* IE: "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C)"
* IE>=11: "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; Media Center PC 6.0; rv:11.0) like Gecko"
* Firefox: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0) Gecko/20100101 Firefox/4.0"
* iPhone: "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5"
* iPad: "Mozilla/5.0 (iPad; U; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5",
* Android: "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; T-Mobile G2 Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"
* Touchpad: "Mozilla/5.0 (hp-tabled;Linux;hpwOS/3.0.5; U; en-US)) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0"
* PhantomJS: "Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34"
* Amazon Silk: "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.22.153_10033210) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true"
*/
var ua = navigator.userAgent
, t = true
, ie = /(msie|trident)/i.test(ua)
, chrome = /chrome|crios/i.test(ua)
, phantom = /phantom/i.test(ua)
, iphone = /iphone/i.test(ua)
, ipad = /ipad/i.test(ua)
, touchpad = /touchpad/i.test(ua)
, silk = /silk/i.test(ua)
, safari = /safari/i.test(ua) && !chrome && !phantom && !silk
, android = /android/i.test(ua)
, opera = /opera/i.test(ua) || /opr/i.test(ua)
, firefox = /firefox/i.test(ua)
, gecko = /gecko\//i.test(ua)
, seamonkey = /seamonkey\//i.test(ua)
, webkitVersion = /version\/(\d+(\.\d+)?)/i
, firefoxVersion = /firefox\/(\d+(\.\d+)?)/i
, o
function detect() {
if (ie) return {
name: 'Internet Explorer'
, msie: t
, version: ua.match(/(msie |rv:)(\d+(\.\d+)?)/i)[2]
}
if (opera) return {
name: 'Opera'
, opera: t
, version: ua.match(webkitVersion) ? ua.match(webkitVersion)[1] : ua.match(/opr\/(\d+(\.\d+)?)/i)[1]
}
if (chrome) return {
name: 'Chrome'
, webkit: t
, chrome: t
, version: ua.match(/(?:chrome|crios)\/(\d+(\.\d+)?)/i)[1]
}
if (phantom) return {
name: 'PhantomJS'
, webkit: t
, phantom: t
, version: ua.match(/phantomjs\/(\d+(\.\d+)+)/i)[1]
}
if (touchpad) return {
name: 'TouchPad'
, webkit: t
, touchpad: t
, version : ua.match(/touchpad\/(\d+(\.\d+)?)/i)[1]
}
if (silk) return {
name: 'Amazon Silk'
, webkit: t
, android: t
, mobile: t
, version : ua.match(/silk\/(\d+(\.\d+)?)/i)[1]
}
if (iphone || ipad) {
o = {
name : iphone ? 'iPhone' : 'iPad'
, webkit: t
, mobile: t
, ios: t
, iphone: iphone
, ipad: ipad
}
// WTF: version is not part of user agent in web apps
if (webkitVersion.test(ua)) {
o.version = ua.match(webkitVersion)[1]
}
return o
}
if (android) return {
name: 'Android'
, webkit: t
, android: t
, mobile: t
, version: (ua.match(webkitVersion) || ua.match(firefoxVersion))[1]
}
if (safari) return {
name: 'Safari'
, webkit: t
, safari: t
, version: ua.match(webkitVersion)[1]
}
if (gecko) {
o = {
name: 'Gecko'
, gecko: t
, mozilla: t
, version: ua.match(firefoxVersion)[1]
}
if (firefox) {
o.name = 'Firefox';
o.firefox = t;
}
return o
}
if (seamonkey) return {
name: 'SeaMonkey'
, seamonkey: t
, version: ua.match(/seamonkey\/(\d+(\.\d+)?)/i)[1]
}
return {}
}
var bowser = detect()
// Graded Browser Support
// http://developer.yahoo.com/yui/articles/gbs
if ((bowser.msie && bowser.version >= 8) ||
(bowser.chrome && bowser.version >= 10) ||
(bowser.firefox && bowser.version >= 4.0) ||
(bowser.safari && bowser.version >= 5) ||
(bowser.opera && bowser.version >= 10.0)) {
bowser.a = t;
}
else if ((bowser.msie && bowser.version < 8) ||
(bowser.chrome && bowser.version < 10) ||
(bowser.firefox && bowser.version < 4.0) ||
(bowser.safari && bowser.version < 5) ||
(bowser.opera && bowser.version < 10.0)) {
bowser.c = t
} else bowser.x = t
return bowser
});