Skip to content

Instantly share code, notes, and snippets.

@chemdemo
Created November 6, 2014 15:01
Show Gist options
  • Save chemdemo/8c2f39e3890f09f38149 to your computer and use it in GitHub Desktop.
Save chemdemo/8c2f39e3890f09f38149 to your computer and use it in GitHub Desktop.
get chinese browsers ua
/*
* @Author: dm.yang
* @Date: 2014-09-19 15:40:08
* @Last Modified by: dm.yang
* @Last Modified time: 2014-11-06 22:36:51
*/
var uaParser = require('ua-parser');
exports.getUA = function(req) {
var ua = req.get('user-agent');
var os = uaParser.parseOS(ua).family;
var browser = uaParser.parseUA(ua).family;
if(/\s+/.test(os)) os = os.split(/\s+/)[0];
if(/iPhone/.test(os)) os = 'iOS';
return {
// device: uaParser.parseDevice(ua).family,
os: os,
browser: browser// || getChineseBrowser(ua) || ,
// vesion: uaParser.parseUA(ua).major
};
};
// ua list(iPhone):
// MQQ => Mozilla/5.0 (iPhone 5SGLOBAL; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/6.0 MQQBrowser/5.4.1 Mobile/12B411 Safari/8536.25
// UC => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X; zh-CN) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/12B411 UCBrowser/10.0.5.508 Mobile
// baidu => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/8.1 Mobile/12B411 Safari/9537.53 baidubrowser/2.3.0.53 (Baidu; P2 8.1)
// 360 => Mozilla/5.0 (iPhone; CPU iPhone OS 8.1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3 QHBrowser/1.0.2
// weixin => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B411 MicroMessenger/6.0 NetType/WIFI
// Mobile QQ => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B411 QQ/5.1.1.97
// opera => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) OPiOS/8.0.5.83168 Mobile/12B411 Safari/9537.53
// Liebao => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Version/7.0 Mobile/12B411 Safari/9537.53
// Sougou => Mozilla/5.0 (iPhone; CPU iPhone OS 8_1 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12B411 SogouMobileBrowser/3.3.10
// ua list(Android):
// Default => Mozilla/5.0 (Linux; U; Android 4.1.2; zh-cn; GT-I9300 Build/JZO54K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30
// Chrome => Mozilla/5.0 (Linux; Android 4.1.2; GT-I9300 Build/JZO54K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.102 Mobile Safari/537.36
// UC => Mozilla/5.0 (Linux; U; Android 4.1.1; zh-CN; M032 Build/JRO03H) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 UCBrowser/9.9.6.495 U3/0.8.0 Mobile Safari/533.1
// MQQ => Mozilla/5.0 (Linux; U; Android 4.4.2; zh-cn; SM-N9005 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko)Version/4.0 MQQBrowser/5.3 Mobile Safari/537.36
// 360 => Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M032 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30; 360 Aphone Browser (6.6.6.1)
// weixin => Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M032 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 MicroMessenger/6.0.0.50_r844973.501 NetType/WIFI
// Mobile QQ => Mozilla/5.0 (Linux; U; Android 4.1.1; zh-cn; M032 Build/JRO03H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 V1_AND_SQ_5.1.2_160_YYB_D QQ/5.1.1.2250
// Opera => Mozilla/5.0 (Linux; U; Android 4.4.2; zh-CN; SM-N9005 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Oupeng/9.3.1.75512 Mobile Safari/537.36 (securitypay,securityinstalled)
// LieBao => Mozilla/5.0 (Linux; Android 4.4.2; SM-N9005 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36 LieBaoFast/2.16.2
// Sougou => Mozilla/5.0 (Linux; U; Android 4.4.2; zh-cn; SM-N9005 Build/KOT49H) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 SogouMSE,SogouMobileBrowser/3.3.1
function getChineseBrowser(ua) {
if(/UCBrowser/ig.test(ua)) return 'UC';
if(/MQQBrowser/ig.test(ua)) return 'MQQ';
if(/baidubrowser/ig.test(ua)) return 'Baidu';
// 360 ni ge si BT!
if(/QHBrowser|360(.*)+Browser/ig.test(ua)) return 'QH360';
if(/OPiOS|Oupeng/g.test(ua)) return 'Opera';
if(/MicroMessenger/ig.test(ua)) return 'WeChat';
if(/\bQQ/g.test(ua)) return 'IMQQ';
if(/LieBao/gi.test(ua)) return 'Liebao';
if(/Sogou/gi.test(ua)) return 'Sogou';
return '';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment