mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-11-15 22:52:16 +03:00
Compare commits
49 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 | ||
|
|
3fe07487cd | ||
|
|
8030aa33f7 | ||
|
|
99251addfc | ||
|
|
610cdb84ae | ||
|
|
31b386c636 | ||
|
|
b15b48b1bf | ||
|
|
58fe246468 | ||
|
|
e1d3f25bf8 | ||
|
|
4efb13be3e | ||
|
|
bf9fb794d8 | ||
|
|
df815d4109 | ||
|
|
6dcee61a0b | ||
|
|
0288766544 | ||
|
|
7ea79afc2f |
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",
|
||||
"name": "ua-parser-js",
|
||||
"version": "0.4.3",
|
||||
"version": "0.5.11",
|
||||
"author": "Faisal Salman <fyzlman@gmail.com> (http://faisalman.com)",
|
||||
"description": "Lightweight JavaScript-based user-agent string parser",
|
||||
"keywords": [
|
||||
"user agent",
|
||||
"user-agent",
|
||||
"parser",
|
||||
"browser",
|
||||
"engine",
|
||||
@@ -14,9 +14,20 @@
|
||||
],
|
||||
"homepage": "http://github.com/faisalman/ua-parser-js",
|
||||
"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",
|
||||
"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",
|
||||
|
||||
38
readme.md
38
readme.md
@@ -2,6 +2,8 @@
|
||||
|
||||
Lightweight JavaScript-based User-Agent string parser
|
||||
|
||||
[](https://travis-ci.org/faisalman/ua-parser-js)
|
||||
|
||||
* Author : Faisalman <<fyzlman@gmail.com>>
|
||||
* Home : http://faisalman.github.com/ua-parser-js
|
||||
* Source : https://github.com/faisalman/ua-parser-js
|
||||
@@ -9,7 +11,9 @@ Lightweight JavaScript-based User-Agent string parser
|
||||
|
||||
## 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
|
||||
|
||||
@@ -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().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"}
|
||||
|
||||
// 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
|
||||
|
||||
```sh
|
||||
$ npm install ua-parser-js
|
||||
```
|
||||
|
||||
```js
|
||||
var UAParser = require('ua-parser');
|
||||
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.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
|
||||
|
||||
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
|
||||
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"
|
||||
}
|
||||
340
ua-parser.js
340
ua-parser.js
@@ -1,51 +1,65 @@
|
||||
// UA-Parser.JS v0.4.3
|
||||
// UA-Parser.JS v0.5.11
|
||||
// Lightweight JavaScript-based User-Agent string parser
|
||||
// https://github.com/faisalman/ua-parser-js
|
||||
//
|
||||
// Copyright © 2012 Faisalman
|
||||
// Copyright © 2012-2013 Faisalman
|
||||
// Dual licensed under GPLv2 & MIT
|
||||
|
||||
(function (undefined) {
|
||||
(function (global, undefined) {
|
||||
|
||||
'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 = {
|
||||
|
||||
|
||||
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') {
|
||||
if (typeof result === UNDEF) {
|
||||
result = {};
|
||||
for (k = 0; k < props.length; k++) {
|
||||
if (typeof props[k] === 'object') {
|
||||
if (typeof props[k] === OBJ) {
|
||||
result[props[k][0]] = undefined;
|
||||
} else {
|
||||
result[props[k]] = undefined;
|
||||
}
|
||||
}
|
||||
if (this.getUA().toString() === '') {
|
||||
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] === 'object' && props[k].length === 2) {
|
||||
if (typeof props[k] === OBJ && 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') {
|
||||
} 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;
|
||||
@@ -57,24 +71,24 @@
|
||||
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) {
|
||||
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;
|
||||
return (i.toString() === UNDEF) ? undefined : i;
|
||||
}
|
||||
}
|
||||
} else if (str.toLowerCase().indexOf(map[i].toLowerCase()) !== -1) {
|
||||
return i;
|
||||
return (i.toString() === UNDEF) ? undefined : i;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,6 +97,39 @@
|
||||
};
|
||||
|
||||
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 : {
|
||||
windows : {
|
||||
version : {
|
||||
@@ -93,181 +140,241 @@
|
||||
'XP' : ['NT 5.1', 'NT 5.2'],
|
||||
'Vista' : 'NT 6.0',
|
||||
'7' : 'NT 6.1',
|
||||
'8' : 'NT 6.2'
|
||||
'8' : 'NT 6.2',
|
||||
'RT' : 'ARM'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var regexes = {
|
||||
|
||||
browser : [[
|
||||
|
||||
// Presto based
|
||||
/(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)[\/\s]+((\d+)?[\w\.]+)/i, // Opera < 9.80
|
||||
|
||||
|
||||
// Mixed
|
||||
/(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
|
||||
|
||||
|
||||
// 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|silk|skyfire|series60|bolt)\/((\d+)?[\w\.]+)/i,
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/S60/Bolt
|
||||
/(chrome|omniweb|arora|dolfin|[tizenoka]{5}\s?browser)\/((\d+)?[\w\.]+)/i,
|
||||
// Chrome/OmniWeb/Arora/Dolphin/Tizen/Nokia
|
||||
], ['name', '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,
|
||||
/(rekonq)((?:\/)[\w\.]+)*/i, // Rekonq
|
||||
/(chromium|flock|rockmelt|midori|epiphany|silk|skyfire|ovibrowser|bolt)\/((\d+)?[\w\.-]+)/i
|
||||
// Chromium/Flock/RockMelt/Midori/Epiphany/Silk/Skyfire/Bolt
|
||||
], [NAME, VERSION, MAJOR], [
|
||||
|
||||
/(yabrowser)\/((\d+)?[\w\.]+)/i // Yandex
|
||||
], [[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
|
||||
/(iceweasel|camino|fennec|maemo\sbrowser|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
|
||||
/(mozilla)\/([\w\.]+).+rv\:.+gecko\/\d+/i, // Mozilla
|
||||
/(navigator|netscape)\/((\d+)?[\w\.-]+)/i // Netscape
|
||||
], [[NAME, 'Netscape'], VERSION, MAJOR], [
|
||||
/(swiftfox)/i, // Swiftfox
|
||||
/(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
|
||||
/(lynx|dillo|icab|doris)[\/\s]?((\d+)?[\w\.]+)/i, // Lynx/Dillo/iCab/Doris
|
||||
/(gobrowser)\/?[\d\.]*/i // GoBrowser
|
||||
], ['name', 'version', 'major']
|
||||
/(uc\s?browser|polaris|lynx|dillo|icab|doris|amaya|w3m|netsurf)[\/\s]?((\d+)?[\w\.]+)/i,
|
||||
// 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]
|
||||
],
|
||||
|
||||
|
||||
device : [[
|
||||
|
||||
/\(((ipad|playbook));/i, // iPad/PlayBook
|
||||
/\((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']], [
|
||||
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/\((ip[honed]+);.+(apple)/i // iPod/iPhone
|
||||
], [MODEL, VENDOR, [TYPE, MOBILE]], [
|
||||
|
||||
/\(((ip[honed]+));/i, // iPod/iPhone
|
||||
/(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
|
||||
/(hp)\s([\w\s]+\w)/i, // HP iPAQ
|
||||
/(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
|
||||
], [['vendor', 'Asus'], 'model', ['type', 'Tablet']], [
|
||||
|
||||
], [[VENDOR, 'Asus'], MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/(sony)\s(tablet\s[ps])/i // Sony Tablets
|
||||
], ['vendor', 'model', ['type', 'Tablet']], [
|
||||
|
||||
], [VENDOR, MODEL, [TYPE, TABLET]], [
|
||||
|
||||
/(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
|
||||
/(zte)-(\w+)*/i // ZTE
|
||||
], ['vendor', ['model', /_/g, ' '], ['type', 'Mobile']], [
|
||||
|
||||
/(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']], [
|
||||
], [[VENDOR, 'Motorola'], MODEL, [TYPE, MOBILE]], [
|
||||
/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
|
||||
], [['vendor', 'Samsung'], 'model', ['type', 'Tablet']], [ // Samsung
|
||||
], [[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']], [
|
||||
], [[VENDOR, 'Samsung'], MODEL, [TYPE, MOBILE]], [
|
||||
/(sie)-(\w+)*/i // Siemens
|
||||
], [['vendor', 'Siemens'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
], [[VENDOR, 'Siemens'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/(maemo|nokia).*(n900|lumia\s\d+)/i, // Nokia
|
||||
/(nokia)[\s_-]?([\w-]+)*/i
|
||||
], [['vendor', 'Nokia'], 'model', ['type', 'Mobile']], [
|
||||
|
||||
], [[VENDOR, 'Nokia'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/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
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Tablet']], [
|
||||
], [[VENDOR, 'LG'], MODEL, [TYPE, TABLET]], [
|
||||
/(lg)[e;\s-\/]+(\w+)*/i
|
||||
], [['vendor', 'LG'], 'model', ['type', 'Mobile']]
|
||||
], [[VENDOR, 'LG'], MODEL, [TYPE, MOBILE]], [
|
||||
|
||||
/(mobile|tablet);.+rv\:.+gecko\//i // Unidentifiable
|
||||
], [TYPE, VENDOR, MODEL]
|
||||
],
|
||||
|
||||
|
||||
engine : [[
|
||||
|
||||
/(presto)\/([\w\.]+)/i, // Presto
|
||||
/([aple]*webkit|trident|netfront)\/([\w\.]+)/i, // Webkit/Trident/NetFront
|
||||
/(khtml)\/([\w\.]+)/i // KHTML
|
||||
], ['name', 'version'], [
|
||||
/(webkit|trident|netfront|netsurf|amaya|lynx|w3m)\/([\w\.]+)/i, // WebKit/Trident/NetFront/NetSurf/Amaya/Lynx/w3m
|
||||
/(khtml)\/([\w\.]+)/i, // KHTML
|
||||
/(tasman)\s([\w\.]+)/i, // Tasman
|
||||
/(links)\s\(([\w\.]+)/i, // Links
|
||||
/(icab)[\/\s]([2-3]\.[\d\.]+)/i // iCab
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/rv\:([\w\.]+).*(gecko)/i // Gecko
|
||||
], ['version', 'name']
|
||||
], [VERSION, NAME]
|
||||
],
|
||||
|
||||
|
||||
os : [[
|
||||
|
||||
// Windows based
|
||||
/(windows\sphone\sos|windows\s?[mobile]*)[\s\/]?([ntce\d\.\s]+\w)/i // Windows
|
||||
], ['name', ['version', mapper.string, maps.os.windows.version]], [
|
||||
/(windows)\snt\s6\.2;\s(arm)/i, // Windows RT
|
||||
/(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]], [
|
||||
|
||||
], [[NAME, 'Windows'], [VERSION, mapper.string, maps.os.windows.version]], [
|
||||
|
||||
// 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
|
||||
/(android|webos|palm\os|qnx|bada|rim\stablet\sos|meego)[\/\s-]?([\w\.]+)*/i
|
||||
// Android/WebOS/Palm/QNX/Bada/RIM/MeeGo
|
||||
], ['name', 'version'], [
|
||||
], [NAME, VERSION], [
|
||||
/(symbian\s?os|symbos|s60(?=;))[\/\s-]?([\w\.]+)*/i // Symbian
|
||||
], [['name', 'Symbian'], 'version'],[
|
||||
|
||||
/(nintendo|playstation)\s([wids3portable]+)/i, // Nintendo/Playstation
|
||||
], [[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
|
||||
/(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
|
||||
], ['name', 'version'], [
|
||||
/(hurd|linux)\s?([\w\.]+)*/i, // Hurd/Linux
|
||||
/(gnu)\s?([\w\.]+)*/i // GNU
|
||||
], [NAME, VERSION], [
|
||||
|
||||
/(cros)\s[\w]+\s([\w\.]+\w)/i // Chromium OS
|
||||
], [['name', 'Chromium OS'], 'version'],[
|
||||
], [[NAME, 'Chromium OS'], VERSION],[
|
||||
|
||||
// Solaris
|
||||
/(sunos)\s?([\w\.\s]+\d)*/i // Solaris
|
||||
], [['name', 'Solaris'], 'version'], [
|
||||
/(sunos)\s?([\w\.]+\d)*/i // Solaris
|
||||
], [[NAME, 'Solaris'], VERSION], [
|
||||
|
||||
// BSD based
|
||||
/\s(\w*bsd|dragonfly)\s?([\w\.]+)*/i, // FreeBSD/NetBSD/OpenBSD/DragonFly
|
||||
], ['name', 'version'],[
|
||||
/\s(\w*bsd|dragonfly)\s?([\w\.]+)*/i // FreeBSD/NetBSD/OpenBSD/DragonFly
|
||||
], [NAME, VERSION],[
|
||||
|
||||
/(ip[honead]+).*os\s*([\w]+)*\slike\smac/i // iOS
|
||||
], [['name', 'iOS'], ['version', /_/g, '.']], [
|
||||
/(ip[honead]+)(?:.*os\s*([\w]+)*\slike\smac|;\sopera)/i // iOS
|
||||
], [[NAME, 'iOS'], [VERSION, /_/g, '.']], [
|
||||
|
||||
/(mac\sos\sx)\s([\w\s\.]+\w)/i, // Mac OS
|
||||
], ['name', ['version', /_/g, '.']], [
|
||||
/(mac\sos\sx)\s?([\w\s\.]+\w)*/i // Mac OS
|
||||
], [NAME, [VERSION, /_/g, '.']], [
|
||||
|
||||
// Other
|
||||
/(haiku)\s(\w+)/i, // Haiku
|
||||
/(macintosh|unix|minix|beos)[\/\s]?()*/i // UNIX/Minix/BeOS
|
||||
], ['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]
|
||||
]
|
||||
};
|
||||
|
||||
var UAParser = function UAParser (uastring) {
|
||||
|
||||
var ua = uastring || (typeof window !== 'undefined' ? window.navigator.userAgent : "");
|
||||
var ua = uastring || ((global && global.navigator && global.navigator.userAgent) ? global.navigator.userAgent : EMPTY);
|
||||
|
||||
this.getBrowser = function () {
|
||||
return mapper.regex.apply(this, regexes.browser);
|
||||
return mapper.regex.apply(this, regexes.browser);
|
||||
};
|
||||
|
||||
this.getDevice = function () {
|
||||
@@ -290,7 +397,7 @@
|
||||
device : this.getDevice()
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
this.getUA = function() {
|
||||
return ua;
|
||||
};
|
||||
@@ -302,14 +409,23 @@
|
||||
|
||||
this.setUA(ua);
|
||||
};
|
||||
|
||||
// check whether script is running inside node.js export as module
|
||||
if (typeof exports !== 'undefined' && this.toString() !== '[object DOMWindow]') {
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
|
||||
// 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 {
|
||||
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