Skip to content

Commit

Permalink
Add Windows 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex authored and Alex committed Sep 26, 2013
1 parent 9d9d6b3 commit 3cd626a
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 47 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ module provides details such as the following:
{
"isMobile":false,
"isDesktop":true,
"isBot":false,
.....
"Browser":"Chrome",
"Version":"17.0.963.79",
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @created 2012-03-24 16:21:10
* @category Express Helpers
* @package express-useragent
* @version 0.0.6
* @version 0.0.8
* @copyright Copyright (c) 2009-2012 - All rights reserved.
* @license MIT License
* @author Alexey Gordeyev IK <aleksej@gordejev.lv>
Expand Down
137 changes: 117 additions & 20 deletions lib/express-useragent.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @created 2011-12-10 17:19:10
* @category Express Helpers
* @package express-useragent
* @version 0.0.7
* @version 0.0.8
* @copyright Copyright (c) 2009-2011 - All rights reserved.
* @license MIT License
* @author Alexey Gordeyev IK <aleksej@gordejev.lv>
Expand All @@ -13,18 +13,29 @@
*/

var UserAgent = function() {
this.version = '0.0.7';
this.version = '0.0.8';
this._Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Opera: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i
Psp: /([\d\w\.\-]+)\)?\s*$/i,
Amaya: /amaya\/([\d\w\.\-]+)/i,
SeaMonkey: /seamonkey\/([\d\w\.\-]+)/i,
OmniWeb: /omniweb\/v([\d\w\.\-]+)/i,
Flock: /flock\/([\d\w\.\-]+)/i,
Epiphany: /epiphany\/([\d\w\.\-]+)/i
};
this._Browsers = {
Amaya: /amaya/i,
Konqueror: /konqueror/i,
Epiphany: /epiphany/i,
SeaMonkey: /seamonkey/i,
Flock: /flock/i,
OmniWeb:/omniweb/i,
Chromium: /chromium/i,
Chrome: /chrome/i,
Safari: /safari/i,
IE: /msie/i,
Expand All @@ -42,6 +53,7 @@ var UserAgent = function() {
WindowsXP: /windows nt 5\.1/i,
Windows2000: /windows nt 5\.0/i,
OSX: /os x (\d+)[._](\d+)/i,
Mac: /os x/i,
Linux: /linux/i,
Wii: /wii/i,
PS3: /playstation 3/i,
Expand Down Expand Up @@ -78,23 +90,50 @@ var UserAgent = function() {
isWebkit : false,
isChrome : false,
isKonqueror : false,
isOmniWeb : false,
isSeaMonkey : false,
isFlock : false,
isAmaya : false,
isEpiphany : false,
isDesktop : false,
isWindows : false,
isLinux : false,
isMac : false,
isBada : false,
isSamsung : false,
isRaspberry : false,
isBot : false,
Browser : 'unknown',
Version : 'unknown',
OS : 'unknown',
Platform : 'unknown',
GeoIP : {},
source:''
};

this.getBrowser = function(string) {
switch (true) {
case this._Browsers.Konqueror.test(string):
this.Agent.isKonqueror = true;
return 'Konqueror';
case this._Browsers.Amaya.test(string):
this.Agent.isAmaya = true;
return 'Amaya';
case this._Browsers.Epiphany.test(string):
this.Agent.isEpiphany = true;
return 'Epiphany';
case this._Browsers.SeaMonkey.test(string):
this.Agent.isSeaMonkey = true;
return 'SeaMonkey';
case this._Browsers.Flock.test(string):
this.Agent.isFlock = true;
return 'Flock';
case this._Browsers.OmniWeb.test(string):
this.Agent.isOmniWeb = true;
return 'OmniWeb';
case this._Browsers.Chromium.test(string):
this.Agent.isChrome = true;
return 'Chromium';
case this._Browsers.Chrome.test(string):
this.Agent.isChrome = true;
return 'Chrome';
Expand Down Expand Up @@ -157,6 +196,36 @@ var UserAgent = function() {
return RegExp.$1;
}
break;
case 'Chromium':
if (this._Versions.Chrome.test(string)) {
return RegExp.$1;
}
break;
case 'Amaya':
if (this._Versions.Amaya.test(string)) {
return RegExp.$1;
}
break;
case 'Epiphany':
if (this._Versions.Epiphany.test(string)) {
return RegExp.$1;
}
break;
case 'SeaMonkey':
if (this._Versions.SeaMonkey.test(string)) {
return RegExp.$1;
}
break;
case 'Flock':
if (this._Versions.Flock.test(string)) {
return RegExp.$1;
}
break;
case 'OmniWeb':
if (this._Versions.OmniWeb.test(string)) {
return RegExp.$1;
}
break;
default:
regex = /#{name}[\/ ]([\d\w\.\-]+)/i;
if (regex.test(string)) {
Expand All @@ -173,6 +242,9 @@ var UserAgent = function() {
case this._OS.Windows7.test(string):
this.Agent.isWindows = true;
return 'Windows 7';
case this._OS.Windows8.test(string):
this.Agent.isWindows = true;
return 'Windows 8';
case this._OS.Windows2003.test(string):
this.Agent.isWindows = true;
return 'Windows 2003';
Expand All @@ -191,6 +263,9 @@ var UserAgent = function() {
return 'Playstation';
case this._OS.PSP.test(string):
return 'Playstation';
case this._OS.Mac.test(string):
this.Agent.isMac = true;
return 'OS X';
case this._OS.OSX.test(string):
this.Agent.isMac = true;
return string.match(this._OS.OSX)[0].replace('_', '.');
Expand Down Expand Up @@ -253,40 +328,60 @@ var UserAgent = function() {
this.testMobile = function testMobile() {
var ua = this;
switch (true) {
case this.Agent.isWindows:
case this.Agent.isLinux:
case this.Agent.isMac:
this.Agent.isDesktop = true;
case ua.Agent.isWindows:
case ua.Agent.isLinux:
case ua.Agent.isMac:
ua.Agent.isDesktop = true;
break;
case this.Agent.isAndroid:
case this.Agent.isSamsung:
this.Agent.isMobile = true;
this.Agent.isDesktop = false;
case ua.Agent.isAndroid:
case ua.Agent.isSamsung:
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
switch (true) {
case this.Agent.isiPad:
case this.Agent.isiPod:
case this.Agent.isiPhone:
case this.Agent.isBada:
case this.Agent.isBlackberry:
case this.Agent.isAndroid:
this.Agent.isMobile = true;
this.Agent.isDesktop = false;
case ua.Agent.isiPad:
case ua.Agent.isiPod:
case ua.Agent.isiPhone:
case ua.Agent.isBada:
case ua.Agent.isBlackberry:
case ua.Agent.isAndroid:
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
break;
default:
}
// console.log(this);
if(/mobile/i.test(ua.Agent.source)) {
ua.Agent.isMobile = true;
ua.Agent.isDesktop = false;
}
};

this.testNginxGeoIP = function testNginxGeoIP(headers) {
var ua = this;
Object.keys(headers).forEach(function(key){
if(/^GEOIP/i.test(key)) {
ua.Agent.GeoIP[key] = headers[key];
}
});
};

this.testBot = function testBot() {
var ua = this;
if(/googlebot|gurujibot|yandexbot|slurp|msnbot|bingbot/i.test(key)) {
ua.Agent.isBot = true;
}
};

this.parse = function parse(source) {
var ua = new UserAgent();
ua.Agent.source = source.replace(/^\s*/, '').replace(/\s*$/, '');
ua.Agent.OS = ua.getOS(ua.Agent.source);
ua.Agent.Platform = ua.getPlatform(ua.Agent.source);
ua.Agent.Browser = ua.getBrowser(ua.Agent.source);
ua.Agent.Version = ua.getBrowserVersion(ua.Agent.source);
ua.testBot();
ua.testMobile();
return ua.Agent;
};
Expand All @@ -301,6 +396,8 @@ var UserAgent = function() {
ua.Agent.Platform = ua.getPlatform(ua.Agent.source);
ua.Agent.Browser = ua.getBrowser(ua.Agent.source);
ua.Agent.Version = ua.getBrowserVersion(ua.Agent.source);
ua.testNginxGeoIP(req.headers);
ua.testBot();
ua.testMobile();
req.useragent = ua.Agent;
res.locals({"useragent" : ua.Agent});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "express-useragent",
"description": "ExpressJS user-agent middleware",
"version": "0.0.7-1",
"version": "0.0.8",
"homepage": "https://github.com/biggora/express-useragent/",
"repository": {
"type": "git",
Expand Down
Loading

0 comments on commit 3cd626a

Please sign in to comment.