mirror of
https://github.com/lancedikson/bowser
synced 2024-10-27 20:34:22 +00:00
combined webos and touchpad as webos with optional touchpad flag, added silk flag for silk browser, expanded documentation
This commit is contained in:
parent
a4014721f2
commit
23e385f884
39
README.md
39
README.md
@ -12,29 +12,32 @@ if (bowser.msie && bowser.version <= 6) {
|
||||
}
|
||||
```
|
||||
|
||||
Detected Browsers[Engines]
|
||||
Flags set for detected Browsers[Engines]
|
||||
-----
|
||||
|
||||
* chrome[webkit]
|
||||
* firefox[gecko]
|
||||
* msie
|
||||
* opera[webkit if >12]
|
||||
* phantomjs[webkit]
|
||||
* safari[webkit]
|
||||
* seamonkey[gecko]
|
||||
* touchpad[webkit]
|
||||
* `chrome`[`webkit`]
|
||||
* `firefox`[`gecko`]
|
||||
* `msie`
|
||||
* Android native browser as `android`[`webkit`]
|
||||
* iOS native browser as `ios`[`webkit`]
|
||||
* `opera`[`webkit` if >12]
|
||||
* `phantomjs`[`webkit`]
|
||||
* `safari`[`webkit`]
|
||||
* `seamonkey`[`gecko`]
|
||||
* BlackBerry native browser as `blackberry`[`webkit`]
|
||||
* WebOS native browser as `webos`[`webkit`]
|
||||
|
||||
Detected mobile operating systems
|
||||
Flags set for detected mobile Operating Systems
|
||||
-----
|
||||
|
||||
* android
|
||||
* windows phone
|
||||
* ios (iphone/ipad/ipod)
|
||||
* blackberry
|
||||
* firefoxos
|
||||
* webos
|
||||
* `android`
|
||||
* Windows Phone as `windowsphone`
|
||||
* `ios` (`iphone`/`ipad`/`ipod`)
|
||||
* `blackberry`
|
||||
* `firefoxos`
|
||||
* `webos`
|
||||
|
||||
Android, iOS and Windows Phone will all report the OS version number if it is contained in the UA string in the `osversion` field. iOS is always reported as `ios` and additionally as `iphone`/`ipad`/`ipod`, whichever one matches best. Windows Phone is reported as `windowsphone`.
|
||||
Android, iOS, Windows Phone, and WebOS will all report the OS version number if it is contained in the UA string in the `osversion` field. iOS is always reported as `ios` and additionally as `iphone`/`ipad`/`ipod`, whichever one matches best. If WebOS device is an HP TouchPad the flag `touchpad` is additionally set.
|
||||
|
||||
All detected mobile OSes are additionally flagged `mobile`.
|
||||
|
||||
@ -44,7 +47,7 @@ Safari, Chrome and some other minor browsers will report that they have `webkit`
|
||||
|
||||
``` js
|
||||
if (bowser.webkit) {
|
||||
// do stuff with safari & chrome
|
||||
// do stuff with safari & chrome & opera & android & blackberry & webos
|
||||
}
|
||||
```
|
||||
|
||||
|
25
bowser.js
25
bowser.js
@ -29,7 +29,6 @@
|
||||
, iphone = /iphone/i.test(ua)
|
||||
, ipad = /ipad/i.test(ua)
|
||||
, ipod = /ipod/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)
|
||||
@ -37,7 +36,7 @@
|
||||
, firefox = /firefox/i.test(ua)
|
||||
, gecko = /gecko\//i.test(ua)
|
||||
, seamonkey = /seamonkey\//i.test(ua)
|
||||
, webos = /webos/i.test(ua)
|
||||
, webos = /(?:web|hpw)os/i.test(ua)
|
||||
, windowsphone = /windows phone/i.test(ua)
|
||||
, blackberry = /blackberry/i.test(ua)
|
||||
, webkitVersion = /version\/(\d+(\.\d+)?)/i
|
||||
@ -95,14 +94,9 @@
|
||||
, phantom: t
|
||||
, version: getVersion(ua, /phantomjs\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
else if (touchpad) o = {
|
||||
name: 'TouchPad'
|
||||
, webkit: t
|
||||
, touchpad: t
|
||||
, version : getVersion(ua, /touchpad\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
else if (silk) o = {
|
||||
name: 'Amazon Silk'
|
||||
, silk: t
|
||||
, webkit: t
|
||||
, android: t
|
||||
, mobile: t
|
||||
@ -134,12 +128,15 @@
|
||||
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
}
|
||||
else if (webos) o = {
|
||||
else if (webos) {
|
||||
o = {
|
||||
name: 'WebOS'
|
||||
, mobile: t
|
||||
, webkit: t
|
||||
, webos: t
|
||||
, version: (getVersion(ua, webkitVersion, 1) || getVersion(ua, /wosbrowser\/(\d+(\.\d+)?)/i, 1))
|
||||
, version: (getVersion(ua, webkitVersion, 1) || getVersion(ua, /w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i, 1))
|
||||
};
|
||||
/touchpad\//i.test(ua) && (o.touchpad = t)
|
||||
}
|
||||
else if (gecko) {
|
||||
o = {
|
||||
@ -186,15 +183,15 @@
|
||||
}
|
||||
} else if (iphone || ipad || ipod) {
|
||||
osVersion = getVersion(ua, /os (\d+([_\s]\d+)*) like mac os x/i, 1);
|
||||
if (osVersion) {
|
||||
o.osversion = osVersion.replace(/[_\s]/g, '.');
|
||||
}
|
||||
osVersion = (osVersion || "").replace(/[_\s]/g, '.');
|
||||
} else if (windowsphone) {
|
||||
osVersion = getVersion(ua, /windows phone (?:os)?\s?(\d+(\.\d+)*)/i, 1);
|
||||
} else if (webos) {
|
||||
osVersion = getVersion(ua, /(?:web|hpw)os\/(\d+(\.\d+)*)/i, 1);
|
||||
}
|
||||
if (osVersion) {
|
||||
o.osversion = osVersion;
|
||||
}
|
||||
}
|
||||
|
||||
// Graded Browser Support
|
||||
// http://developer.yahoo.com/yui/articles/gbs
|
||||
|
2
bowser.min.js
vendored
2
bowser.min.js
vendored
@ -3,4 +3,4 @@
|
||||
* https://github.com/ded/bowser
|
||||
* MIT License | (c) Dustin Diaz 2014
|
||||
*/
|
||||
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function n(e,t,n){var r=e.match(t);return r&&r.length>n&&r[n]||0}function r(r){var i=/(msie|trident)/i.test(r),s=/chrome|crios/i.test(r),o=/phantom/i.test(r),u=/iphone/i.test(r),a=/ipad/i.test(r),f=/ipod/i.test(r),l=/touchpad/i.test(r),c=/silk/i.test(r),h=/safari/i.test(r)&&!s&&!o&&!c,p=/android/i.test(r),d=/opera/i.test(r)||/opr/i.test(r),m=/firefox/i.test(r),g=/gecko\//i.test(r),y=/seamonkey\//i.test(r),b=/webos/i.test(r),w=/windows phone/i.test(r),E=/blackberry/i.test(r),S=/version\/(\d+(\.\d+)?)/i,x=/firefox[ \/](\d+(\.\d+)?)/i,T={};f&&(u=!1);if(w)T={name:"Windows Phone",windowsphone:e,msie:e,mobile:e,version:n(r,/iemobile\/(\d+(\.\d+)?)/i,1)};else if(d)t=n(r,S,1)||n(r,/opr\/(\d+(\.\d+)?)/i,1)||n(r,/opera[ \/](\d+(\.\d+)?)/i,1),T={name:"Opera",opera:e,version:t},p&&(T.android=e,T.mobile=e),s&&(T.webkit=e);else if(i)T={name:"Internet Explorer",msie:e,version:n(r,/(msie |rv:)(\d+(\.\d+)?)/i,2)};else if(s){T={name:"Chrome",webkit:e,chrome:e,version:n(r,/(?:chrome|crios)\/(\d+(\.\d+)?)/i,1)},p&&(T.android=e);if(a||f||u)T[u?"iphone":a?"ipad":"ipod"]=e,T.ios=e;if(T.android||T.ios)T.mobile=e}else o?T={name:"PhantomJS",webkit:e,phantom:e,version:n(r,/phantomjs\/(\d+(\.\d+)?)/i,1)}:l?T={name:"TouchPad",webkit:e,touchpad:e,version:n(r,/touchpad\/(\d+(\.\d+)?)/i,1)}:c?T={name:"Amazon Silk",webkit:e,android:e,mobile:e,version:n(r,/silk\/(\d+(\.\d+)?)/i,1)}:u||a||f?(T={name:u?"iPhone":a?"iPad":"iPod",webkit:e,mobile:e,ios:e},T[u?"iphone":a?"ipad":"ipod"]=e,S.test(r)&&(T.version=n(r,S,1))):E?(T={name:"BlackBerry",blackberry:e,mobile:e},(t=n(r,S,1))?(T.version=t,T.webkit=e):T.version=n(r,/blackberry[\d]+\/(\d+(\.\d+)?)/i,1)):b?T={name:"WebOS",mobile:e,webkit:e,webos:e,version:n(r,S,1)||n(r,/wosbrowser\/(\d+(\.\d+)?)/i,1)}:g?(T={name:"Gecko",gecko:e,mozilla:e,version:n(r,x,1)},y?(T.name="SeaMonkey",T.seamonkey=e,T.version=n(r,/seamonkey\/(\d+(\.\d+)?)/i,1)):m&&(T.name="Firefox",T.firefox=e),p?(T.android=e,T.mobile=e):!p&&m&&/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(r)&&(T.firefoxos=e,T.mobile=e)):p?T={name:"Android",webkit:e,android:e,mobile:e,version:n(r,S,1)}:h&&(T={name:"Safari",webkit:e,safari:e,version:n(r,S,1)});var N;return p?(N=n(r,/android[ \/](\d+(\.\d+)*)/i,1),N&&(T.osversion=N)):u||a||f?(N=n(r,/os (\d+([_\s]\d+)*) like mac os x/i,1),N&&(T.osversion=N.replace(/[_\s]/g,"."))):w&&(N=n(r,/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,1),N&&(T.osversion=N)),T.msie&&T.version>=9||T.chrome&&T.version>=20||T.firefox&&T.version>=10||T.safari&&T.version>=5||T.opera&&T.version>=10||T.ios&&T.osversion&&T.osversion.split(".")[0]>=6?T.a=e:T.msie&&T.version<9||T.chrome&&T.version<20||T.firefox&&T.version<10||T.safari&&T.version<5||T.opera&&T.version<10||T.ios&&T.osversion&&T.osversion.split(".")[0]<6?T.c=e:T.x=e,T}var e=!0,t,i=r(typeof navigator!="undefined"?navigator.userAgent:"");return i._detect=r,i})
|
||||
!function(e,t){typeof module!="undefined"&&module.exports?module.exports.browser=t():typeof define=="function"?define(t):this[e]=t()}("bowser",function(){function n(e,t,n){var r=e.match(t);return r&&r.length>n&&r[n]||0}function r(r){var i=/(msie|trident)/i.test(r),s=/chrome|crios/i.test(r),o=/phantom/i.test(r),u=/iphone/i.test(r),a=/ipad/i.test(r),f=/ipod/i.test(r),l=/silk/i.test(r),c=/safari/i.test(r)&&!s&&!o&&!l,h=/android/i.test(r),p=/opera/i.test(r)||/opr/i.test(r),d=/firefox/i.test(r),m=/gecko\//i.test(r),g=/seamonkey\//i.test(r),y=/(?:web|hpw)os/i.test(r),b=/windows phone/i.test(r),w=/blackberry/i.test(r),E=/version\/(\d+(\.\d+)?)/i,S=/firefox[ \/](\d+(\.\d+)?)/i,x={};f&&(u=!1);if(b)x={name:"Windows Phone",windowsphone:e,msie:e,mobile:e,version:n(r,/iemobile\/(\d+(\.\d+)?)/i,1)};else if(p)t=n(r,E,1)||n(r,/opr\/(\d+(\.\d+)?)/i,1)||n(r,/opera[ \/](\d+(\.\d+)?)/i,1),x={name:"Opera",opera:e,version:t},h&&(x.android=e,x.mobile=e),s&&(x.webkit=e);else if(i)x={name:"Internet Explorer",msie:e,version:n(r,/(msie |rv:)(\d+(\.\d+)?)/i,2)};else if(s){x={name:"Chrome",webkit:e,chrome:e,version:n(r,/(?:chrome|crios)\/(\d+(\.\d+)?)/i,1)},h&&(x.android=e);if(a||f||u)x[u?"iphone":a?"ipad":"ipod"]=e,x.ios=e;if(x.android||x.ios)x.mobile=e}else o?x={name:"PhantomJS",webkit:e,phantom:e,version:n(r,/phantomjs\/(\d+(\.\d+)?)/i,1)}:l?x={name:"Amazon Silk",silk:e,webkit:e,android:e,mobile:e,version:n(r,/silk\/(\d+(\.\d+)?)/i,1)}:u||a||f?(x={name:u?"iPhone":a?"iPad":"iPod",webkit:e,mobile:e,ios:e},x[u?"iphone":a?"ipad":"ipod"]=e,E.test(r)&&(x.version=n(r,E,1))):w?(x={name:"BlackBerry",blackberry:e,mobile:e},(t=n(r,E,1))?(x.version=t,x.webkit=e):x.version=n(r,/blackberry[\d]+\/(\d+(\.\d+)?)/i,1)):y?(x={name:"WebOS",mobile:e,webkit:e,webos:e,version:n(r,E,1)||n(r,/w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i,1)},/touchpad\//i.test(r)&&(x.touchpad=e)):m?(x={name:"Gecko",gecko:e,mozilla:e,version:n(r,S,1)},g?(x.name="SeaMonkey",x.seamonkey=e,x.version=n(r,/seamonkey\/(\d+(\.\d+)?)/i,1)):d&&(x.name="Firefox",x.firefox=e),h?(x.android=e,x.mobile=e):!h&&d&&/\((mobile|tablet);[^\)]*rv:[\d\.]+\)/i.test(r)&&(x.firefoxos=e,x.mobile=e)):h?x={name:"Android",webkit:e,android:e,mobile:e,version:n(r,E,1)}:c&&(x={name:"Safari",webkit:e,safari:e,version:n(r,E,1)});var T;return h?(T=n(r,/android[ \/](\d+(\.\d+)*)/i,1),T&&(x.osversion=T)):u||a||f?(T=n(r,/os (\d+([_\s]\d+)*) like mac os x/i,1),T=(T||"").replace(/[_\s]/g,".")):b?T=n(r,/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,1):y&&(T=n(r,/(?:web|hpw)os\/(\d+(\.\d+)*)/i,1)),T&&(x.osversion=T),x.msie&&x.version>=9||x.chrome&&x.version>=20||x.firefox&&x.version>=10||x.safari&&x.version>=5||x.opera&&x.version>=10||x.ios&&x.osversion&&x.osversion.split(".")[0]>=6?x.a=e:x.msie&&x.version<9||x.chrome&&x.version<20||x.firefox&&x.version<10||x.safari&&x.version<5||x.opera&&x.version<10||x.ios&&x.osversion&&x.osversion.split(".")[0]<6?x.c=e:x.x=e,x}var e=!0,t,i=r(typeof navigator!="undefined"?navigator.userAgent:"");return i._detect=r,i})
|
@ -23,7 +23,6 @@
|
||||
, iphone = /iphone/i.test(ua)
|
||||
, ipad = /ipad/i.test(ua)
|
||||
, ipod = /ipod/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)
|
||||
@ -31,7 +30,7 @@
|
||||
, firefox = /firefox/i.test(ua)
|
||||
, gecko = /gecko\//i.test(ua)
|
||||
, seamonkey = /seamonkey\//i.test(ua)
|
||||
, webos = /webos/i.test(ua)
|
||||
, webos = /(?:web|hpw)os/i.test(ua)
|
||||
, windowsphone = /windows phone/i.test(ua)
|
||||
, blackberry = /blackberry/i.test(ua)
|
||||
, webkitVersion = /version\/(\d+(\.\d+)?)/i
|
||||
@ -89,14 +88,9 @@
|
||||
, phantom: t
|
||||
, version: getVersion(ua, /phantomjs\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
else if (touchpad) o = {
|
||||
name: 'TouchPad'
|
||||
, webkit: t
|
||||
, touchpad: t
|
||||
, version : getVersion(ua, /touchpad\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
else if (silk) o = {
|
||||
name: 'Amazon Silk'
|
||||
, silk: t
|
||||
, webkit: t
|
||||
, android: t
|
||||
, mobile: t
|
||||
@ -128,12 +122,15 @@
|
||||
o.version = getVersion(ua, /blackberry[\d]+\/(\d+(\.\d+)?)/i, 1)
|
||||
}
|
||||
}
|
||||
else if (webos) o = {
|
||||
else if (webos) {
|
||||
o = {
|
||||
name: 'WebOS'
|
||||
, mobile: t
|
||||
, webkit: t
|
||||
, webos: t
|
||||
, version: (getVersion(ua, webkitVersion, 1) || getVersion(ua, /w(?:eb)?osbrowser\/(\d+(\.\d+)?)/i, 1))
|
||||
};
|
||||
/touchpad\//i.test(ua) && (o.touchpad = t)
|
||||
}
|
||||
else if (gecko) {
|
||||
o = {
|
||||
|
@ -91,6 +91,7 @@ module.exports.useragents = {
|
||||
, 'Amazon Silk': {
|
||||
'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Mobile Safari/535.19 Silk-Accelerated=true': {
|
||||
name: 'Amazon Silk'
|
||||
, silk: true
|
||||
, webkit: true
|
||||
, android: true
|
||||
, osversion: '4.0.3'
|
||||
@ -100,6 +101,7 @@ module.exports.useragents = {
|
||||
}
|
||||
, 'Mozilla/5.0 (Linux; U; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/3.4 Safari/535.19 Silk-Accelerated=true': {
|
||||
name: 'Amazon Silk'
|
||||
, silk: true
|
||||
, webkit: true
|
||||
, android: true
|
||||
, mobile: true
|
||||
@ -108,6 +110,7 @@ module.exports.useragents = {
|
||||
}
|
||||
, 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.0.13.81_10003810) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=true': {
|
||||
name: 'Amazon Silk'
|
||||
, silk: true
|
||||
, webkit: true
|
||||
, android: true
|
||||
, osversion: '2.3.4'
|
||||
@ -117,6 +120,7 @@ module.exports.useragents = {
|
||||
}
|
||||
, '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': {
|
||||
name: 'Amazon Silk'
|
||||
, silk: true
|
||||
, webkit: true
|
||||
, android: true
|
||||
, mobile: true
|
||||
@ -666,7 +670,34 @@ module.exports.useragents = {
|
||||
}
|
||||
}
|
||||
, WebOS: {
|
||||
'Mozilla/5.0 (Linux; webOS/2.1.2; U; xx-xx) AppleWebKit/534.6 (KHTML, like Gecko) webOSBrowser/221.11 Safari/534.6 Pre/3.0': {
|
||||
'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, webos: true
|
||||
, osversion: '3.0.5'
|
||||
, version: '234.83'
|
||||
, webkit: true
|
||||
, mobile: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.2; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.40.1 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, webos: true
|
||||
, osversion: '3.0.2'
|
||||
, version: '234.40'
|
||||
, webkit: true
|
||||
, mobile: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; de-DE) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, webos: true
|
||||
, osversion: '3.0.0'
|
||||
, version: '233.70'
|
||||
, webkit: true
|
||||
, mobile: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (Linux; webOS/2.1.2; U; xx-xx) AppleWebKit/534.6 (KHTML, like Gecko) webOSBrowser/221.11 Safari/534.6 Pre/3.0': {
|
||||
webos: true
|
||||
, osversion: '2.1.2'
|
||||
, webkit: true
|
||||
@ -709,26 +740,6 @@ module.exports.useragents = {
|
||||
, x: true
|
||||
}
|
||||
}
|
||||
, TouchPad: {
|
||||
'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.5; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.83 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, version: '1.0'
|
||||
, webkit: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.2; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/234.40.1 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, version: '1.0'
|
||||
, webkit: true
|
||||
, x: true
|
||||
}
|
||||
, 'Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; de-DE) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0': {
|
||||
touchpad: true
|
||||
, version: '1.0'
|
||||
, webkit: true
|
||||
, x: true
|
||||
}
|
||||
}
|
||||
, PhantomJS: {
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.5.0 Safari/534.34': {
|
||||
phantom: true
|
||||
|
Loading…
Reference in New Issue
Block a user