Authored by ccbikai(👎🏻🍜)

完善 APP 检测规则

@@ -3,6 +3,27 @@ @@ -3,6 +3,27 @@
3 */ 3 */
4 const qs = require('yoho-qs'); 4 const qs = require('yoho-qs');
5 5
  6 +const u = navigator.userAgent;
  7 +const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer);
  8 +const isApp = /yohobuy/i.test(u) || !!window.yohoInterface || /app_version=/i.test(location.search) || /openrefer=/i.test(location.search);
  9 +
  10 +const isiOS = /(iPhone|iPad|iPod|iOS)/i.test(u); // ios终端
  11 +const isAndroid = /Android/i.test(u); // android终端
  12 +const iOSVersion = parseInt((u.match(/OS (\d+)_(\d+)_?(\d+)?/i) || [])[1], 10); // iOS 版本
  13 +
  14 +const nodownload = document.getElementById('no-download'); // 页面不需要下载
  15 +const urlBlacklist = ['m.yohobuy.com/brands', 'm.yohobuy.com/passport'];
  16 +const blackCheck = urlBlacklist.some(function (url) {
  17 + return new RegExp(url, 'i').test(location.href);
  18 +});
  19 +
  20 +const canOpenApp = () => {
  21 + if (isApp || isFromYOHO || nodownload || qs.nodownload || qs.no_openapp || blackCheck) {
  22 + return false;
  23 + }
  24 + return isAndroid || iOSVersion < 9 || qs.openapp;
  25 +};
  26 +
6 const getAppPath = () => { 27 const getAppPath = () => {
7 let appPath = document.getElementById('main-wrap').dataset.apppath || 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}'; 28 let appPath = document.getElementById('main-wrap').dataset.apppath || 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}';
8 let ct = qs.mkt_code || qs.union_type; 29 let ct = qs.mkt_code || qs.union_type;
@@ -14,14 +35,8 @@ const getAppPath = () => { @@ -14,14 +35,8 @@ const getAppPath = () => {
14 return appPath; 35 return appPath;
15 }; 36 };
16 37
17 -const u = navigator.userAgent;  
18 -const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer);  
19 -const isiOS = /(iPhone|iPad|iPod|iOS)/i.test(u); // ios终端  
20 -const isAndroid = /Android/i.test(u); // android终端  
21 -const iOSVersion = parseInt((u.match(/OS (\d+)_(\d+)_?(\d+)?/i) || [])[1], 10);  
22 -  
23 38
24 -if (!isFromYOHO && !qs.no_openapp && (isAndroid || iOSVersion < 9 || qs.openapp)) { 39 +if (canOpenApp()) {
25 let appPath = getAppPath(); 40 let appPath = getAppPath();
26 let ifr; 41 let ifr;
27 42