...
|
...
|
@@ -3,17 +3,57 @@ |
|
|
*/
|
|
|
const qs = require('yoho-qs');
|
|
|
|
|
|
const u = navigator.userAgent;
|
|
|
const isFromYOHO = /m\.yohobuy\.com/i.test(document.referrer);
|
|
|
const isApp = /yohobuy/i.test(u) || !!window.yohoInterface || /app_version=/i.test(location.search) || /openrefer=/i.test(location.search);
|
|
|
|
|
|
const isiOS = /(iPhone|iPad|iPod|iOS)/i.test(u); // ios终端
|
|
|
const isAndroid = /Android/i.test(u); // android终端
|
|
|
const iOSVersion = parseInt((u.match(/OS (\d+)_(\d+)_?(\d+)?/i) || [])[1], 10); // iOS 版本
|
|
|
|
|
|
const nodownload = document.getElementById('no-download'); // 页面不需要下载
|
|
|
const urlBlacklist = ['m.yohobuy.com/brands', 'm.yohobuy.com/passport'];
|
|
|
const blackCheck = urlBlacklist.some(function (url) {
|
|
|
return new RegExp(url, 'i').test(location.href);
|
|
|
});
|
|
|
|
|
|
const canOpenApp = () => {
|
|
|
if (isApp || isFromYOHO || nodownload || qs.nodownload || qs.no_openapp || blackCheck) {
|
|
|
return false;
|
|
|
}
|
|
|
return isAndroid || iOSVersion < 9 || qs.openapp;
|
|
|
};
|
|
|
|
|
|
const getAppPath = () => {
|
|
|
return document.getElementById('main-wrap').dataset.apppath || 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}';
|
|
|
let appPath = document.getElementById('main-wrap').dataset.apppath || 'yohobuy://yohobuy.com/goapp?openby:yohobuy={"action":"go.home","params":{"gender":"1","channel":"2"}}';
|
|
|
let ct = qs.mkt_code || qs.union_type;
|
|
|
|
|
|
if (ct) {
|
|
|
appPath = appPath.replace('goapp?', 'goapp?ct=' + ct + '&');
|
|
|
}
|
|
|
|
|
|
return appPath;
|
|
|
};
|
|
|
|
|
|
if (qs.openapp) {
|
|
|
const u = navigator.userAgent.toLowerCase();
|
|
|
const isiOS = u.indexOf('os') > -1 || u.indexOf('iphone') > -1 || u.indexOf('mac') > -1 || u.indexOf('ipad') > -1;
|
|
|
|
|
|
if (canOpenApp()) {
|
|
|
let appPath = getAppPath();
|
|
|
let ifr;
|
|
|
|
|
|
if (window._yas && window._yas.sendCustomInfo) {
|
|
|
window._yas.sendCustomInfo({
|
|
|
op: 'YB_H5_AWAKE_APP',
|
|
|
param: JSON.stringify({
|
|
|
PAGE_NAME: encodeURIComponent(document.title),
|
|
|
PAGE_URL: encodeURIComponent(location.href)
|
|
|
})
|
|
|
}, true);
|
|
|
}
|
|
|
|
|
|
if (window._hmt && window._hmt.push) {
|
|
|
window._hmt.push(['_trackEvent', 'H5唤起APP', isiOS ? 'Apple' : 'Android', document.title, location.href]);
|
|
|
}
|
|
|
|
|
|
if (isiOS) {
|
|
|
window.location.href = appPath;
|
|
|
} else {
|
...
|
...
|
@@ -22,14 +62,4 @@ if (qs.openapp) { |
|
|
ifr.style.display = 'none';
|
|
|
document.body.appendChild(ifr);
|
|
|
}
|
|
|
|
|
|
// let time = Date.now();
|
|
|
|
|
|
// window.setTimeout(function() {
|
|
|
// document.body.removeChild(ifr);
|
|
|
// if (Date.now() - time < 2200) {
|
|
|
// window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
|
|
|
// }
|
|
|
// }, 2000);
|
|
|
} |
|
|
|
...
|
...
|
|