if (typeof Object.assign != 'function') { // Must be writable: true, enumerable: false, configurable: true Object.defineProperty(Object, "assign", { value: function assign(target, varArgs) { // .length of function is 2 'use strict'; if (target == null) { // TypeError if undefined or null throw new TypeError('Cannot convert undefined or null to object'); } var to = Object(target); for (var index = 1; index < arguments.length; index++) { var nextSource = arguments[index]; if (nextSource != null) { // Skip over if undefined or null for (var nextKey in nextSource) { // Avoid bugs when hasOwnProperty is shadowed if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { to[nextKey] = nextSource[nextKey]; } } } } return to; }, writable: true, configurable: true }); } var BASE64_MAPPING = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' ]; /** * ascii convert to binary */ var _toBinary = function(ascii) { var binary = new Array(); while (ascii > 0) { var b = ascii % 2; ascii = Math.floor(ascii / 2); binary.push(b); } /* var len = binary.length; if(6-len > 0){ for(var i = 6-len ; i > 0 ; --i){ binary.push(0); } }*/ binary.reverse(); return binary; }; /** * binary convert to decimal */ var _toDecimal = function(binary) { var dec = 0; var p = 0; for (var i = binary.length - 1; i >= 0; --i) { var b = binary[i]; if (b == 1) { dec += Math.pow(2, p); } ++p; } return dec; }; /** * unicode convert to utf-8 */ var _toUTF8Binary = function(c, binaryArray) { var mustLen = (8 - (c + 1)) + ((c - 1) * 6); var fatLen = binaryArray.length; var diff = mustLen - fatLen; while (--diff >= 0) { binaryArray.unshift(0); } var binary = []; var _c = c; while (--_c >= 0) { binary.push(1); } binary.push(0); var i = 0, len = 8 - (c + 1); for (; i < len; ++i) { binary.push(binaryArray[i]); } for (var j = 0; j < c - 1; ++j) { binary.push(1); binary.push(0); var sum = 6; while (--sum >= 0) { binary.push(binaryArray[i++]); } } return binary; }; /** * BASE64 Encode */ var encoder = function(str) { var base64_Index = []; var binaryArray = []; for (var i = 0, len = str.length; i < len; ++i) { var unicode = str.charCodeAt(i); var _tmpBinary = _toBinary(unicode); if (unicode < 0x80) { var _tmpdiff = 8 - _tmpBinary.length; while (--_tmpdiff >= 0) { _tmpBinary.unshift(0); } binaryArray = binaryArray.concat(_tmpBinary); } else if (unicode >= 0x80 && unicode <= 0x7FF) { binaryArray = binaryArray.concat(_toUTF8Binary(2, _tmpBinary)); } else if (unicode >= 0x800 && unicode <= 0xFFFF) { //UTF-8 3byte binaryArray = binaryArray.concat(_toUTF8Binary(3, _tmpBinary)); } else if (unicode >= 0x10000 && unicode <= 0x1FFFFF) { //UTF-8 4byte binaryArray = binaryArray.concat(_toUTF8Binary(4, _tmpBinary)); } else if (unicode >= 0x200000 && unicode <= 0x3FFFFFF) { //UTF-8 5byte binaryArray = binaryArray.concat(_toUTF8Binary(5, _tmpBinary)); } else if (unicode >= 4000000 && unicode <= 0x7FFFFFFF) { //UTF-8 6byte binaryArray = binaryArray.concat(_toUTF8Binary(6, _tmpBinary)); } } var extra_Zero_Count = 0; for (var i = 0, len = binaryArray.length; i < len; i += 6) { var diff = (i + 6) - len; if (diff == 2) { extra_Zero_Count = 2; } else if (diff == 4) { extra_Zero_Count = 4; } var _tmpExtra_Zero_Count = extra_Zero_Count; while (--_tmpExtra_Zero_Count >= 0) { binaryArray.push(0); } base64_Index.push(_toDecimal(binaryArray.slice(i, i + 6))); } var base64 = ''; for (var i = 0, len = base64_Index.length; i < len; ++i) { base64 += BASE64_MAPPING[base64_Index[i]]; } for (var i = 0, len = extra_Zero_Count / 2; i < len; ++i) { base64 += '='; } return base64; }; function urlsafe_b64encode(input) { return encoder(input).replace(/\+/g, '-').replace(/\//g, '_'); } function browser() { var UA = window.navigator.userAgent; var isAndroid = /Android/i.test(UA); var isiOS = /iPhone|iPad|iPod/i.test(UA); var isMeetyouWebview = /MeetYouClient/i.test(UA); var isWechat = /MicroMessenger\/(\d+)\.(\d+)\.?(\d+)?/i.test(UA); var isQQ = isiOS ? /QQ|Qzone/i.test(UA) && !/MQQBrowser/i.test(UA) : /MQQBrowser/i.test(UA) && /QQ/i.test(UA.split('MQQBrowser')); var isZhihu = /zhihu/i.test(UA); var isWeibo = /weibo/i.test(UA); var isAliApp = /AliApp/i.test(UA); var isWebview = isQQ || isZhihu || isWeibo || isAliApp; var isOtherWebview = isZhihu || isWeibo || isAliApp; var iOSMatch = UA.match(/OS (\d+)_(\d+)_?(\d+)?/i); var iOSVersion = iOSMatch ? parseInt(iOSMatch[1], 10) : 0; return { isiOS: isiOS, iOSVersion: iOSVersion, isAndroid: isAndroid, isMeetyouWebview: isMeetyouWebview, isWechat: isWechat, isQQ: isQQ, isZhihu: isZhihu, isWeibo: isWeibo, isWebview: isWebview, isOtherWebview: isOtherWebview }; }; var template = '
' + '
' + '' + '' + '
' + '
'; var shareTip = { show: function () { if(!this.hasShareGuide()){ document.body.insertAdjacentHTML('beforeend', template); } this.addEvent(); this.doShow(); }, doShow: function(){ var wrapperEl = document.querySelector('.mui-share-guide'); wrapperEl.style.display = 'block'; }, hide: function(){ var wrapperEl = document.querySelector('.mui-share-guide'); wrapperEl.style.display = 'none'; }, hasShareGuide: function () { var el = document.querySelector('.mui-share-guide'); return el ? true : false; }, addEvent: function () { var wrapperEl = document.querySelector('.mui-share-guide'); wrapperEl.addEventListener('click', function (e) { shareTip.hide(); e.stopPropagation(); }) } }; var Awaken = function (opt) { this.defaultOpts = { selectorEvent: 'click', customTrigger: false, download: '', link: 'https://bbj.meiyou.com/docouments/download.html', path: 'web' }; this.props = { itunesStoreDownloadURL: 'https://itunes.apple.com/cn/app/id1459838978?mt=8', androidApkDownloadURL: 'https://estatic.seeyouyima.com/bbj/Baby.apk', tencentMarketURL: 'https://a.app.qq.com/o/simple.jsp?pkgname=com.meiyou.seeyoubaby', scheme: 'meetyou.linggan.seeyoubaby://', schemeInApp: 'meiyou://', universalLinkBase: 'meetyou.linggan.seeyoubaby://' }; var newConfig = Object.assign({}, this.defaultOpts, opt); this.opts = newConfig; this.init(); } Awaken.prototype.init = function () { var _this = this; var triggerElement = document.querySelector(this.opts.selector); if (triggerElement && !this.opts.customTrigger) { triggerElement.addEventListener(_this.opts.selectorEvent, function () { if(_this.opts.beforeOpenHook && isFunction(_this.opts.beforeOpenHook)){ _this.opts.beforeOpenHook(); } _this.handleOpen(); }); } } Awaken.prototype.gotoDownloadLink = function (duration){ var isBlur = false; var target = this.props.tencentMarketURL; if (browser().isiOS) { target = this.props.itunesStoreDownloadURL; } if (this.opts.download) { target = this.opts.download; } window.onblur = function () { isBlur = true; }; var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : ''; var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange'); document.addEventListener(visibilityChangeEvent, function () { if(document[hiddenProperty]){ isBlur = true; } }); setTimeout(function () { if(!isBlur){ window.location.href = target; } }, duration) } Awaken.prototype.createSchemeLink = function (link){ var path = this.opts.path; var params = this.opts.params; var scheme = this.props.scheme; var schemeLink = scheme + path; if (link) { schemeLink += '?params=' + urlsafe_b64encode(JSON.stringify({url: link})); } else if (params) { schemeLink += '?params=' + urlsafe_b64encode(JSON.stringify(params)); } return schemeLink; } Awaken.prototype.tryOpenByScheme = function (link){ var timeout = 1000; var called = false; var callTimeout; var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.onload = iframe.onerror = callback; iframe.src = link; callTimeout = window.setTimeout(callback, timeout); document.getElementsByTagName('body')[0].appendChild(iframe); function callback() { if (called) { return; } iframe.onload = iframe.onerror = undefined; iframe.parentNode.removeChild(iframe); if (callTimeout) { window.clearTimeout(callTimeout); callTimeout = null; } called = true; } } Awaken.prototype.isNeedOpenInBrowser = function (){ return browser().isiOS && browser().iOSVersion < 9 || browser().isOtherWebview && browser().isiOS || browser().isWeibo && browser().isAndroid } Awaken.prototype.handleOpen = function (){ if (browser().isMeetyouWebview && browser().isAndroid) { window.location.href = this.props.androidApkDownloadURL; return; } if (this.isNeedOpenInBrowser()) { shareTip.show(); return; } var link = this.opts.link var weblink = this.opts.weblink; var download = this.opts.download; var schemeLink = this.createSchemeLink(link); if (browser().iOSVersion >= 9 && browser().isOtherWebview) { var universalLink = this.props.universalLinkBase + '?link=' + encodeURIComponent(link) + (weblink ? '&weblink=' + encodeURIComponent(weblink) : ''); if (download) { universalLink += '&download=' + encodeURIComponent(download); } window.location.href = universalLink; } else if (browser().isAndroid && browser().isWechat) { window.location.href = this.props.tencentMarketURL + '&android_schema=' + encodeURIComponent(schemeLink); } else { var duration = 1500; if (schemeLink) { if (browser().isiOS) { duration = 200; } else { this.tryOpenByScheme(schemeLink); } } this.gotoDownloadLink(duration); } } function isFunction(functionToCheck) { return functionToCheck && {}.toString.call(functionToCheck) === '[object Function]'; } window.onload = function () { new Awaken({selector: '.awaken-button'}); var btn = document.querySelector('.awaken-button'); btn.addEventListener('click', function () { if (window._czc) { _czc.push(['_trackEvent', '下载落地页', '立即下载']); } }) }