mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-16 23:21:52 +03:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0109c76858 | ||
|
|
d1120a4d5d | ||
|
|
204345a8bf | ||
|
|
a20d8f7052 | ||
|
|
9a90d932ce | ||
|
|
cea29e5c1b | ||
|
|
e0b6ae65e5 | ||
|
|
59714adea3 | ||
|
|
249dcf0c80 | ||
|
|
b99546072d | ||
|
|
4e911cec88 | ||
|
|
f1fa7f38a1 | ||
|
|
a6610646ca | ||
|
|
4703137b79 | ||
|
|
541dfea86d | ||
|
|
35b410009f | ||
|
|
5e84ab7b82 | ||
|
|
816b5d22b4 | ||
|
|
29bb0797a6 | ||
|
|
52897acf24 | ||
|
|
9ccc32ce5a | ||
|
|
4a65f1b3f8 | ||
|
|
be4d8a10d1 | ||
|
|
6d183003b3 | ||
|
|
a2b4f6d5c5 | ||
|
|
3f98036d50 | ||
|
|
d1d4e0a7a0 | ||
|
|
3ecb3fbea2 | ||
|
|
5cc6bf78a5 | ||
|
|
08c7a84407 | ||
|
|
ea9d093f0d | ||
|
|
1f4befe4c3 | ||
|
|
d35fb44066 | ||
|
|
9a6479193a | ||
|
|
527ba70cf4 |
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
|
||||||
17
package.json
17
package.json
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"title": "UA-Parser.JS",
|
"title": "UA-Parser.JS",
|
||||||
"name": "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version": "0.4.8",
|
"version": "0.5.11",
|
||||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"user agent",
|
"user-agent",
|
||||||
"parser",
|
"parser",
|
||||||
"browser",
|
"browser",
|
||||||
"engine",
|
"engine",
|
||||||
@@ -14,9 +14,20 @@
|
|||||||
],
|
],
|
||||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
"Faisal Salman <fyzlman@gmail.com>"
|
"Faisal Salman <fyzlman@gmail.com>",
|
||||||
|
"Christopher De Cairos <chris.decairos@gmail.com>",
|
||||||
|
"John Tantalo <john.tantalo@gmail.com>",
|
||||||
|
"Lee Treveil <leetreveil@gmail.com>"
|
||||||
],
|
],
|
||||||
"main": "ua-parser",
|
"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": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
38
readme.md
38
readme.md
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
Lightweight JavaScript-based User-Agent string parser
|
Lightweight JavaScript-based User-Agent string parser
|
||||||
|
|
||||||
|
[](https://travis-ci.org/faisalman/ua-parser-js)
|
||||||
|
|
||||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||||
* Home : http://faisalman.github.com/ua-parser-js
|
* Home : http://faisalman.github.com/ua-parser-js
|
||||||
* Source : https://github.com/faisalman/ua-parser-js
|
* Source : https://github.com/faisalman/ua-parser-js
|
||||||
@@ -9,7 +11,9 @@ Lightweight JavaScript-based User-Agent string parser
|
|||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string.
|
Extract detailed type of web browser, layout engine, operating system, and device purely from user-agent string with relatively lightweight footprint (~7KB minified / ~3KB gzipped).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ Extract detailed type of web browser, layout engine, operating system, and devic
|
|||||||
|
|
||||||
console.log(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
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().device); // {model: undefined, type: undefined, vendor: undefined}
|
||||||
console.log(parser.getResult().engine); // {name: "AppleWebKit", version: "535.2"}
|
console.log(parser.getResult().engine); // {name: "WebKit", version: "535.2"}
|
||||||
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
console.log(parser.getResult().os); // {name: "Ubuntu", version: "11.10"}
|
||||||
|
|
||||||
// let's take another test please
|
// let's take another test please
|
||||||
@@ -73,6 +77,10 @@ Extract detailed type of web browser, layout engine, operating system, and devic
|
|||||||
|
|
||||||
## Using node.js
|
## Using node.js
|
||||||
|
|
||||||
|
```sh
|
||||||
|
$ npm install ua-parser-js
|
||||||
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var UAParser = require('ua-parser');
|
var UAParser = require('ua-parser');
|
||||||
var parser = new UAParser();
|
var parser = new UAParser();
|
||||||
@@ -80,12 +88,34 @@ var uaString = 'Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWe
|
|||||||
|
|
||||||
console.log(parser.setUA(uaString).getDevice().model); // "PlayBook"
|
console.log(parser.setUA(uaString).getDevice().model); // "PlayBook"
|
||||||
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
console.log(parser.getOS()) // {name: "RIM Tablet OS", version: "1.0.0"}
|
||||||
console.log(parser.getEngine().name); // "AppleWebKit"
|
console.log(parser.getEngine().name); // "WebKit"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using jQuery
|
||||||
|
|
||||||
|
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. To change different user-agent use `$.setUA(uastring)`. In case you need, `UAParser` is still present in global though.
|
||||||
|
|
||||||
|
```js
|
||||||
|
// In browser with default user-agent: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0':
|
||||||
|
|
||||||
|
// Do some tests
|
||||||
|
console.log($.ua.device); // {vendor: "HTC", model: "Evo Shift 4G", type: "mobile"}
|
||||||
|
console.log($.ua.os); // {name: "Android", version: "2.3.4"}
|
||||||
|
console.log($.ua.os.name); // "Android"
|
||||||
|
|
||||||
|
// reset to custom user-agent
|
||||||
|
$.setUA('Mozilla/5.0 (Linux; U; Android 3.0.1; en-us; Xoom Build/HWI69) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13');
|
||||||
|
|
||||||
|
// Test again
|
||||||
|
console.log($.ua.device); // {vendor: "Motorola", model: "Xoom", type: "tablet"}
|
||||||
|
console.log($.ua.engine.name); // "Webkit"
|
||||||
|
console.log($.ua.browser.version); // "4.0"
|
||||||
|
console.log(parseInt($.ua.browser.version.split('.')[0], 10)); // 4
|
||||||
```
|
```
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © 2012 Faisalman <<fyzlman@gmail.com>>
|
Copyright © 2012-2013 Faisalman <<fyzlman@gmail.com>>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
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
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
|||||||
31
ua-parser-js.jquery.json
Normal file
31
ua-parser-js.jquery.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"title": "UA-Parser.JS",
|
||||||
|
"name": "ua-parser-js",
|
||||||
|
"version": "0.5.11",
|
||||||
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
|
"keywords": [
|
||||||
|
"user-agent",
|
||||||
|
"parser",
|
||||||
|
"browser",
|
||||||
|
"engine",
|
||||||
|
"os",
|
||||||
|
"device"
|
||||||
|
],
|
||||||
|
"homepage": "https://faisalman.github.com/ua-parser-js",
|
||||||
|
"author": {
|
||||||
|
"name": "Faisal Salman",
|
||||||
|
"email": "fyzlman@gmail.com"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jquery": ">=1.5"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "MIT",
|
||||||
|
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bugs": "https://github.com/faisalman/ua-parser-js/issues",
|
||||||
|
"docs": "https://github.com/faisalman/ua-parser-js",
|
||||||
|
"download": "https://raw.github.com/faisalman/ua-parser-js/master/ua-parser.min.js"
|
||||||
|
}
|
||||||
269
ua-parser.js
269
ua-parser.js
@@ -1,14 +1,28 @@
|
|||||||
// UA-Parser.JS v0.4.8
|
// UA-Parser.JS v0.5.11
|
||||||
// Lightweight JavaScript-based User-Agent string parser
|
// Lightweight JavaScript-based User-Agent string parser
|
||||||
// https://github.com/faisalman/ua-parser-js
|
// https://github.com/faisalman/ua-parser-js
|
||||||
//
|
//
|
||||||
// Copyright © 2012 Faisalman
|
// Copyright © 2012-2013 Faisalman
|
||||||
// Dual licensed under GPLv2 & MIT
|
// Dual licensed under GPLv2 & MIT
|
||||||
|
|
||||||
(function (undefined) {
|
(function (global, undefined) {
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var EMPTY = '',
|
||||||
|
FUNC = 'function',
|
||||||
|
UNDEF = 'undefined',
|
||||||
|
OBJ = 'object',
|
||||||
|
MAJOR = 'major',
|
||||||
|
MODEL = 'model',
|
||||||
|
NAME = 'name',
|
||||||
|
TYPE = 'type',
|
||||||
|
VENDOR = 'vendor',
|
||||||
|
VERSION = 'version',
|
||||||
|
CONSOLE = 'console',
|
||||||
|
MOBILE = 'mobile',
|
||||||
|
TABLET = 'tablet';
|
||||||
|
|
||||||
var mapper = {
|
var mapper = {
|
||||||
|
|
||||||
regex : function () {
|
regex : function () {
|
||||||
@@ -22,16 +36,16 @@
|
|||||||
props = args[i + 1]; // even sequence (1,3,5,..)
|
props = args[i + 1]; // even sequence (1,3,5,..)
|
||||||
|
|
||||||
// construct object barebones
|
// construct object barebones
|
||||||
if (typeof result === 'undefined') {
|
if (typeof result === UNDEF) {
|
||||||
result = {};
|
result = {};
|
||||||
for (k = 0; k < props.length; k++) {
|
for (k = 0; k < props.length; k++) {
|
||||||
if (typeof props[k] === 'object') {
|
if (typeof props[k] === OBJ) {
|
||||||
result[props[k][0]] = undefined;
|
result[props[k][0]] = undefined;
|
||||||
} else {
|
} else {
|
||||||
result[props[k]] = undefined;
|
result[props[k]] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.getUA().toString() === '') {
|
if (this.getUA().toString() === EMPTY) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,10 +56,10 @@
|
|||||||
if (!!l) {
|
if (!!l) {
|
||||||
for (k = 0; k < props.length; k++) {
|
for (k = 0; k < props.length; k++) {
|
||||||
m = l[k + 1];
|
m = l[k + 1];
|
||||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
if (typeof props[k] === OBJ && props[k].length === 2) {
|
||||||
result[props[k][0]] = props[k][1];
|
result[props[k][0]] = props[k][1];
|
||||||
} else if (typeof props[k] === 'object' && props[k].length === 3) {
|
} else if (typeof props[k] === OBJ && props[k].length === 3) {
|
||||||
if (typeof props[k][1] === 'function' && !(props[k][1].exec && props[k][1].test)) {
|
if (typeof props[k][1] === FUNC && !(props[k][1].exec && props[k][1].test)) {
|
||||||
result[props[k][0]] = m ? props[k][1].call(this, m, props[k][2]) : undefined;
|
result[props[k][0]] = m ? props[k][1].call(this, m, props[k][2]) : undefined;
|
||||||
} else {
|
} else {
|
||||||
result[props[k][0]] = m ? m.replace(props[k][1], props[k][2]) : undefined;
|
result[props[k][0]] = m ? m.replace(props[k][1], props[k][2]) : undefined;
|
||||||
@@ -67,14 +81,14 @@
|
|||||||
|
|
||||||
for (var i in map) {
|
for (var i in map) {
|
||||||
if (map.hasOwnProperty(i)) {
|
if (map.hasOwnProperty(i)) {
|
||||||
if (typeof map[i] === 'object' && map[i].length > 0) {
|
if (typeof map[i] === OBJ && map[i].length > 0) {
|
||||||
for (var j = 0; j < map[i].length; j++) {
|
for (var j = 0; j < map[i].length; j++) {
|
||||||
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) {
|
if (str.toLowerCase().indexOf(map[i][j].toLowerCase()) !== -1) {
|
||||||
return (i.toString() === 'undefined') ? undefined : i;
|
return (i.toString() === UNDEF) ? undefined : i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
||||||
return (i.toString() === 'undefined') ? undefined : i;
|
return (i.toString() === UNDEF) ? undefined : i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,6 +97,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var maps = {
|
var maps = {
|
||||||
|
|
||||||
browser : {
|
browser : {
|
||||||
oldsafari : {
|
oldsafari : {
|
||||||
major : {
|
major : {
|
||||||
@@ -102,6 +117,19 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
device : {
|
||||||
|
sprint : {
|
||||||
|
model : {
|
||||||
|
'Evo Shift 4G' : '7373KT'
|
||||||
|
},
|
||||||
|
vendor : {
|
||||||
|
'HTC' : 'APA',
|
||||||
|
'Sprint' : 'Sprint'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
os : {
|
os : {
|
||||||
windows : {
|
windows : {
|
||||||
version : {
|
version : {
|
||||||
@@ -112,7 +140,8 @@
|
|||||||
'XP' : ['NT 5.1', 'NT 5.2'],
|
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||||
'Vista' : 'NT 6.0',
|
'Vista' : 'NT 6.0',
|
||||||
'7' : 'NT 6.1',
|
'7' : 'NT 6.1',
|
||||||
'8' : 'NT 6.2'
|
'8' : 'NT 6.2',
|
||||||
|
'RT' : 'ARM'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,13 +153,13 @@
|
|||||||
|
|
||||||
// Presto based
|
// Presto based
|
||||||
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
/(opera\smini)\/((\d+)?[\w\.-]+)/i, // Opera Mini
|
||||||
/(opera\smobi)\/((\d+)?[\w\.-]+)/i, // Opera Mobile
|
/(opera\s[mobiletab]+).+version\/((\d+)?[\w\.-]+)/i, // Opera Mobi/Tablet
|
||||||
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||||
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||||
|
|
||||||
// Mixed
|
// Mixed
|
||||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||||
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)/i,
|
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,
|
||||||
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
||||||
|
|
||||||
// Trident based
|
// Trident based
|
||||||
@@ -139,179 +168,210 @@
|
|||||||
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||||
|
|
||||||
// Webkit/KHTML based
|
// Webkit/KHTML based
|
||||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|s60|series60|ovibrowser|bolt)\/((\d+)?[\w\.]+)/i,
|
/(rekonq)((?:\/)[\w\.]+)*/i, // Rekonq
|
||||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/S60/Bolt
|
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||||
/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i,
|
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||||
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
], [NAME, VERSION, MAJOR], [
|
||||||
], ['name', 'version', 'major'], [
|
|
||||||
|
|
||||||
/(dolfin)\/((\d+)?[\w\.]+)/i // Dolphin
|
|
||||||
], [['name', 'Dolphin'], 'version', 'major'], [
|
|
||||||
|
|
||||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||||
], [['name', 'Yandex'], 'version', 'major'], [
|
], [[NAME, 'Yandex'], VERSION, MAJOR], [
|
||||||
|
|
||||||
/(?:android.+(crmo|crios))\/((\d+)?[\w\.]+)/i, // Chrome for Android/iOS
|
/(comodo_dragon)\/((\d+)?[\w\.]+)/i // Comodo Dragon
|
||||||
], [['name', 'Chrome'], 'version', 'major'], [
|
], [[NAME, /_/g, ' '], VERSION, MAJOR], [
|
||||||
|
|
||||||
/version\/((\d+)?[\w\.]+).+(mobile\s?safari|safari)/i // Safari & Safari Mobile
|
/(chrome|omniweb|arora|[tizenoka]{5}\s?browser)\/v?((\d+)?[\w\.]+)/i
|
||||||
], ['version', 'major', 'name'], [
|
// Chrome/OmniWeb/Arora/Tizen/Nokia
|
||||||
|
], [NAME, VERSION, MAJOR], [
|
||||||
/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]], [
|
/(dolfin)\/((\d+)?[\w\.]+)/i // Dolphin
|
||||||
|
], [[NAME, 'Dolphin'], VERSION, MAJOR], [
|
||||||
|
|
||||||
|
/((?:android.+)crmo|crios)\/((\d+)?[\w\.]+)/i // Chrome for Android/iOS
|
||||||
|
], [[NAME, 'Chrome'], VERSION, MAJOR], [
|
||||||
|
|
||||||
|
/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
|
/(konqueror)\/((\d+)?[\w\.]+)/i, // Konqueror
|
||||||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i,
|
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i
|
||||||
|
], [NAME, VERSION, MAJOR], [
|
||||||
|
|
||||||
// Gecko based
|
// Gecko based
|
||||||
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||||
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo
|
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||||
/(firefox|seamonkey|netscape|navigator|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.]+)/i,
|
/(swiftfox)/i, // Swiftfox
|
||||||
// Firefox/SeaMonkey/Netscape/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||||
/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
// Iceweasel/Camino/Chimera/Fennec/Maemo/Minimo/Conkeror
|
||||||
|
/(firefox|seamonkey|k-meleon|icecat|iceape|firebird|phoenix)\/((\d+)?[\w\.-]+)/i,
|
||||||
|
// Firefox/SeaMonkey/K-Meleon/IceCat/IceApe/Firebird/Phoenix
|
||||||
|
/(mozilla)\/((\d+)?[\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
/(uc\s?browser)\/?((\d+)?[\w\.]+)/i, // UCBrowser
|
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||||
/(lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab/Doris
|
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf
|
||||||
/(gobrowser)\/?[\d\.]*/i, // GoBrowser
|
/(links)\s\(((\d+)?[\w\.]+)/i, // Links
|
||||||
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i
|
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||||
// Mosaic
|
/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i, // ICE Browser
|
||||||
], ['name', 'version', 'major']
|
/(mosaic)[\/\s]((\d+)?[\w\.]+)/i // Mosaic
|
||||||
|
], [NAME, VERSION, MAJOR]
|
||||||
],
|
],
|
||||||
|
|
||||||
device : [[
|
device : [[
|
||||||
|
|
||||||
/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
|
/\((ipad|playbook);[\w\s\);-]+(rim|apple)/i // iPad/PlayBook
|
||||||
], ['model', 'vendor', ['type', 'Tablet']], [
|
], [MODEL, VENDOR, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/(hp).+(touchpad)/i, // HP TouchPad
|
/(hp).+(touchpad)/i, // HP TouchPad
|
||||||
/(kindle)\/([\w\.]+)/i, // Kindle
|
/(kindle)\/([\w\.]+)/i, // Kindle
|
||||||
/\s(nook)[\w\s]+build\/(\w+)/i, // Nook
|
/\s(nook)[\w\s]+build\/(\w+)/i, // Nook
|
||||||
/(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
|
/(dell)\s(strea[kpr\s\d]*[\dko])/i // Dell Streak
|
||||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/\((ip[honed]+);.+(apple)/i // iPod/iPhone
|
/\((ip[honed]+);.+(apple)/i // iPod/iPhone
|
||||||
], ['model', 'vendor', ['type', 'Mobile']], [
|
], [MODEL, VENDOR, [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
||||||
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i,
|
/(blackberry|benq|palm(?=\-)|sonyericsson|acer|asus|dell|huawei|meizu|motorola)[\s_-]?([\w-]+)*/i,
|
||||||
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Huawei/Meizu/Motorola
|
// BenQ/Palm/Sony-Ericsson/Acer/Asus/Dell/Huawei/Meizu/Motorola
|
||||||
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
||||||
/(asus)-?(\w+)/i // Asus
|
/(asus)-?(\w+)/i // Asus
|
||||||
], ['vendor', 'model', ['type', 'Mobile']], [
|
], [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
|
/android.+((transfo[prime\s]{4,10}\s\w+|eeepc|slider\s\w+))/i // Asus Tablets
|
||||||
], [['vendor', 'Asus'], 'model', ['type', 'Tablet']], [
|
], [[VENDOR, 'Asus'], MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
||||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
/(nintendo|playstation)\s([wids3portablev]+)/i // Nintendo/Playstation
|
||||||
], ['vendor', 'model', ['type', 'Console']], [
|
], [VENDOR, MODEL, [TYPE, CONSOLE]], [
|
||||||
|
|
||||||
|
/(sprint\s(\w+))/i // Sprint Phones
|
||||||
|
], [[VENDOR, mapper.string, maps.device.sprint.vendor], [MODEL, mapper.string, maps.device.sprint.model], [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
/(htc)[;_\s-]+([\w\s]+(?=\))|\w+)*/i, // HTC
|
||||||
/(zte)-(\w+)*/i // ZTE
|
/(zte)-(\w+)*/i, // ZTE
|
||||||
], ['vendor', ['model', /_/g, ' '], ['type', 'Mobile']], [
|
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|;\ssony)[_\s-]?([\w-]+)*/i
|
||||||
|
// Alcatel/GeeksPhone/Huawei/Lenovo/Nexian/Panasonic/Sony
|
||||||
|
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
/\s((milestone|droid[2x]?))[globa\s]*\sbuild\//i, // Motorola
|
||||||
/(mot)[\s-]?(\w+)*/i
|
/(mot)[\s-]?(\w+)*/i
|
||||||
], [['vendor', 'Motorola'], 'model', ['type', 'Mobile']], [
|
], [[VENDOR, 'Motorola'], MODEL, [TYPE, MOBILE]], [
|
||||||
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i
|
/android.+\s((mz60\d|xoom[\s2]{0,2}))\sbuild\//i
|
||||||
], [['vendor', 'Motorola'], 'model', ['type', 'Tablet']], [
|
], [[VENDOR, 'Motorola'], MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/android.+((sch-i[89]0\d|shw-m380s|gt-p\d{4}|gt-n8000|sgh-t8[56]9))/i
|
/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
|
], [[VENDOR, 'Samsung'], MODEL, [TYPE, TABLET]], [ // Samsung
|
||||||
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
/((s[cgp]h-\w+|gt-\w+|galaxy\snexus))/i,
|
||||||
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
/(sam[sung]*)[\s-]*(\w+-?[\w-]*)*/i,
|
||||||
/sec-((sgh\w+))/i
|
/sec-((sgh\w+))/i
|
||||||
], [['vendor', 'Samsung'], 'model', ['type', 'Mobile']], [
|
], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
|
||||||
/(sie)-(\w+)*/i // Siemens
|
/(sie)-(\w+)*/i // Siemens
|
||||||
], [['vendor', 'Siemens'], 'model', ['type', 'Mobile']], [
|
], [[VENDOR, 'Siemens'], MODEL, [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
||||||
/(nokia)[\s_-]?([\w-]+)*/i
|
/(nokia)[\s_-]?([\w-]+)*/i
|
||||||
], [['vendor', 'Nokia'], 'model', ['type', 'Mobile']], [
|
], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer
|
/android\s3\.[\s\w-;]{10}((a\d{3}))/i // Acer
|
||||||
], [['vendor', 'Acer'], 'model', ['type', 'Tablet']], [
|
], [[VENDOR, 'Acer'], MODEL, [TYPE, TABLET]], [
|
||||||
|
|
||||||
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG
|
/android\s3\.[\s\w-;]{10}(lg?)-([06cv9]{3,4})/i // LG
|
||||||
], [['vendor', 'LG'], 'model', ['type', 'Tablet']], [
|
], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
|
||||||
/(lg)[e;\s-\/]+(\w+)*/i
|
/(lg)[e;\s-\/]+(\w+)*/i
|
||||||
], [['vendor', 'LG'], 'model', ['type', 'Mobile']], [
|
], [[VENDOR, 'LG'], MODEL, [TYPE, MOBILE]], [
|
||||||
|
|
||||||
/(mobile|tablet);.+rv\:.+gecko\//i // Unidentifiable
|
/(mobile|tablet);.+rv\:.+gecko\//i // Unidentifiable
|
||||||
], ['type', 'vendor', 'model']
|
], [TYPE, VENDOR, MODEL]
|
||||||
],
|
],
|
||||||
|
|
||||||
engine : [[
|
engine : [[
|
||||||
|
|
||||||
/(presto)\/([\w\.]+)/i, // Presto
|
/(presto)\/([\w\.]+)/i, // Presto
|
||||||
/([aple]*webkit|trident|netfront)\/([\w\.]+)/i, // Webkit/Trident/NetFront
|
/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
|
||||||
/(khtml)\/([\w\.]+)/i // KHTML
|
/(khtml)\/([\w\.]+)/i, // KHTML
|
||||||
], ['name', 'version'], [
|
/(tasman)\s([\w\.]+)/i, // Tasman
|
||||||
|
/(links)\s\(([\w\.]+)/i, // Links
|
||||||
|
/(icab)[\/\s]([2-3]\.[\d\.]+)/i // iCab
|
||||||
|
], [NAME, VERSION], [
|
||||||
|
|
||||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||||
], ['version', 'name']
|
], [VERSION, NAME]
|
||||||
],
|
],
|
||||||
|
|
||||||
os : [[
|
os : [[
|
||||||
|
|
||||||
// Windows based
|
// Windows based
|
||||||
/(windows\sphone\sos|windows\s?[mobile]*)[\s\/]?([ntce\d\.\s]+\w)/i // Windows
|
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||||
], ['name', ['version', mapper.string, maps.os.windows.version]], [
|
/(windows\sphone\sos|windows\smobile|windows)[\s\/]?([ntce\d\.\s]+\w)/i
|
||||||
|
], [NAME, [VERSION, mapper.string, maps.os.windows.version]], [
|
||||||
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
/(win(?=3|9|n)|win\s9x\s)([nt\d\.]+)/i
|
||||||
], [['name', 'Windows'], ['version', mapper.string, maps.os.windows.version]], [
|
], [[NAME, 'Windows'], [VERSION, mapper.string, maps.os.windows.version]], [
|
||||||
|
|
||||||
// Mobile/Embedded OS
|
// Mobile/Embedded OS
|
||||||
/(blackberry).+version\/([\w\.]+)/i, // Blackberry
|
/\((bb)(10);/i // BlackBerry 10
|
||||||
|
], [[NAME, 'BlackBerry'], VERSION], [
|
||||||
|
/(blackberry)\w*\/?([\w\.]+)*/i, // Blackberry
|
||||||
/(tizen)\/([\w\.]+)/i, // Tizen
|
/(tizen)\/([\w\.]+)/i, // Tizen
|
||||||
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i
|
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i
|
||||||
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
||||||
], ['name', 'version'], [
|
], [NAME, VERSION], [
|
||||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||||
], [['name', 'Symbian'], 'version'],[
|
], [[NAME, 'Symbian'], VERSION],[
|
||||||
|
/mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
|
||||||
|
], [[NAME, 'Firefox OS'], VERSION], [
|
||||||
|
|
||||||
/(nintendo|playstation)\s([wids3portable]+)/i, // Nintendo/Playstation
|
// Console
|
||||||
|
/(nintendo|playstation)\s([wids3portablev]+)/i, // Nintendo/Playstation
|
||||||
|
|
||||||
// GNU/Linux based
|
// GNU/Linux based
|
||||||
/(mint)[\/\s\(]?(\w+)*/i, // Mint
|
/(mint)[\/\s\(]?(\w+)*/i, // Mint
|
||||||
/(joli|[kxln]?ubuntu|debian|[open]*suse|gentoo|arch|slackware|fedora|mandriva|centos|pclinuxos|redhat|zenwalk)[\/\s-]?([\w\.-]+)*/i,
|
/(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
|
// Joli/Ubuntu/Debian/SUSE/Gentoo/Arch/Slackware
|
||||||
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk
|
// Fedora/Mandriva/CentOS/PCLinuxOS/RedHat/Zenwalk
|
||||||
/(gnu|linux)\s?([\w\.]+)*/i // Other GNU/Linux
|
/(hurd|linux)\s?([\w\.]+)*/i, // Hurd/Linux
|
||||||
], ['name', 'version'], [
|
/(gnu)\s?([\w\.]+)*/i // GNU
|
||||||
|
], [NAME, VERSION], [
|
||||||
|
|
||||||
/(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
|
/(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
|
||||||
], [['name', 'Chromium OS'], 'version'],[
|
], [[NAME, 'Chromium OS'], VERSION],[
|
||||||
|
|
||||||
// Solaris
|
// Solaris
|
||||||
/(sunos)\s?([\w\.]+\d)*/i // Solaris
|
/(sunos)\s?([\w\.]+\d)*/i // Solaris
|
||||||
], [['name', 'Solaris'], 'version'], [
|
], [[NAME, 'Solaris'], VERSION], [
|
||||||
|
|
||||||
// BSD based
|
// BSD based
|
||||||
/\s(\w*bsd|dragonfly)\s?([\w\.]+)*/i, // FreeBSD/NetBSD/OpenBSD/DragonFly
|
/\s(\w*bsd|dragonfly)\s?([\w\.]+)*/i // FreeBSD/NetBSD/OpenBSD/DragonFly
|
||||||
], ['name', 'version'],[
|
], [NAME, VERSION],[
|
||||||
|
|
||||||
/(ip[honead]+).*os\s*([\w]+)*\slike\smac/i // iOS
|
/(ip[honead]+)(?:.*os\s*([\w]+)*\slike\smac|;\sopera)/i // iOS
|
||||||
], [['name', 'iOS'], ['version', /_/g, '.']], [
|
], [[NAME, 'iOS'], [VERSION, /_/g, '.']], [
|
||||||
|
|
||||||
/(mac\sos\sx)\s?([\d\s\.]+\w)*/i, // Mac OS
|
/(mac\sos\sx)\s?([\w\s\.]+\w)*/i // Mac OS
|
||||||
], ['name', ['version', /_/g, '.']], [
|
], [NAME, [VERSION, /_/g, '.']], [
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
/(haiku)\s(\w+)/i, // Haiku
|
/(haiku)\s(\w+)/i, // Haiku
|
||||||
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||||
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|qnx|os\/2)[\/\s]?()*/i,
|
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos)/i,
|
||||||
// Plan9/Minix/BeOS/QNX/OS2
|
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS
|
||||||
/(unix)\s?([\w\.]+)*/i // UNIX
|
/(unix)\s?([\w\.]+)*/i // UNIX
|
||||||
], ['name', 'version']
|
], [NAME, VERSION]
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
var UAParser = function UAParser (uastring) {
|
var UAParser = function UAParser (uastring) {
|
||||||
|
|
||||||
var ua = uastring || ((window && window.navigator && window.navigator.userAgent) ? window.navigator.userAgent : "");
|
var ua = uastring || ((global && global.navigator && global.navigator.userAgent) ? global.navigator.userAgent : EMPTY);
|
||||||
|
|
||||||
this.getBrowser = function () {
|
this.getBrowser = function () {
|
||||||
return mapper.regex.apply(this, regexes.browser);
|
return mapper.regex.apply(this, regexes.browser);
|
||||||
@@ -350,13 +410,22 @@
|
|||||||
this.setUA(ua);
|
this.setUA(ua);
|
||||||
};
|
};
|
||||||
|
|
||||||
// check whether script is running inside node.js export as module
|
// check js environment
|
||||||
if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') {
|
if (typeof exports !== UNDEF && !/\[object\s[DOM]*Window\]/.test(global.toString())) {
|
||||||
if (typeof module !== 'undefined' && module.exports) {
|
// nodejs env
|
||||||
|
if (typeof module !== UNDEF && module.exports) {
|
||||||
exports = module.exports = UAParser;
|
exports = module.exports = UAParser;
|
||||||
}
|
}
|
||||||
exports.UAParser = UAParser;
|
exports.UAParser = UAParser;
|
||||||
} else {
|
} else {
|
||||||
window['UAParser'] = UAParser;
|
// browser env
|
||||||
|
global.UAParser = UAParser;
|
||||||
|
// jQuery specific
|
||||||
|
if (typeof global.jQuery !== UNDEF) {
|
||||||
|
global.jQuery.ua = new UAParser().getResult();
|
||||||
|
global.jQuery.setUA = function (uastring) {
|
||||||
|
global.jQuery.ua = new UAParser(uastring).getResult();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})();
|
})(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