mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-19 00:42:28 +03:00
Compare commits
86 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
615d6a2034 | ||
|
|
40ac5c5bc3 | ||
|
|
3eb1c1c352 | ||
|
|
217cef226a | ||
|
|
a5e4b7bf72 | ||
|
|
8aaf7db771 | ||
|
|
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 | ||
|
|
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
|
||||||
73
package.json
73
package.json
@@ -1,40 +1,63 @@
|
|||||||
{
|
{
|
||||||
"title" : "UA-Parser.js",
|
"title": "UA-Parser.JS",
|
||||||
"name" : "ua-parser-js",
|
"name": "ua-parser-js",
|
||||||
"version" : "0.1.2",
|
"version": "0.5.15",
|
||||||
"author" : {
|
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||||
"name" : "Faisal Salman",
|
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||||
"email" : "fyzlman@gmail.com",
|
"keywords": [
|
||||||
"url" : "http://faisalman.com"
|
|
||||||
},
|
|
||||||
"description" : "Lightweight JavaScript-based user-agent parser",
|
|
||||||
"keywords" : [
|
|
||||||
"user-agent",
|
"user-agent",
|
||||||
"parser",
|
"parser",
|
||||||
"browser"
|
"browser",
|
||||||
|
"engine",
|
||||||
|
"os",
|
||||||
|
"device"
|
||||||
],
|
],
|
||||||
"homepage" : "http://faisalman.github.com/ua-parser-js",
|
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
"Faisal Salman <fyzlman@gmail.com>",
|
||||||
"name" : "Faisal Salman",
|
"Christopher De Cairos <chris.decairos@gmail.com>",
|
||||||
"email" : "fyzlman@gmail.com"
|
"John Tantalo <john.tantalo@gmail.com>",
|
||||||
}
|
"Jon Buckley <jon@jbuckley.ca>",
|
||||||
|
"Lee Treveil <leetreveil@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": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type" : "git",
|
"type": "git",
|
||||||
"url" : "https://github.com/faisalman/ua-parser-js.git"
|
"url": "https://github.com/faisalman/ua-parser-js.git"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"licenses" : [
|
"repository" :
|
||||||
{
|
{
|
||||||
"type" : "GPLv2",
|
"type": "git",
|
||||||
"url" : "http://www.gnu.org/licenses/gpl-2.0.html"
|
"url": "https://github.com/faisalman/ua-parser-js.git"
|
||||||
|
},
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "GPLv2",
|
||||||
|
"url": "http://www.gnu.org/licenses/gpl-2.0.html"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type" : "MIT",
|
"type": "MIT",
|
||||||
"url" : "http://www.opensource.org/licenses/mit-license.php"
|
"url": "http://www.opensource.org/licenses/mit-license.php"
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"lib": "."
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"repository": "git://github.com/faisalman/ua-parser-js.git"
|
||||||
}
|
}
|
||||||
|
|||||||
113
readme.md
113
readme.md
@@ -1,21 +1,28 @@
|
|||||||
# UA-Parser.js
|
# UA-Parser.JS
|
||||||
|
|
||||||
JavaScript-based user-agent 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
|
||||||
* License : GPLv2
|
* License : GPLv2 & MIT
|
||||||
|
|
||||||
## Features
|
## 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 with relatively lightweight footprint (~7KB minified / ~3KB gzipped).
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
||||||
* `getBrowser([uastring])`
|
* `getBrowser()`
|
||||||
* `getEngine([uastring])`
|
* `getDevice()`
|
||||||
* `getOS([uastring])`
|
* `getEngine()`
|
||||||
|
* `getOS()`
|
||||||
|
* `getResult()`
|
||||||
|
* `getUA()`
|
||||||
* `setUA(uastring)`
|
* `setUA(uastring)`
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
@@ -24,9 +31,10 @@ Get detailed type and version of web browser, layout engine, and operating syste
|
|||||||
<script type="text/javascript" src="ua-parser.js"></script>
|
<script type="text/javascript" src="ua-parser.js"></script>
|
||||||
<script type="text/javascript">
|
<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
|
var parser = new UAParser();
|
||||||
|
|
||||||
console.log(p.result);
|
// 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:
|
/// this will print an object structured like this:
|
||||||
{
|
{
|
||||||
@@ -42,30 +50,91 @@ Get detailed type and version of web browser, layout engine, and operating syste
|
|||||||
os: {
|
os: {
|
||||||
name: "",
|
name: "",
|
||||||
version: ""
|
version: ""
|
||||||
|
},
|
||||||
|
device: {
|
||||||
|
model: "",
|
||||||
|
type: "",
|
||||||
|
vendor: ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// let's test a custom user-agent string as an example
|
// 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(parser.getResult().browser); // {name: "Chromium", major: "15", version: "15.0.874.106"}
|
||||||
console.log(p.result.engine); // {name: "AppleWebKit", version: "535.2"}
|
console.log(parser.getResult().device); // {model: undefined, type: undefined, vendor: undefined}
|
||||||
console.log(p.result.os); // {name: "Ubuntu", version: "11.10"}
|
console.log(parser.getResult().engine); // {name: "WebKit", 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>
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using requirejs
|
||||||
|
|
||||||
|
If you're using requirejs, you can load UA-Parser like any other module.
|
||||||
|
|
||||||
|
```js
|
||||||
|
require(['ua-parser'], function(UAParser) {
|
||||||
|
var parser = new UAParser();
|
||||||
|
console.log(parser.getResult());
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
## 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); // "WebKit"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Using jQuery
|
||||||
|
|
||||||
|
If you're using jQuery, `$.ua` object will be created automatically based on container's user-agent. Use `$.ua.get()` / `$.ua.set(uastring)` to get/set user-agent. In case you need, `UAParser` constructor 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"
|
||||||
|
console.log($.ua.get()); // "Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Sprint APA7373KT Build/GRJ22) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0"
|
||||||
|
|
||||||
|
// reset to custom user-agent
|
||||||
|
$.ua.set('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>>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
modify it under the terms of the GNU General Public License
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
as published by the Free Software Foundation; either version 2
|
the Software without restriction, including without limitation the rights to use,
|
||||||
of the License, or (at your option) any later version.
|
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,
|
The above copyright notice and this permission notice shall be included in all
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
copies or substantial portions of the Software.
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|||||||
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.15",
|
||||||
|
"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"
|
||||||
|
}
|
||||||
511
ua-parser.js
511
ua-parser.js
@@ -1,210 +1,401 @@
|
|||||||
// UA-Parser.js v0.2.0
|
// UA-Parser.JS v0.5.15
|
||||||
// Lightweight JavaScript-based user-agent 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
|
||||||
// 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 EMPTY = '',
|
||||||
var regxMap = function (ua) {
|
FUNC = 'function',
|
||||||
var result;
|
UNDEF = 'undefined',
|
||||||
var i, j, k, l;
|
OBJ = 'object',
|
||||||
for (i = 1; i < arguments.length; i += 2) {
|
MAJOR = 'major',
|
||||||
var regex = arguments[i];
|
MODEL = 'model',
|
||||||
var props = arguments[i + 1];
|
NAME = 'name',
|
||||||
var isMatchFound = false;
|
TYPE = 'type',
|
||||||
for (j = 0; j < regex.length; j++) {
|
VENDOR = 'vendor',
|
||||||
var match = regex[j].exec(ua);
|
VERSION = 'version',
|
||||||
//console.log(match);
|
CONSOLE = 'console',
|
||||||
if (!!match) {
|
MOBILE = 'mobile',
|
||||||
|
TABLET = 'tablet';
|
||||||
|
|
||||||
|
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 === UNDEF) {
|
||||||
result = {};
|
result = {};
|
||||||
l = 1;
|
|
||||||
for (k = 0; k < props.length; k++) {
|
for (k = 0; k < props.length; k++) {
|
||||||
if (typeof props[k] === 'object' && props[k].length === 2) {
|
if (typeof props[k] === OBJ) {
|
||||||
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') {
|
|
||||||
result[props[k][0]] = undefined;
|
result[props[k][0]] = undefined;
|
||||||
} else {
|
} else {
|
||||||
result[props[k]] = undefined;
|
result[props[k]] = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.getUA().toString() === EMPTY) {
|
||||||
|
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] === OBJ && props[k].length === 2) {
|
||||||
|
result[props[k][0]] = props[k][1];
|
||||||
|
} else if (typeof props[k] === OBJ && props[k].length === 3) {
|
||||||
|
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;
|
||||||
|
} else {
|
||||||
|
result[props[k][0]] = m ? m.replace(props[k][1], props[k][2]) : undefined;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return result;
|
result[props[k]] = m ? m : undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!!l) break; // break the loop immediately if match found
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
|
string : function (str, map) {
|
||||||
|
|
||||||
|
for (var i in map) {
|
||||||
|
if (map.hasOwnProperty(i)) {
|
||||||
|
if (typeof map[i] === OBJ && 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() === UNDEF) ? undefined : i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
||||||
|
return (i.toString() === UNDEF) ? undefined : i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var mapper = {
|
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' : '/'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
device : {
|
||||||
|
sprint : {
|
||||||
|
model : {
|
||||||
|
'Evo Shift 4G' : '7373KT'
|
||||||
|
},
|
||||||
|
vendor : {
|
||||||
|
'HTC' : 'APA',
|
||||||
|
'Sprint' : 'Sprint'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
os : {
|
os : {
|
||||||
win: function (str, match) {
|
windows : {
|
||||||
switch (match.toLowerCase()) {
|
version : {
|
||||||
case 'nt 5.0':
|
'ME' : '4.90',
|
||||||
return '2000';
|
'NT 3.11' : 'NT3.51',
|
||||||
case 'nt 5.1':
|
'NT 4.0' : 'NT4.0',
|
||||||
case 'nt 5.2':
|
'2000' : 'NT 5.0',
|
||||||
return 'XP';
|
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||||
case 'nt 6.0':
|
'Vista' : 'NT 6.0',
|
||||||
return 'Vista';
|
'7' : 'NT 6.1',
|
||||||
case 'nt 6.1':
|
'8' : 'NT 6.2',
|
||||||
return '7';
|
'RT' : 'ARM'
|
||||||
case 'nt 6.2':
|
}
|
||||||
return '8';
|
|
||||||
default:
|
|
||||||
return match;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getBrowser = function (uastring) {
|
var regexes = {
|
||||||
|
|
||||||
return regxMap(uastring || ua, [
|
browser : [[
|
||||||
|
|
||||||
// Mixed
|
|
||||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
|
||||||
/(lunascape|maxthon|netfront|jasmine)[\/\s]?((\d+)?[\w\.]+)/i, // Lunascape/Maxthon/Netfront/Jasmine
|
|
||||||
|
|
||||||
// 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).*\/((\d+)?[\w\.]+)/i, // Opera
|
/(opera).+version\/((\d+)?[\w\.]+)/i, // Opera > 9.80
|
||||||
|
/(opera)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||||
|
|
||||||
|
], [NAME, VERSION, MAJOR], [
|
||||||
|
|
||||||
|
/\s(opr)\/((\d+)?[\w\.]+)/i // Opera Webkit
|
||||||
|
], [[NAME, 'Opera'], VERSION, MAJOR], [
|
||||||
|
|
||||||
|
// Mixed
|
||||||
|
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||||
|
/(lunascape|maxthon|netfront|jasmine|blazer)[\/\s]?((\d+)?[\w\.]+)*/i,
|
||||||
|
// Lunascape/Maxthon/Netfront/Jasmine/Blazer
|
||||||
|
|
||||||
// Trident based
|
// 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
|
/ms(ie)\s((\d+)?[\w\.]+)/i, // Internet Explorer
|
||||||
|
|
||||||
// Webkit/KHTML based
|
// Webkit/KHTML based
|
||||||
/(chromium|flock|rockmelt|midori|epiphany)\/((\d+)?[\w\.]+)/i, // Chromium/Flock/RockMelt/Midori/Epiphany
|
/(rekonq)((?:\/)[\w\.]+)*/i, // Rekonq
|
||||||
/(chrome|omniweb|arora|dolfin)\/((\d+)?[\w\.]+)/i, // Chrome/OmniWeb/Arora/Dolphin
|
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||||
], ['name', 'version', 'major'], [
|
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||||
/android.+crmo\/((\d+)?[\w\.]+)/i, // Chrome for Android
|
], [NAME, VERSION, MAJOR], [
|
||||||
], [['name', 'Chrome'], 'version', 'major'], [
|
|
||||||
/(mobile\ssafari|safari|konqueror)\/((\d+)?[\w\.]+)/i, // Safari/Konqueror
|
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||||
/(applewebkit|khtml)\/((\d+)?[\w\.]+)/i,
|
], [[NAME, 'Yandex'], VERSION, MAJOR], [
|
||||||
|
|
||||||
|
/(comodo_dragon)\/((\d+)?[\w\.]+)/i // Comodo Dragon
|
||||||
|
], [[NAME, /_/g, ' '], 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], [
|
||||||
|
|
||||||
|
/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
|
// Gecko based
|
||||||
/(iceweasel|camino|fennec|maemo|minimo)[\/\s]?((\d+)?[\w\.\+]+)/i, // Iceweasel/Camino/Fennec/Maemo/Minimo
|
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||||
/(firefox|seamonkey|netscape|navigator|k-meleon|icecat|iceape)\/((\d+)?[\w\.]+)/i,
|
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||||
// Firefox/SeaMonkey/Netscape/K-Meleon/IceCat/IceApe
|
/(swiftfox)/i, // Swiftfox
|
||||||
/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
/(iceweasel|camino|chimera|fennec|maemo\sbrowser|minimo|conkeror)[\/\s]?((\d+)?[\w\.\+]+)/i,
|
||||||
|
// 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
|
||||||
/(lynx|dillo|icab)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab
|
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||||
], ['name', 'version', 'major']);
|
// UCBrowser/Polaris/Lynx/Dillo/iCab/Doris/Amaya/w3m/NetSurf
|
||||||
};
|
/(links)\s\(((\d+)?[\w\.]+)/i, // Links
|
||||||
|
/(gobrowser)\/?((\d+)?[\w\.]+)*/i, // GoBrowser
|
||||||
|
/(ice\s?browser)\/v?((\d+)?[\w\._]+)/i, // ICE Browser
|
||||||
|
/(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]], [
|
||||||
|
|
||||||
|
/(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
|
||||||
|
/(zte)-(\w+)*/i, // ZTE
|
||||||
|
/(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
|
||||||
|
/(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
|
/(presto)\/([\w\.]+)/i, // Presto
|
||||||
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
|
/(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]
|
||||||
};
|
],
|
||||||
|
|
||||||
this.getOS = function (uastring) {
|
os : [[
|
||||||
|
|
||||||
return regxMap(uastring || ua, [
|
|
||||||
|
|
||||||
// Windows based
|
// Windows based
|
||||||
/(windows\sphone\sos|windows)\s+([\w\.\s]+)*/i, // Windows
|
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||||
], ['name', ['version', /(nt\s[\d\.]+)/gi, mapper.os.win]], [
|
/(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
|
||||||
|
], [[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
|
||||||
/(android|symbianos|symbos|webos|palm\os|qnx|bada|rim\stablet\sos)[\/\s-]?([\w\.]+)*/i,
|
], [[NAME, 'BlackBerry'], VERSION], [
|
||||||
// Android/Symbian/WebOS/Palm/QNX/Bada/RIM
|
/(blackberry)\w*\/?([\w\.]+)*/i, // Blackberry
|
||||||
/(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],[
|
||||||
|
/mozilla.+\(mobile;.+gecko.+firefox/i // Firefox OS
|
||||||
|
], [[NAME, 'Firefox OS'], VERSION], [
|
||||||
|
|
||||||
|
// 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]+)/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\.\s]+)*/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', /.+/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, '.']], [
|
], [NAME, [VERSION, /_/g, '.']], [
|
||||||
|
|
||||||
// Other
|
// Other
|
||||||
/(macintosh|unix|minix|beos)[\/\s]?()*/i
|
/(haiku)\s(\w+)/i, // Haiku
|
||||||
], ['name', 'version']);
|
/(aix)\s((\d)(?=\.|\)|\s)[\w\.]*)*/i, // AIX
|
||||||
|
/(macintosh|mac(?=_powerpc)|plan\s9|minix|beos|os\/2|amigaos|morphos|risc\sos)/i,
|
||||||
|
// Plan9/Minix/BeOS/OS2/AmigaOS/MorphOS/RISCOS
|
||||||
|
/(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 : EMPTY);
|
||||||
|
|
||||||
/\((ip[honead]+|playbook);/i, // iPod/iPhone/iPad/PlayBook
|
this.getBrowser = function () {
|
||||||
/(blackberry)[\s-]?(\w+)/i, // BlackBerry
|
return mapper.regex.apply(this, regexes.browser);
|
||||||
/(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) {
|
this.getDevice = function () {
|
||||||
ua = uastring || ua;
|
return mapper.regex.apply(this, regexes.device);
|
||||||
return this.result = {
|
};
|
||||||
|
|
||||||
|
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(),
|
browser : this.getBrowser(),
|
||||||
engine : this.getEngine(),
|
engine : this.getEngine(),
|
||||||
os : this.getOS(),
|
os : this.getOS(),
|
||||||
@@ -212,5 +403,47 @@ function UAParser (uastring) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 !== UNDEF && !/\[object\s[DOM]*Window\]/.test(global.toString())) {
|
||||||
|
// nodejs env
|
||||||
|
if (typeof module !== UNDEF && module.exports) {
|
||||||
|
exports = module.exports = UAParser;
|
||||||
|
}
|
||||||
|
exports.UAParser = UAParser;
|
||||||
|
} else if (typeof define === FUNC && define.amd) {
|
||||||
|
// requirejs env
|
||||||
|
define(function() {
|
||||||
|
return UAParser;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// browser env
|
||||||
|
global.UAParser = UAParser;
|
||||||
|
// jQuery specific
|
||||||
|
if (typeof global.jQuery !== UNDEF) {
|
||||||
|
var parser = new UAParser();
|
||||||
|
global.jQuery.ua = parser.getResult();
|
||||||
|
global.jQuery.ua.get = function() {
|
||||||
|
return parser.getUA();
|
||||||
|
};
|
||||||
|
global.jQuery.ua.set = function(uastring) {
|
||||||
|
parser.setUA(uastring);
|
||||||
|
var result = parser.getResult();
|
||||||
|
for (var prop in result) {
|
||||||
|
global.jQuery.ua[prop] = result[prop];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})(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