Authored by zhangwenxue

refactor: extract ua

@@ -60,10 +60,12 @@ module.exports = () => { @@ -60,10 +60,12 @@ module.exports = () => {
60 yoho.fullScreen = true; 60 yoho.fullScreen = true;
61 } 61 }
62 62
63 - yoho.isMobile = /(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i.test(req.get('User-Agent') || ''); // eslint-disable-line  
64 - yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');  
65 - yoho.isWeibo = /weibo/i.test(req.get('User-Agent') || '');  
66 - yoho.isqq = /MQQBrowser/i.test(req.get('User-Agent') || ''); 63 + const ua = req.get('User-Agent') || '';
  64 +
  65 + yoho.isMobile = /(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220)/i.test(ua); // eslint-disable-line
  66 + yoho.isWechat = /micromessenger/i.test(ua);
  67 + yoho.isWeibo = /weibo/i.test(ua);
  68 + yoho.isqq = /MQQBrowser/i.test(ua);
67 69
68 Object.assign(res.locals, yoho); 70 Object.assign(res.locals, yoho);
69 Object.assign(req.yoho, yoho); 71 Object.assign(req.yoho, yoho);