mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 22:52:16 +03:00
Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
29bb0797a6 | ||
|
|
52897acf24 | ||
|
|
9ccc32ce5a | ||
|
|
4a65f1b3f8 | ||
|
|
be4d8a10d1 | ||
|
|
6d183003b3 | ||
|
|
a2b4f6d5c5 | ||
|
|
3f98036d50 | ||
|
|
d1d4e0a7a0 | ||
|
|
3ecb3fbea2 | ||
|
|
5cc6bf78a5 | ||
|
|
08c7a84407 | ||
|
|
ea9d093f0d | ||
|
|
1f4befe4c3 | ||
|
|
d35fb44066 | ||
|
|
9a6479193a | ||
|
|
527ba70cf4 | ||
|
|
3fe07487cd | ||
|
|
8030aa33f7 | ||
|
|
99251addfc | ||
|
|
610cdb84ae | ||
|
|
31b386c636 | ||
|
|
b15b48b1bf | ||
|
|
58fe246468 | ||
|
|
e1d3f25bf8 | ||
|
|
4efb13be3e | ||
|
|
bf9fb794d8 | ||
|
|
df815d4109 | ||
|
|
6dcee61a0b | ||
|
|
0288766544 | ||
|
|
7ea79afc2f | ||
|
|
59270c8cf7 | ||
|
|
3f92a3cb10 | ||
|
|
b9843b4108 | ||
|
|
bdeefcd1fb | ||
|
|
bf9c8de5c4 | ||
|
|
41b3e247a4 | ||
|
|
e5be3083cf | ||
|
|
68d124c59c | ||
|
|
33e6fe42d1 | ||
|
|
51822ad172 | ||
|
|
ec40433c5c | ||
|
|
65703e7c1a | ||
|
|
064d52255f | ||
|
|
71b5300080 | ||
|
|
e41fa1c829 | ||
|
|
7cd76a3fba | ||
|
|
ac1f92d3c6 | ||
|
|
eaacb14ef2 | ||
|
|
7704570581 | ||
|
|
9bb8bdb1b0 | ||
|
|
1f21d35ab8 | ||
|
|
d3668b9c2f | ||
|
|
a243a6a7c3 | ||
|
|
9a9844180d | ||
|
|
a84fb2f93a | ||
|
|
9bc93dc058 | ||
|
|
3d60909f30 | ||
|
|
8cb5b173fe | ||
|
|
faefb6fbb7 | ||
|
|
5e4d686e3e | ||
|
|
f1065dc4f8 |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
8
.travis.yml
Normal file
8
.travis.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- 0.8
|
||||
- 0.6
|
||||
notifications:
|
||||
email:
|
||||
on_success: never
|
||||
on_failure: always
|
||||
71
package.json
71
package.json
@@ -1,40 +1,59 @@
|
||||
{
|
||||
"title" : "UA-Parser.js",
|
||||
"name" : "ua-parser-js",
|
||||
"version" : "0.1.2",
|
||||
"author" : {
|
||||
"name" : "Faisal Salman",
|
||||
"email" : "fyzlman@gmail.com",
|
||||
"url" : "http://faisalman.com"
|
||||
},
|
||||
"description" : "Lightweight JavaScript-based user-agent parser",
|
||||
"keywords" : [
|
||||
"user-agent",
|
||||
"title": "UA-Parser.JS",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.4.15",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user agent",
|
||||
"parser",
|
||||
"browser"
|
||||
"browser",
|
||||
"engine",
|
||||
"os",
|
||||
"device"
|
||||
],
|
||||
"homepage" : "http://faisalman.github.com/ua-parser-js",
|
||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||
"contributors": [
|
||||
{
|
||||
"name" : "Faisal Salman",
|
||||
"email" : "fyzlman@gmail.com"
|
||||
}
|
||||
"Faisal Salman <fyzlman@gmail.com>"
|
||||
],
|
||||
"main" : "ua-parser.js",
|
||||
"main": "ua-parser",
|
||||
"scripts": {
|
||||
"test": "./node_modules/mocha/bin/mocha -R spec",
|
||||
"pretest": "./node_modules/uglify-js/bin/uglifyjs ua-parser.js > ua-parser.min.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": ">= 1.7.1",
|
||||
"uglify-js": ">= 1.3.4"
|
||||
},
|
||||
"repositories": [
|
||||
{
|
||||
"type" : "git",
|
||||
"url" : "https://github.com/faisalman/ua-parser-js.git"
|
||||
"type": "git",
|
||||
"url": "https://github.com/faisalman/ua-parser-js.git"
|
||||
}
|
||||
],
|
||||
"licenses" : [
|
||||
"repository" :
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/faisalman/ua-parser-js.git"
|
||||
},
|
||||
"licenses": [
|
||||
{
|
||||
"type" : "GPLv2",
|
||||
"url" : "http://www.gnu.org/licenses/gpl-2.0.html"
|
||||
"type": "GPLv2",
|
||||
"url": "http://www.gnu.org/licenses/gpl-2.0.html"
|
||||
},
|
||||
{
|
||||
"type" : "MIT",
|
||||
"url" : "http://www.opensource.org/licenses/mit-license.php"
|
||||
"type": "MIT",
|
||||
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||
}
|
||||
]
|
||||
],
|
||||
"engines": {
|
||||
"node": "*"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "."
|
||||
},
|
||||
"files": [
|
||||
""
|
||||
],
|
||||
"repository": "git://github.com/faisalman/ua-parser-js.git"
|
||||
}
|
||||
|
||||
81
readme.md
81
readme.md
@@ -1,21 +1,26 @@
|
||||
# UA-Parser.js
|
||||
# UA-Parser.JS
|
||||
|
||||
JavaScript-based user-agent parser
|
||||
Lightweight JavaScript-based User-Agent string parser
|
||||
|
||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||
* Home : http://faisalman.github.com/ua-parser-js
|
||||
* Source : https://github.com/faisalman/ua-parser-js
|
||||
* License : GPLv2
|
||||
* Source : https://github.com/faisalman/ua-parser-js
|
||||
* License : GPLv2 & MIT
|
||||
|
||||
[](https://travis-ci.org/faisalman/ua-parser-js)
|
||||
|
||||
## Features
|
||||
|
||||
Get detailed type and version of web browser, layout engine, and operating system.
|
||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string.
|
||||
|
||||
## Methods
|
||||
|
||||
* `getBrowser([uastring])`
|
||||
* `getEngine([uastring])`
|
||||
* `getOS([uastring])`
|
||||
* `getBrowser()`
|
||||
* `getDevice()`
|
||||
* `getEngine()`
|
||||
* `getOS()`
|
||||
* `getResult()`
|
||||
* `getUA()`
|
||||
* `setUA(uastring)`
|
||||
|
||||
## Example
|
||||
@@ -23,10 +28,11 @@ Get detailed type and version of web browser, layout engine, and operating syste
|
||||
```html
|
||||
<script type="text/javascript" src="ua-parser.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var p = new UAParser(); // if no string given as parameter, by default it takes ua string from current browser's window.navigator
|
||||
|
||||
console.log(p.result);
|
||||
var parser = new UAParser();
|
||||
|
||||
// by default it takes ua string from current browser's window.navigator.userAgent
|
||||
console.log(parser.getResult());
|
||||
/*
|
||||
/// this will print an object structured like this:
|
||||
{
|
||||
@@ -42,30 +48,57 @@ Get detailed type and version of web browser, layout engine, and operating syste
|
||||
os: {
|
||||
name: "",
|
||||
version: ""
|
||||
},
|
||||
device: {
|
||||
model: "",
|
||||
type: "",
|
||||
vendor: ""
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// let's test a custom user-agent string as an example
|
||||
p.setUA("Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2");
|
||||
var uastr = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.2 (KHTML, like Gecko) Ubuntu/11.10 Chromium/15.0.874.106 Chrome/15.0.874.106 Safari/535.2";
|
||||
parser.setUA(uastr);
|
||||
|
||||
console.log(p.result.browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
||||
console.log(p.result.engine); // {name: "AppleWebKit", version: "535.2"}
|
||||
console.log(p.result.os); // {name: "Ubuntu", version: "11.10"}
|
||||
console.log(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
||||
console.log(parser.getResult().device); // {model: undefined, type: undefined, vendor: undefined}
|
||||
console.log(parser.getResult().engine); // {name: "AppleWebKit", version: "535.2"}
|
||||
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
||||
|
||||
// let's take another test please
|
||||
console.log(parser.setUA("Mozilla/5.0 (compatible; Konqueror/4.1; OpenBSD) KHTML/4.1.4 (like Gecko)").getBrowser().name); // "Konqueror"
|
||||
console.log(parser.getOS()); // {name: "OpenBSD", version: undefined}
|
||||
console.log(parser.getEngine()); // {name: "KHTML", version: "4.1.4"}
|
||||
</script>
|
||||
```
|
||||
|
||||
## Using node.js
|
||||
|
||||
```sh
|
||||
$ npm install ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser');
|
||||
var parser = new UAParser();
|
||||
var uaString = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.11 (KHTML, like Gecko) Version/7.1.0.7 Safari/534.11';
|
||||
|
||||
console.log(parser.setUA(uaString).getDevice().model); // "PlayBook"
|
||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||
console.log(parser.getEngine().name); // "AppleWebKit"
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
567
test.js
Normal file
567
test.js
Normal file
@@ -0,0 +1,567 @@
|
||||
var assert = require('assert');
|
||||
var UAParser = require('./ua-parser');
|
||||
var parser = new UAParser();
|
||||
var browsers = [
|
||||
{
|
||||
desc : 'Arora',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; de-CH) AppleWebKit/523.15 (KHTML, like Gecko, Safari/419.3) Arora/0.2',
|
||||
expect :
|
||||
{
|
||||
name : 'Arora',
|
||||
version : '0.2'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Avant',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB5; Avant Browser; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
|
||||
expect :
|
||||
{
|
||||
name : 'Avant Browser',
|
||||
version : undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Baidu',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; baidubrowser 1.x)',
|
||||
expect :
|
||||
{
|
||||
name : 'baidubrowser',
|
||||
version : '1.x'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Bolt',
|
||||
ua : 'Mozilla/5.0 (X11; 78; CentOS; US-en) AppleWebKit/527+ (KHTML, like Gecko) Bolt/0.862 Version/3.0 Safari/523.15',
|
||||
expect :
|
||||
{
|
||||
name : 'Bolt',
|
||||
version : '0.862'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Camino',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X 10.4; en; rv:1.9.0.19) Gecko/2011091218 Camino/2.0.9 (like Firefox/3.0.19)',
|
||||
expect :
|
||||
{
|
||||
name : 'Camino',
|
||||
version : '2.0.9'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Chimera',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; pl-PL; rv:1.0.1) Gecko/20021111 Chimera/0.6',
|
||||
expect :
|
||||
{
|
||||
name : 'Chimera',
|
||||
version : '0.6'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Chrome',
|
||||
ua : 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.6 (KHTML, like Gecko) Chrome/20.0.1090.0 Safari/536.6',
|
||||
expect :
|
||||
{
|
||||
name : 'Chrome',
|
||||
version : '20.0.1090.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Chrome on iOS',
|
||||
ua : 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3',
|
||||
expect :
|
||||
{
|
||||
name : 'Chrome',
|
||||
version : '19.0.1084.60'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Chromium',
|
||||
ua : 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.10 Chromium/16.0.912.21 Chrome/16.0.912.21 Safari/535.7',
|
||||
expect :
|
||||
{
|
||||
name : 'Chromium',
|
||||
version : '16.0.912.21'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Chrome on Android',
|
||||
ua : 'Mozilla/5.0 (Linux; U; Android-4.0.3; en-us; Galaxy Nexus Build/IML74K) AppleWebKit/535.7 (KHTML, like Gecko) CrMo/16.0.912.75 Mobile Safari/535.7',
|
||||
expect :
|
||||
{
|
||||
name : 'Chrome',
|
||||
version : '16.0.912.75'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Dillo',
|
||||
ua : 'Dillo/2.2',
|
||||
expect :
|
||||
{
|
||||
name : 'Dillo',
|
||||
version : '2.2'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Dolphin',
|
||||
ua : 'Mozilla/5.0 (SCH-F859/F859DG12;U;NUCLEUS/2.1;Profile/MIDP-2.1 Configuration/CLDC-1.1;480*800;CTC/2.0) Dolfin/2.0',
|
||||
expect :
|
||||
{
|
||||
name : 'Dolphin',
|
||||
version : '2.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Doris',
|
||||
ua : 'Doris/1.15 [en] (Symbian)',
|
||||
expect :
|
||||
{
|
||||
name : 'Doris',
|
||||
version : '1.15'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Epiphany',
|
||||
ua : 'Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7) Gecko/20040628 Epiphany/1.2.6',
|
||||
expect :
|
||||
{
|
||||
name : 'Epiphany',
|
||||
version : '1.2.6'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Firebird',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031007 Firebird/0.7',
|
||||
expect :
|
||||
{
|
||||
name : 'Firebird',
|
||||
version : '0.7'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Firefox',
|
||||
ua : 'Mozilla/5.0 (Windows NT 6.1; rv:15.0) Gecko/20120716 Firefox/15.0a2',
|
||||
expect :
|
||||
{
|
||||
name : 'Firefox',
|
||||
version : '15.0a2'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Fennec',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux armv61; en-US; rv:1.9.1b2pre) Gecko/20081015 Fennec/1.0a1',
|
||||
expect :
|
||||
{
|
||||
name : 'Fennec',
|
||||
version : '1.0a1'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Flock',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008100716 Firefox/3.0.3 Flock/2.0',
|
||||
expect :
|
||||
{
|
||||
name : 'Flock',
|
||||
version : '2.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'GoBrowser',
|
||||
ua : 'Nokia5700XpressMusic/GoBrowser/1.6.91',
|
||||
expect :
|
||||
{
|
||||
name : 'GoBrowser',
|
||||
version : '1.6.91'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'IceApe',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.19) Gecko/20110817 Iceape/2.0.14',
|
||||
expect :
|
||||
{
|
||||
name : 'Iceape',
|
||||
version : '2.0.14'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'IceCat',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092921 IceCat/3.0.3-g1',
|
||||
expect :
|
||||
{
|
||||
name : 'IceCat',
|
||||
version : '3.0.3-g1'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Iceweasel',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.0.16) Gecko/2009121610 Iceweasel/3.0.6 (Debian-3.0.6-3)',
|
||||
expect :
|
||||
{
|
||||
name : 'Iceweasel',
|
||||
version : '3.0.6'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'iCab',
|
||||
ua : 'iCab/2.9.5 (Macintosh; U; PPC; Mac OS X)',
|
||||
expect :
|
||||
{
|
||||
name : 'iCab',
|
||||
version : '2.9.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'IEMobile',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows CE; IEMobile 7.11) 320x240; VZW; Motorola-Q9c; Windows Mobile 6.1 Standard',
|
||||
expect :
|
||||
{
|
||||
name : 'IEMobile',
|
||||
version : '7.11'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'K-Meleon',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.5) Gecko/20031016 K-Meleon/0.8.2',
|
||||
expect :
|
||||
{
|
||||
name : 'K-Meleon',
|
||||
version : '0.8.2'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Kindle Browser',
|
||||
ua : 'Mozilla/4.0 (compatible; Linux 2.6.22) NetFront/3.4 Kindle/2.5 (screen 600x800; rotate)',
|
||||
expect :
|
||||
{
|
||||
name : 'Kindle',
|
||||
version : '2.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Konqueror',
|
||||
ua : 'Mozilla/5.0 (compatible; Konqueror/3.5; Linux; X11; x86_64) KHTML/3.5.6 (like Gecko) (Kubuntu)',
|
||||
expect :
|
||||
{
|
||||
name : 'Konqueror',
|
||||
version : '3.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Lunascape',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.2) Gecko/20090804 Firefox/3.5.2 Lunascape/5.1.4.5',
|
||||
expect :
|
||||
{
|
||||
name : 'Lunascape',
|
||||
version : '5.1.4.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Lynx',
|
||||
ua : 'Lynx/2.8.5dev.16 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6b',
|
||||
expect :
|
||||
{
|
||||
name : 'Lynx',
|
||||
version : '2.8.5dev.16'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Maemo Browser',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux armv7l; ru-RU; rv:1.9.2.3pre) Gecko/20100723 Firefox/3.5 Maemo Browser 1.7.4.8 RX-51 N900',
|
||||
expect :
|
||||
{
|
||||
name : 'Maemo Browser',
|
||||
version : '1.7.4.8'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Maxthon',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)',
|
||||
expect :
|
||||
{
|
||||
name : 'Maxthon',
|
||||
version : undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Midori',
|
||||
ua : 'Midori/0.2.2 (X11; Linux i686; U; en-us) WebKit/531.2+',
|
||||
expect :
|
||||
{
|
||||
name : 'Midori',
|
||||
version : '0.2.2'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Minimo',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux armv6l; rv 1.8.1.5pre) Gecko/20070619 Minimo/0.020',
|
||||
expect :
|
||||
{
|
||||
name : 'Minimo',
|
||||
version : '0.020'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Mobile Safari',
|
||||
ua : 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A293 Safari/6531.22.7',
|
||||
expect :
|
||||
{
|
||||
name : 'Mobile Safari',
|
||||
version : '4.0.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Mosaic',
|
||||
ua : 'NCSA_Mosaic/2.6 (X11; SunOS 4.1.3 sun4m)',
|
||||
expect :
|
||||
{
|
||||
name : 'Mosaic',
|
||||
version : '2.6'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Mozilla',
|
||||
ua : 'Mozilla/5.0 (X11; U; SunOS sun4u; en-US; rv:1.7) Gecko/20070606',
|
||||
expect :
|
||||
{
|
||||
name : 'Mozilla',
|
||||
version : '5.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'MSIE',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 5.0b1; Mac_PowerPC)',
|
||||
expect :
|
||||
{
|
||||
name : 'IE',
|
||||
version : '5.0b1'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'NetFront',
|
||||
ua : 'Mozilla/4.0 (PDA; Windows CE/1.0.1) NetFront/3.0',
|
||||
expect :
|
||||
{
|
||||
name : 'NetFront',
|
||||
version : '3.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Netscape on Windows ME',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.8.1.8pre) Gecko/20071015 Firefox/2.0.0.7 Navigator/9.0',
|
||||
expect :
|
||||
{
|
||||
name : 'Netscape',
|
||||
version : '9.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Netscape on Windows 2000',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.5) Gecko/20050519 Netscape/8.0.1',
|
||||
expect :
|
||||
{
|
||||
name : 'Netscape',
|
||||
version : '8.0.1'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Nokia Browser',
|
||||
ua : 'Mozilla/5.0 (Symbian/3; Series60/5.2 NokiaN8-00/025.007; Profile/MIDP-2.1 Configuration/CLDC-1.1 ) AppleWebKit/533.4 (KHTML, like Gecko) NokiaBrowser/7.3.1.37 Mobile Safari/533.4 3gpp-gba',
|
||||
expect :
|
||||
{
|
||||
name : 'NokiaBrowser',
|
||||
version : '7.3.1.37'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'OmniWeb',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-US) AppleWebKit/85 (KHTML, like Gecko) OmniWeb/v558.48',
|
||||
expect :
|
||||
{
|
||||
name : 'OmniWeb',
|
||||
version : '558.48'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera > 9.80',
|
||||
ua : 'Opera/9.80 (X11; Linux x86_64; U; Linux Mint; en) Presto/2.2.15 Version/10.10',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera',
|
||||
version : '10.10'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera < 9.80 on Windows',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 5.0; Windows 95) Opera 6.01 [en]',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera',
|
||||
version : '6.01'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera < 9.80 on OSX',
|
||||
ua : 'Opera/8.5 (Macintosh; PPC Mac OS X; U; en)',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera',
|
||||
version : '8.5'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera Mobile',
|
||||
ua : 'Opera/9.80 (Android 2.3.5; Linux; Opera Mobi/ADR-1111101157; U; de) Presto/2.9.201 Version/11.50',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera Mobi',
|
||||
version : '11.50'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Opera Mini',
|
||||
ua : 'Opera/9.80 (J2ME/MIDP; Opera Mini/5.1.21214/19.916; U; en) Presto/2.5.25',
|
||||
expect :
|
||||
{
|
||||
name : 'Opera Mini',
|
||||
version : '5.1.21214'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Phoenix',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2b) Gecko/20021029 Phoenix/0.4',
|
||||
expect :
|
||||
{
|
||||
name : 'Phoenix',
|
||||
version : '0.4'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Polaris',
|
||||
ua : 'LG-LX600 Polaris/6.0 MMP/2.0 Profile/MIDP-2.1 Configuration/CLDC-1.1',
|
||||
expect :
|
||||
{
|
||||
name : 'Polaris',
|
||||
version : '6.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'RockMelt',
|
||||
ua : 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.7 (KHTML, like Gecko) RockMelt/0.8.36.78 Chrome/7.0.517.44 Safari/534.7',
|
||||
expect :
|
||||
{
|
||||
name : 'RockMelt',
|
||||
version : '0.8.36.78'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Safari < 3.0',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/419 (KHTML, like Gecko) Safari/419.3',
|
||||
expect :
|
||||
{
|
||||
name : 'Safari',
|
||||
version : '2.0.4'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'SeaMonkey',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b4pre) Gecko/20090405 SeaMonkey/2.0b1pre',
|
||||
expect :
|
||||
{
|
||||
name : 'SeaMonkey',
|
||||
version : '2.0b1pre'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Silk Browser',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-84)',
|
||||
expect :
|
||||
{
|
||||
name : 'Silk',
|
||||
version : '1.1.0-84'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Skyfire',
|
||||
ua : 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Safari/530.17 Skyfire/2.0',
|
||||
expect :
|
||||
{
|
||||
name : 'Skyfire',
|
||||
version : '2.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'SlimBrowser',
|
||||
ua : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SlimBrowser)',
|
||||
expect :
|
||||
{
|
||||
name : 'SlimBrowser',
|
||||
version : undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Swiftfox',
|
||||
ua : 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1) Gecko/20061024 Firefox/2.0 (Swiftfox)',
|
||||
expect :
|
||||
{
|
||||
name : 'Swiftfox',
|
||||
version : undefined
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Tizen Browser',
|
||||
ua : 'Mozilla/5.0 (Linux; U; Tizen/1.0 like Android; en-us; AppleWebKit/534.46 (KHTML, like Gecko) Tizen Browser/1.0 Mobile',
|
||||
expect :
|
||||
{
|
||||
name : 'Tizen Browser',
|
||||
version : '1.0'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'UC Browser on Samsung',
|
||||
ua : 'Mozilla/5.0 (Java; U; Pt-br; samsung-gt-s5620) UCBrowser8.2.1.144/69/352/UCWEB Mobile UNTRUSTED/1.0',
|
||||
expect :
|
||||
{
|
||||
name : 'UCBrowser',
|
||||
version : '8.2.1.144'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'UC Browser on Nokia',
|
||||
ua : 'Mozilla/5.0 (S60V3; U; en-in; NokiaN73)/UC Browser8.4.0.159/28/351/UCWEB Mobile',
|
||||
expect :
|
||||
{
|
||||
name : 'UC Browser',
|
||||
version : '8.4.0.159'
|
||||
}
|
||||
},
|
||||
{
|
||||
desc : 'Yandex',
|
||||
ua : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.5 (KHTML, like Gecko) YaBrowser/1.0.1084.5402 Chrome/19.0.1084.5402 Safari/536.5',
|
||||
expect :
|
||||
{
|
||||
name : 'Yandex',
|
||||
version : '1.0.1084.5402'
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
describe('getBrowser', function () {
|
||||
|
||||
for (var i in browsers) {
|
||||
|
||||
describe('[' + browsers[i].desc + ']', function () {
|
||||
describe('"' + browsers[i].ua + '"', function () {
|
||||
|
||||
var expect = browsers[i].expect;
|
||||
var result = parser.setUA(browsers[i].ua).getBrowser();
|
||||
|
||||
it('should return browser name: ' + expect.name, function () {
|
||||
assert.equal(result.name, expect.name);
|
||||
});
|
||||
|
||||
it('should return browser version: ' + expect.version, function () {
|
||||
assert.equal(result.version, expect.version);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
436
ua-parser.js
436
ua-parser.js
@@ -1,159 +1,308 @@
|
||||
// UA-Parser.js v0.2.0
|
||||
// Lightweight JavaScript-based user-agent parser
|
||||
// UA-Parser.JS v0.4.15
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
// Copyright © 2012 Faisalman
|
||||
// Licensed under GPLv2
|
||||
// Dual licensed under GPLv2 & MIT
|
||||
|
||||
function UAParser (uastring) {
|
||||
(function (global, undefined) {
|
||||
|
||||
var ua = uastring || window.navigator.userAgent;
|
||||
'use strict';
|
||||
|
||||
// regexp mapper
|
||||
var regxMap = function (ua) {
|
||||
var result;
|
||||
var i, j, k, l;
|
||||
for (i = 1; i < arguments.length; i += 2) {
|
||||
var regex = arguments[i];
|
||||
var props = arguments[i + 1];
|
||||
var isMatchFound = false;
|
||||
for (j = 0; j < regex.length; j++) {
|
||||
var match = regex[j].exec(ua);
|
||||
//console.log(match);
|
||||
if (!!match) {
|
||||
var mapper = {
|
||||
|
||||
regex : function () {
|
||||
|
||||
var result, i, j, k, l, m, args = arguments;
|
||||
|
||||
// loop through all regexes maps
|
||||
for (i = 0; i < args.length; i += 2) {
|
||||
|
||||
var regex = args[i], // odd sequence (0,2,4,..)
|
||||
props = args[i + 1]; // even sequence (1,3,5,..)
|
||||
|
||||
// construct object barebones
|
||||
if (typeof result === 'undefined') {
|
||||
result = {};
|
||||
l = 1;
|
||||
for (k = 0; k < props.length; k++) {
|
||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
||||
result[props[k][0]] = props[k][1];
|
||||
l -= 1;
|
||||
} else if (typeof props[k] === 'object' && props[k].length === 3) {
|
||||
result[props[k][0]] = (!!match[k + l]) ? match[k + l].replace(props[k][1], props[k][2]) : undefined;
|
||||
} else {
|
||||
result[props[k]] = (!!match[k + l]) ? match[k + l] : undefined;
|
||||
}
|
||||
}
|
||||
isMatchFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isMatchFound) {
|
||||
result = {};
|
||||
for (k in props) {
|
||||
if (props.hasOwnProperty(k)) {
|
||||
if (typeof props[k] == 'object') {
|
||||
if (typeof props[k] === 'object') {
|
||||
result[props[k][0]] = undefined;
|
||||
} else {
|
||||
result[props[k]] = undefined;
|
||||
}
|
||||
}
|
||||
if (this.getUA().toString() === '') {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return result;
|
||||
|
||||
// try matching uastring with regexes
|
||||
for (j = 0; j < regex.length; j++) {
|
||||
l = regex[j].exec(this.getUA());
|
||||
if (!!l) {
|
||||
for (k = 0; k < props.length; k++) {
|
||||
m = l[k + 1];
|
||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
||||
result[props[k][0]] = props[k][1];
|
||||
} else if (typeof props[k] === 'object' && props[k].length === 3) {
|
||||
if (typeof props[k][1] === 'function' && !(props[k][1].exec && props[k][1].test)) {
|
||||
result[props[k][0]] = m ? props[k][1].call(this, m, props[k][2]) : undefined;
|
||||
} else {
|
||||
result[props[k][0]] = m ? m.replace(props[k][1], props[k][2]) : undefined;
|
||||
}
|
||||
} else {
|
||||
result[props[k]] = m ? m : undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!!l) break; // break the loop immediately if match found
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
string : function (str, map) {
|
||||
|
||||
for (var i in map) {
|
||||
if (map.hasOwnProperty(i)) {
|
||||
if (typeof map[i] === 'object' && map[i].length > 0) {
|
||||
for (var j = 0; j < map[i].length; j++) {
|
||||
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) {
|
||||
return (i.toString() === 'undefined') ? undefined : i;
|
||||
}
|
||||
}
|
||||
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
||||
return (i.toString() === 'undefined') ? undefined : i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
var mapper = {
|
||||
os : {
|
||||
win: function (str, match) {
|
||||
switch (match.toLowerCase()) {
|
||||
case 'nt 5.0':
|
||||
return '2000';
|
||||
case 'nt 5.1':
|
||||
case 'nt 5.2':
|
||||
return 'XP';
|
||||
case 'nt 6.0':
|
||||
return 'Vista';
|
||||
case 'nt 6.1':
|
||||
return '7';
|
||||
case 'nt 6.2':
|
||||
return '8';
|
||||
default:
|
||||
return match;
|
||||
};
|
||||
var maps = {
|
||||
browser : {
|
||||
oldsafari : {
|
||||
major : {
|
||||
'1' : ['/85', '/125', '/312'],
|
||||
'2' : ['/412', '/416', '/417', '/419'],
|
||||
'undefined' : '/'
|
||||
},
|
||||
version : {
|
||||
'1.0' : '/85',
|
||||
'1.2' : '/125',
|
||||
'1.3' : '/312',
|
||||
'2.0' : '/412',
|
||||
'2.0.2' : '/416',
|
||||
'2.0.3' : '/417',
|
||||
'2.0.4' : '/419',
|
||||
'undefined' : '/'
|
||||
}
|
||||
}
|
||||
},
|
||||
os : {
|
||||
windows : {
|
||||
version : {
|
||||
'ME' : '4.90',
|
||||
'NT 3.11' : 'NT3.51',
|
||||
'NT 4.0' : 'NT4.0',
|
||||
'2000' : 'NT 5.0',
|
||||
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||
'Vista' : 'NT 6.0',
|
||||
'7' : 'NT 6.1',
|
||||
'8' : 'NT 6.2',
|
||||
'RT' : 'ARM'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.getBrowser = function (uastring) {
|
||||
var regexes = {
|
||||
|
||||
return regxMap(uastring || ua, [
|
||||
browser : [[
|
||||
|
||||
// Presto based
|
||||
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
||||
/(opera\smobi).+version\/((\d+)?[\w\.-]+)/i, // Opera Mobile
|
||||
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||
|
||||
// Mixed
|
||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||
/(lunascape|maxthon|netfront|jasmine)[\/\s]?((\d+)?[\w\.]+)/i, // Lunascape/Maxthon/Netfront/Jasmine
|
||||
|
||||
// Presto based
|
||||
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
||||
/(opera\smobi)\/((\d+)?[\w\.-]+)/i, // Opera Mobile
|
||||
/(opera).*\/((\d+)?[\w\.]+)/i, // Opera
|
||||
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,
|
||||
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
||||
|
||||
// Trident based
|
||||
/(avant\sbrowser|iemobile|slimbrowser)[\/\s]?((\d+)?[\w\.]*)/i, // Avant/IEMobile/SlimBrowser
|
||||
/(avant\sbrowser|iemobile|slimbrowser|baidubrowser)[\/\s]?((\d+)?[\w\.]*)/i,
|
||||
// Avant/IEMobile/SlimBrowser/Baidu
|
||||
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||
|
||||
// Webkit/KHTML based
|
||||
/(chromium|flock|rockmelt|midori|epiphany)\/((\d+)?[\w\.]+)/i, // Chromium/Flock/RockMelt/Midori/Epiphany
|
||||
/(chrome|omniweb|arora|dolfin)\/((\d+)?[\w\.]+)/i, // Chrome/OmniWeb/Arora/Dolphin
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||
], ['name', 'version', 'major'], [
|
||||
/android.+crmo\/((\d+)?[\w\.]+)/i, // Chrome for Android
|
||||
|
||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||
], [['name', 'Yandex'], 'version', 'major'], [
|
||||
|
||||
/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i
|
||||
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
||||
], ['name', 'version', 'major'], [
|
||||
|
||||
/(dolfin)\/((\d+)?[\w\.]+)/i // Dolphin
|
||||
], [['name', 'Dolphin'], 'version', 'major'], [
|
||||
|
||||
/((?:android.+)crmo|crios)\/((\d+)?[\w\.]+)/i // Chrome for Android/iOS
|
||||
], [['name', 'Chrome'], 'version', 'major'], [
|
||||
/(mobile\ssafari|safari|konqueror)\/((\d+)?[\w\.]+)/i, // Safari/Konqueror
|
||||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i,
|
||||
|
||||
/version\/((\d+)?[\w\.]+).+?mobile\/\w+\s(safari)/i // Mobile Safari
|
||||
], ['version', 'major', ['name', 'Mobile Safari']], [
|
||||
|
||||
/version\/((\d+)?[\w\.]+).+?(mobile\s?safari|safari)/i // Safari & Safari Mobile
|
||||
], ['version', 'major', 'name'], [
|
||||
|
||||
/applewebkit.+?(mobile\s?safari|safari)((\/[\w\.]+))/i // Safari < 3.0
|
||||
], ['name', ['major', mapper.string, maps.browser.oldsafari.major], ['version', mapper.string, maps.browser.oldsafari.version]], [
|
||||
|
||||
/(konqueror)\/((\d+)?[\w\.]+)/i, // Konqueror
|
||||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i
|
||||
], ['name', 'version', 'major'], [
|
||||
|
||||
// Gecko based
|
||||
/(iceweasel|camino|fennec|maemo|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i, // Iceweasel/Camino/Fennec/Maemo/Minimo
|
||||
/(firefox|seamonkey|netscape|navigator|k-meleon|icecat|iceape)\/((\d+)?[\w\.]+)/i,
|
||||
// Firefox/SeaMonkey/Netscape/K-Meleon/IceCat/IceApe
|
||||
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||
], [['name', 'Netscape'], 'version', 'major'], [
|
||||
/(swiftfox)/i, // Swiftfox
|
||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo
|
||||
/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.-]+)/i,
|
||||
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
||||
/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||
|
||||
// Other
|
||||
/(lynx|dillo|icab)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab
|
||||
], ['name', 'version', 'major']);
|
||||
};
|
||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris
|
||||
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
||||
], ['name', 'version', 'major']
|
||||
],
|
||||
|
||||
this.getEngine = function (uastring) {
|
||||
device : [[
|
||||
|
||||
return regxMap(uastring || ua, [
|
||||
/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
|
||||
], ['model', 'vendor', ['type', 'Tablet']], [
|
||||
|
||||
/(hp).+(touchpad)/i, // HP TouchPad
|
||||
/(kindle)\/([\w\.]+)/i, // Kindle
|
||||
/\s(nook)[\w\s]+build\/(\w+)/i, // Nook
|
||||
/(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
|
||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
||||
|
||||
/\((ip[honed]+);.+(apple)/i // iPod/iPhone
|
||||
], ['model', 'vendor', ['type', 'Mobile']], [
|
||||
|
||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
||||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i,
|
||||
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Huawei/Meizu/Motorola
|
||||
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
||||
/(asus)-?(\w+)/i // Asus
|
||||
], ['vendor', 'model', ['type', 'Mobile']], [
|
||||
/\((bb10);\s(\w+)/i // BlackBerry 10
|
||||
], [['vendor', 'BlackBerry'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/android.+((transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+))/i // Asus Tablets
|
||||
], [['vendor', 'Asus'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
||||
|
||||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
||||
], ['vendor', 'model', ['type', 'Console']], [
|
||||
|
||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||
/(zte)-(\w+)*/i // ZTE
|
||||
], ['vendor', ['model', /_/g, ' '], ['type', 'Mobile']], [
|
||||
|
||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||
/(mot)[\s-]?(\w+)*/i
|
||||
], [['vendor', 'Motorola'], 'model', ['type', 'Mobile']], [
|
||||
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i
|
||||
], [['vendor', 'Motorola'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
||||
], [['vendor', 'Samsung'], 'model', ['type', 'Tablet']], [ // Samsung
|
||||
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||
/sec-((sgh\w+))/i
|
||||
], [['vendor', 'Samsung'], 'model', ['type', 'Mobile']], [
|
||||
/(sie)-(\w+)*/i // Siemens
|
||||
], [['vendor', 'Siemens'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
||||
/(nokia)[\s_-]?([\w-]+)*/i
|
||||
], [['vendor', 'Nokia'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer
|
||||
], [['vendor', 'Acer'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Tablet']], [
|
||||
/(lg)[e;\s-\/]+(\w+)*/i
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
/(mobile|tablet);.+rv\:.+gecko\//i // Unidentifiable
|
||||
], ['type', 'vendor', 'model']
|
||||
],
|
||||
|
||||
engine : [[
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
|
||||
/(khtml)\/([\w\.]+)/i // KHTML
|
||||
/([aple]*webkit|trident|netfront)\/([\w\.]+)/i, // Webkit/Trident/NetFront
|
||||
/(khtml)\/([\w\.]+)/i, // KHTML
|
||||
/(tasman)\s([\w\.]+)/i // Tasman
|
||||
], ['name', 'version'], [
|
||||
|
||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||
], ['version', 'name']);
|
||||
};
|
||||
], ['version', 'name']
|
||||
],
|
||||
|
||||
this.getOS = function (uastring) {
|
||||
|
||||
return regxMap(uastring || ua, [
|
||||
os : [[
|
||||
|
||||
// Windows based
|
||||
/(windows\sphone\sos|windows)\s+([\w\.\s]+)*/i, // Windows
|
||||
], ['name', ['version', /(nt\s[\d\.]+)/gi, mapper.os.win]], [
|
||||
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||
/(windows\sphone\sos|windows\s?[mobile]*)[\s\/]?([ntce\d\.\s]+\w)/i
|
||||
], ['name', ['version', mapper.string, maps.os.windows.version]], [
|
||||
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
||||
], [['name', 'Windows'], ['version', mapper.string, maps.os.windows.version]], [
|
||||
|
||||
// Mobile/Embedded OS
|
||||
/\((bb)(10);/i // BlackBerry 10
|
||||
], [['name', 'BlackBerry'], 'version'], [
|
||||
/(blackberry).+version\/([\w\.]+)/i, // Blackberry
|
||||
/(android|symbianos|symbos|webos|palm\os|qnx|bada|rim\stablet\sos)[\/\s-]?([\w\.]+)*/i,
|
||||
// Android/Symbian/WebOS/Palm/QNX/Bada/RIM
|
||||
/(nintendo|playstation)\s([wids3portable]+)/i, // Nintendo/Playstation
|
||||
/(tizen)\/([\w\.]+)/i, // Tizen
|
||||
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i
|
||||
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
||||
], ['name', 'version'], [
|
||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||
], [['name', 'Symbian'], 'version'],[
|
||||
|
||||
/(nintendo|playstation)\s([wids3portablev]+)/i, // Nintendo/Playstation
|
||||
|
||||
// GNU/Linux based
|
||||
/(mint)[\/\s\(]?(\w+)*/i, // Mint
|
||||
/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk)[\/\s-]?([\w\.-]+)*/i,
|
||||
// Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
|
||||
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk
|
||||
/(gnu|linux)\s?([\w\.]+)*/i // Other GNU/Linux
|
||||
/(hurd|linux)\s?([\w\.]+)*/i, // Hurd/Linux
|
||||
/(gnu)\s?([\w\.]+)*/i // GNU
|
||||
], ['name', 'version'], [
|
||||
|
||||
/cros\s([\w\.\s]+)/i // Chromium OS
|
||||
/(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
|
||||
], [['name', 'Chromium OS'], 'version'],[
|
||||
|
||||
// Solaris
|
||||
/sunos\s?([\w\.\s]+)*/i // Solaris
|
||||
/(sunos)\s?([\w\.]+\d)*/i // Solaris
|
||||
], [['name', 'Solaris'], 'version'], [
|
||||
|
||||
// BSD based
|
||||
@@ -161,56 +310,71 @@ function UAParser (uastring) {
|
||||
], ['name', 'version'],[
|
||||
|
||||
/(ip[honead]+).*os\s*([\w]+)*\slike\smac/i // iOS
|
||||
], [['name', /.+/g, 'iOS'], ['version', /_/g, '.']], [
|
||||
], [['name', 'iOS'], ['version', /_/g, '.']], [
|
||||
|
||||
/(mac\sos)\sx\s([\w\s\.]+)/i, // Mac OS
|
||||
/(mac\sos\sx)\s?([\w\s\.]+\w)*/i, // Mac OS
|
||||
], ['name', ['version', /_/g, '.']], [
|
||||
|
||||
// Other
|
||||
/(macintosh|unix|minix|beos)[\/\s]?()*/i
|
||||
], ['name', 'version']);
|
||||
/(haiku)\s(\w+)/i, // Haiku
|
||||
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|qnx|os\/2|amigaos|morphos)/i,
|
||||
// Plan9/Minix/BeOS/QNX/OS2/AmigaOS/MorphOS
|
||||
/(unix)\s?([\w\.]+)*/i // UNIX
|
||||
], ['name', 'version']
|
||||
]
|
||||
};
|
||||
|
||||
this.getDevice = function (uastring) {
|
||||
var UAParser = function UAParser (uastring) {
|
||||
|
||||
return regxMap(uastring || ua, [
|
||||
var ua = uastring || ((global && global.navigator && global.navigator.userAgent) ? global.navigator.userAgent : "");
|
||||
|
||||
/\((ip[honead]+|playbook);/i, // iPod/iPhone/iPad/PlayBook
|
||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
||||
/(blackberry|benq|nokia|palm(?=\-)|sonyericsson)[\s-]?([\w-]+)*/i, // BenQ/Nokia/Palm/Sony-Ericsson
|
||||
/(hp)\s([\w\s]+)/i, // HP iPAQ
|
||||
/(hp).+(touchpad)/i, // HP TouchPad
|
||||
/(kindle)\/([\w\.]+)/i, // Kindle
|
||||
/(lg)[e;\s-]+(\w+)*/i, // LG
|
||||
/(nintendo|playstation)\s([wids3portable]+)/i // Nintendo/Playstation
|
||||
], ['name', 'version'], [
|
||||
|
||||
/(htc)[;_\s-]+([\w\s]+(?=\))|[\w]+)*/i, // HTC
|
||||
/(zte)-([\w]+)*/i
|
||||
], ['name', ['version', /_/g, ' ']], [
|
||||
|
||||
/\s(milestone|mz601|droid[2x]?|xoom)[globa\s]*\sbuild\//i, // Motorola
|
||||
/mot[\s-]?(\w+)*/i
|
||||
], [['name', 'Motorola'], 'version'], [
|
||||
|
||||
/(s[cgp]h-\w+|gt-\w+|galaxy\snexus)/i, // Samsung
|
||||
/sam[sung]*[\s-]*(\w+-?[\w-]*)*/i,
|
||||
/sec-(sgh\w+)/i
|
||||
], [['name', 'Samsung'], 'version'], [
|
||||
|
||||
/sie-(\w+)*/i // Siemens
|
||||
], [['name', 'Siemens'], 'version']);
|
||||
};
|
||||
|
||||
this.setUA = function (uastring) {
|
||||
ua = uastring || ua;
|
||||
return this.result = {
|
||||
browser : this.getBrowser(),
|
||||
engine : this.getEngine(),
|
||||
os : this.getOS(),
|
||||
device : this.getDevice()
|
||||
this.getBrowser = function () {
|
||||
return mapper.regex.apply(this, regexes.browser);
|
||||
};
|
||||
|
||||
this.getDevice = function () {
|
||||
return mapper.regex.apply(this, regexes.device);
|
||||
};
|
||||
|
||||
this.getEngine = function () {
|
||||
return mapper.regex.apply(this, regexes.engine);
|
||||
};
|
||||
|
||||
this.getOS = function () {
|
||||
return mapper.regex.apply(this, regexes.os);
|
||||
};
|
||||
|
||||
this.getResult = function() {
|
||||
return {
|
||||
browser : this.getBrowser(),
|
||||
engine : this.getEngine(),
|
||||
os : this.getOS(),
|
||||
device : this.getDevice()
|
||||
};
|
||||
};
|
||||
|
||||
this.getUA = function() {
|
||||
return ua;
|
||||
};
|
||||
|
||||
this.setUA = function (uastring) {
|
||||
ua = uastring;
|
||||
return this;
|
||||
};
|
||||
|
||||
this.setUA(ua);
|
||||
};
|
||||
|
||||
this.setUA(ua);
|
||||
};
|
||||
// check js environment
|
||||
if (typeof exports !== 'undefined' && !/\[object\s[DOM]*Window\]/.test(global.toString())) {
|
||||
// nodejs env
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
exports = module.exports = UAParser;
|
||||
}
|
||||
exports.UAParser = UAParser;
|
||||
} else {
|
||||
// browser env
|
||||
global['UAParser'] = UAParser;
|
||||
}
|
||||
})(this);
|
||||
|
||||
7
ua-parser.min.js
vendored
Normal file
7
ua-parser.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user