mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Added setUA() method and result object
This commit is contained in:
parent
0276dd0c49
commit
294b4e6d58
33
ua-parser.js
33
ua-parser.js
@ -5,7 +5,9 @@
|
|||||||
// Copyright © 2012 Faisalman
|
// Copyright © 2012 Faisalman
|
||||||
// Licensed under GPLv2
|
// Licensed under GPLv2
|
||||||
|
|
||||||
function uaparser (uastring) {
|
function UAParser (uastring) {
|
||||||
|
|
||||||
|
var ua = uastring || window.navigator.userAgent;
|
||||||
|
|
||||||
// regexp mapper
|
// regexp mapper
|
||||||
var regxMap = function (ua) {
|
var regxMap = function (ua) {
|
||||||
@ -69,15 +71,13 @@ function uaparser (uastring) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.ua = uastring || window.navigator.userAgent;
|
this.getBrowser = function(uastring) {
|
||||||
|
|
||||||
this.getBrowser = function() {
|
return regxMap(uastring || ua, [
|
||||||
|
|
||||||
return regxMap(this.ua, [
|
|
||||||
|
|
||||||
// Mixed
|
// Mixed
|
||||||
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
/(kindle)\/((\d+)?[\w\.]+)/i, // Kindle
|
||||||
/(lunpropsape|maxthon|netfront|jasmine)[\/\s]?((\d+)?[\w\.]+)/i, // Lunpropsape/Maxthon/Netfront/Jasmine
|
/(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
|
||||||
@ -108,9 +108,9 @@ function uaparser (uastring) {
|
|||||||
], ['name', 'version', 'major']);
|
], ['name', 'version', 'major']);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getEngine = function() {
|
this.getEngine = function(uastring) {
|
||||||
|
|
||||||
return regxMap(this.ua, [
|
return regxMap(uastring || ua, [
|
||||||
|
|
||||||
/(presto)\/([\w\.]+)/i, // Presto
|
/(presto)\/([\w\.]+)/i, // Presto
|
||||||
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
|
/([aple]*webkit|trident)\/([\w\.]+)/i, // Webkit/Trident
|
||||||
@ -121,9 +121,9 @@ function uaparser (uastring) {
|
|||||||
], ['version', 'name']);
|
], ['version', 'name']);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.getOS = function() {
|
this.getOS = function(uastring) {
|
||||||
|
|
||||||
return regxMap(this.ua, [
|
return regxMap(uastring || ua, [
|
||||||
|
|
||||||
// Windows based
|
// Windows based
|
||||||
/(windows\sphone\sos|windows)\s+([\w\.\s]+)*/i, // Windows
|
/(windows\sphone\sos|windows)\s+([\w\.\s]+)*/i, // Windows
|
||||||
@ -164,4 +164,15 @@ function uaparser (uastring) {
|
|||||||
/(macintosh|unix|minix|beos)[\/\s]?()*/i
|
/(macintosh|unix|minix|beos)[\/\s]?()*/i
|
||||||
], ['name', 'version']);
|
], ['name', 'version']);
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
this.setUA = function (uastring) {
|
||||||
|
ua = uastring || ua;
|
||||||
|
return this.result = {
|
||||||
|
browser : this.getBrowser(),
|
||||||
|
engine : this.getEngine(),
|
||||||
|
os : this.getOS()
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
this.setUA(ua);
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user