update Ox.parseUserAgent
This commit is contained in:
parent
f8dcca9fe4
commit
61f9496f34
1 changed files with 102 additions and 31 deletions
|
@ -246,65 +246,136 @@ Ox.parseSRT = function(str, fps) {
|
|||
});
|
||||
};
|
||||
|
||||
Ox.parseUserAgent = function(str) {
|
||||
var names = {
|
||||
chromeframe: 'Internet Explorer (Chrome Frame)',
|
||||
Ox.parseUserAgent = function(userAgent) {
|
||||
var aliases = {
|
||||
browser: {
|
||||
'Firefox': /(Fennec|Firebird|Iceweasel|Minefield|Namoroka|Phoenix|SeaMonkey|Shiretoko)/
|
||||
},
|
||||
system: {
|
||||
'BSD': /(FreeBSD|NetBSD|OpenBSD)/,
|
||||
'Linux': /(CrOS|MeeGo|webOS)/,
|
||||
'Unix': /(AIX|HP-UX|IRIX|SunOS)/
|
||||
}
|
||||
},
|
||||
names = {
|
||||
browser: {
|
||||
'chromeframe': 'Chrome Frame',
|
||||
'MSIE': 'Internet Explorer'
|
||||
},
|
||||
system: {
|
||||
'iPhone OS': 'iOS',
|
||||
Fennec: 'Mobile Firefox',
|
||||
Mobile: 'Mobile Safari',
|
||||
MSIE: 'Internet Explorer',
|
||||
'Macintosh': 'Mac OS X'
|
||||
}
|
||||
},
|
||||
regexps = {
|
||||
browser: [
|
||||
/(Camino)\/(\d+)/,
|
||||
/(chromeframe)\/(\d+)/,
|
||||
/(Chrome)\/(\d+)/,
|
||||
/(Fennec)\/(\d+)/,
|
||||
/(Epiphany)\/(\d+)/,
|
||||
/(Firefox)\/(\d+)/,
|
||||
/(MSIE)\/(\d+)/,
|
||||
/(Galeon)\/(\d+)/,
|
||||
/(Googlebot)\/(\d+)/,
|
||||
/(Konqueror)\/(\d+)/,
|
||||
/(MSIE) (\d+)/,
|
||||
/(Netscape)\d?\/(\d+)/,
|
||||
/(NokiaBrowser)\/(\d+)/,
|
||||
/(Opera) (\d+)/,
|
||||
/(Opera)\/.+Version\/(\d+)/,
|
||||
/Version\/(\d+).+(Mobile)\/.+Safari/,
|
||||
/Version\/(\d+).+(Safari)/
|
||||
],
|
||||
system: [
|
||||
/(Android) (\d+)/,
|
||||
/(BeOS)/,
|
||||
/(BlackBerry) (\d+)/,
|
||||
/(Darwin)/,
|
||||
/(BSD) (FreeBSD|NetBSD|OpenBSD)/,
|
||||
/(iPhone OS) (\d+)/,
|
||||
/(Linux).+(CentOS|CrOS|Debian|Fedora|Gentoo|Mandriva|MeeGo|Mint|Red Hat|SUSE|Ubuntu|webOS)/,
|
||||
/(Linux)/,
|
||||
/(Mac OS X) (10.\d)/,
|
||||
/(Windows) (NT \d\.\d)/
|
||||
/(Mac OS X)/,
|
||||
/(Macintosh)/,
|
||||
/(SymbianOS)\/(\d+)/,
|
||||
/(SymbOS)/,
|
||||
/(OS\/2)/,
|
||||
/(Unix) (AIX|HP-UX|IRIX|SunOS)/,
|
||||
/(Unix)/,
|
||||
/(Windows) (NT \d\.\d)/,
|
||||
/(Windows) (95|98|2000|2003|ME|NT|XP)/, // Opera
|
||||
/(Windows).+(Win 9x 4\.90)/, // Firefox
|
||||
/(Windows).+(Win9\d)/, // Firefox
|
||||
/(Windows).+(WinNT4.0)/ // Firefox
|
||||
]
|
||||
},
|
||||
userAgent = {
|
||||
browser: {name: '', version: ''},
|
||||
system: {name: '', version: ''}
|
||||
},
|
||||
versions = {
|
||||
'10.3': 'Panther',
|
||||
'10.4': 'Tiger',
|
||||
'10.5': 'Leopard',
|
||||
'10.6': 'Snow Leopard',
|
||||
'10.7': 'Lion',
|
||||
'NT 5.0': '2000',
|
||||
'NT 5.1': 'XP',
|
||||
'NT 5.2': '2003',
|
||||
'NT 6.0': 'Vista',
|
||||
'NT 6.1': '7'
|
||||
browser: {},
|
||||
system: {
|
||||
'10.2': '10.2 (Jaguar)',
|
||||
'10.3': '10.3 (Panther)',
|
||||
'10.4': '10.4 (Tiger)',
|
||||
'10.5': '10.5 (Leopard)',
|
||||
'10.6': '10.6 (Snow Leopard)',
|
||||
'10.7': '10.7 (Lion)',
|
||||
'CrOS': 'Chrome OS',
|
||||
'NT 4.0': 'NT 4.0 (Windows NT)',
|
||||
'NT 4.1': 'NT 4.1 (Windows 98)',
|
||||
'Win 9x 4.90': 'NT 4.9 (Windows ME)',
|
||||
'NT 5.0': 'NT 5.0 (Windows 2000)',
|
||||
'NT 5.1': 'NT 5.1 (Windows XP)',
|
||||
'NT 5.2': 'NT 5.2 (Windows 2003)',
|
||||
'NT 6.0': 'NT 6.0 (Windows Vista)',
|
||||
'NT 6.1': 'NT 6.1 (Windows 7)',
|
||||
'NT 6.2': 'NT 6.2 (Windows 8)',
|
||||
'95': 'NT 4.0 (Windows 95)',
|
||||
'NT': 'NT 4.0 (Windows NT)',
|
||||
'98': 'NT 4.1 (Windows 98)',
|
||||
'ME': 'NT 4.9 (Windows ME)',
|
||||
'2000': 'NT 5.0 (Windows 2000)',
|
||||
'2003': 'NT 5.2 (Windows 2003)',
|
||||
'XP': 'NT 5.1 (Windows XP)',
|
||||
'Win95': 'NT 4.0 (Windows 95)',
|
||||
'WinNT4.0': 'NT 4.0 (Windows NT)',
|
||||
'Win98': 'NT 4.1 (Windows 98)'
|
||||
}
|
||||
},
|
||||
userAgentData = {};
|
||||
Ox.forEach(regexps, function(regexps, key) {
|
||||
regexps.forEach(function(regexp) {
|
||||
var matches = str.match(regexp), name, swap, version;
|
||||
userAgentData[key] = {name: '', string: '', version: ''};
|
||||
Ox.forEach(aliases[key], function(regexp, alias) {
|
||||
userAgent = userAgent.replace(
|
||||
regexp, key == 'browser' ? alias : alias + ' $1'
|
||||
);
|
||||
});
|
||||
Ox.forEach(regexps, function(regexp) {
|
||||
var matches = userAgent.match(regexp),
|
||||
name, string, swap, version;
|
||||
if (matches) {
|
||||
matches[2] = matches[2] || '';
|
||||
swap = matches[1].match(/^\d+$/);
|
||||
name = matches[swap ? 2 : 1];
|
||||
version = matches[swap ? 1 : 2].replace('_', '.');
|
||||
userAgent[key] = {
|
||||
name = names[key][name] || name,
|
||||
version = versions[key][version] || version;
|
||||
string = name + (
|
||||
version
|
||||
? ' ' + (
|
||||
['BSD', 'Linux', 'Unix'].indexOf(name) > -1
|
||||
? '(' + version + ')'
|
||||
: version
|
||||
)
|
||||
: ''
|
||||
);
|
||||
userAgentData[key] = {
|
||||
name: names[name] || name,
|
||||
string: string,
|
||||
version: versions[version] || version
|
||||
};
|
||||
return false;
|
||||
}
|
||||
});
|
||||
});
|
||||
return userAgent;
|
||||
return userAgentData;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
Loading…
Reference in a new issue