-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebPopup.min.js
2 lines (2 loc) · 47.5 KB
/
webPopup.min.js
1
2
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():e()}(this,function(){"use strict";function t(t){var e="t6KJCZa5pDdQ9khoEM3Tj70fbP2eLSyc4BrsYugARqFIw1mzlGNVXOHiWvxUn8",n=e.length-1,i={},a=0;for(a=0;a<e.length;a++)i[e.charAt(a)]=e.charAt(n-a);var o="";for(a=0;a<t.length;a++)o+=t.charAt(a)in i?i[t.charAt(a)]:t.charAt(a);return o}function e(e){return 0===e.indexOf(s)&&(e=e.substring(s.length),e=t(e)),e}function n(e){return s+t(e)}function i(){if(!a.isSupportPopup())return!1;if(window.screen.width&&Number(window.screen.width)<=1024)return"object"==typeof console&&console.log&&console.log("Web \u5f39\u7a97\u4ec5\u652f\u6301 PC\u7aef\uff0c\u4e14\u5c4f\u5e55\u5bbd\u5ea6\u5927\u4e8e 1024"),!1;var t={};return arguments.length>0&&(1===arguments.length&&o.isObject(arguments[0])?t=arguments[0]:arguments.length>=2&&o.isObject(arguments[1])&&(t=arguments[1])),!!this.setPara(t)&&(a.info.platform="WEB",!!a.setIsLoad()&&void(a.testSend.hasParam()?a.testSend.start():(a.listenPageStateChange(),a.updateDataAndSetListen.initial())))}var a={sa:{},info:{},plugin_name:"WebPopup",lib_version:"1.25.2",plugin_version:"1.25.2",defaultPara:{platform:"H5",preload_image:!0,encrypt_cookie:!1},serverData:{},localData:{global_popup_count:[],local_update_time:null,eventQueue:[],update_time:null},eventRule:{},convertPlans:[],isRun:!1,setArg:function(t){var e={};if(t&&"[object Object]"===Object.prototype.toString.call(t)){for(var n in t)n&&"popup_window_content"!==n&&(e[n]=t[n]);return JSON.stringify(e,null," ")}return t},log:function(){if(a.info.show_log===!0&&"object"==typeof console&&"function"==typeof console.log)try{return arguments[0]=a.setArg(arguments[0]),arguments[1]=a.setArg(arguments[1]),console.log.apply(console,arguments)}catch(t){console.log(arguments[0])}}};a.config={storageName:"sensorsdata202002-webpopupdata",loadedSign:"SensorsData2015JSSDKWebPopupIsLoad"};var o={visibility:function(t){t=t||{};var e={hidden:void 0,visibilityChange:void 0,isSupported:function(){return"undefined"!=typeof this.hidden},_visible:t.onVisible,_hidden:t.onHidden,_nativeSwitch:function(){document[this.hidden]===!0?this._hidden():this._visible()},listen:function(){try{this.isSupported()?document.addEventListener(this.visibilityChange,function(){e._nativeSwitch.apply(e,arguments)},1):document.addEventListener?(window.addEventListener("focus",this._visible,1),window.addEventListener("blur",this._hidden,1)):(document.attachEvent("onfocusin",this._visible),document.attachEvent("onfocusout",this._hidden))}catch(t){}},init:function(){"undefined"!=typeof document.hidden?(this.hidden="hidden",this.visibilityChange="visibilitychange"):"undefined"!=typeof document.mozHidden?(this.hidden="mozHidden",this.visibilityChange="mozvisibilitychange"):"undefined"!=typeof document.msHidden?(this.hidden="msHidden",this.visibilityChange="msvisibilitychange"):"undefined"!=typeof document.webkitHidden&&(this.hidden="webkitHidden",this.visibilityChange="webkitvisibilitychange"),this.listen()}};e.init()},getRgba:function(t){return"object"!=typeof t?t:"rgba("+t.r+","+t.g+","+t.b+","+t.a+")"},conversionNum:function(t){if(t){if(/^[0|1]?\.\d+$/.test(t))return 100*Number(t)+"%";var e=/^(-?\d+(\.\d+)?)px$/.exec(t);return e?(Number(e[1])/375*window.screen.width).toFixed(2)+"px":t}},boxModel:function(t){return function(e){if("object"!=typeof e)return t+":"+e+";";var n="";for(var i in e)n+=t+"-"+i+":"+o.conversionNum(e[i])+";";return n}},localStorage:{get:function(t){return window.localStorage.getItem(t)},parse:function(t){var e=null;try{e=JSON.parse(o.localStorage.get(t))||null}catch(n){}return e},set:function(t,e){window.localStorage.setItem(t,e)},remove:function(t){window.localStorage.removeItem(t)},isSupport:function(){var t=!0;try{var e="__sensorsdatasupport__",n="testIsSupportStorage";o.localStorage.set(e,n),o.localStorage.get(e)!==n&&(t=!1),o.localStorage.remove(e)}catch(i){t=!1}return t}},addEvent:function(){function t(e){return e&&(e.preventDefault=t.preventDefault,e.stopPropagation=t.stopPropagation,e._getPath=t._getPath),e}function e(e,n,i){var a=function(a){if(a=a||t(window.event)){a.target=a.srcElement;var o,r,s=!0;return"function"==typeof i&&(o=i(a)),r=n.call(e,a),!1!==o&&!1!==r||(s=!1),s}};return a}t._getPath=function(){var t=this,e=function(){try{var e=t.target,n=[e];if(null===e||null===e.parentElement)return[];for(;null!==e.parentElement;)e=e.parentElement,n.unshift(e);return n}catch(i){return[]}};return this.path||this.composedPath&&this.composedPath()||e()},t.preventDefault=function(){this.returnValue=!1},t.stopPropagation=function(){this.cancelBubble=!0};var n=function(n,i,a){if(n&&n.addEventListener)n.addEventListener(i,function(e){e._getPath=t._getPath,a.call(this,e)},!1);else{var o="on"+i,r=n[o];n[o]=e(n,a,r)}};n.apply(null,arguments)},extend:function(t){var e=Array.prototype.slice;return o.each(e.call(arguments,1),function(e){for(var n in e)void 0!==e[n]&&(t[n]=e[n])}),t},extend2Lev:function(t){return o.each(Array.prototype.slice.call(arguments,1),function(e){for(var n in e)void 0!==e[n]&&(o.isObject(e[n])&&o.isObject(t[n])?o.extend(t[n],e[n]):t[n]=e[n])}),t},each:function(t,e,n){var i=Object.prototype.hasOwnProperty,a=Array.prototype.forEach,o={};if(null==t)return!1;if(a&&t.forEach===a)t.forEach(e,n);else if(t.length===+t.length){for(var r=0,s=t.length;r<s;r++)if(r in t&&e.call(n,t[r],r,t)===o)return!1}else for(var p in t)if(i.call(t,p)&&e.call(n,t[p],p,t)===o)return!1},xhr:function(t){if(t)return"undefined"!=typeof window.XMLHttpRequest&&"withCredentials"in new XMLHttpRequest?new XMLHttpRequest:"undefined"!=typeof XDomainRequest?new XDomainRequest:null;if("undefined"!=typeof window.XMLHttpRequest)return new XMLHttpRequest;if(window.ActiveXObject)try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(e){try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e){}}},ajax:function(t){function e(t){if(!t)return"";try{return JSON.parse(t)}catch(e){return{}}}function n(){try{o.isObject(i)&&i.abort&&i.abort()}catch(e){sd.log(e)}a&&(clearTimeout(a),a=null,t.error&&t.error(),i.onreadystatechange=null,i.onload=null,i.onerror=null)}t.timeout=t.timeout||2e4,t.credentials="undefined"==typeof t.credentials||t.credentials;var i=o.xhr(t.cors);if(!i)return!1;t.type||(t.type=t.data?"POST":"GET"),t=o.extend({success:function(){},error:function(){}},t);var a,r=t.success,s=t.error;t.success=function(t){r(t),a&&(clearTimeout(a),a=null)},t.error=function(t){s(t),a&&(clearTimeout(a),a=null)},a=setTimeout(function(){n()},t.timeout),"undefined"!=typeof XDomainRequest&&i instanceof XDomainRequest&&(i.onload=function(){t.success&&t.success(e(i.responseText)),i.onreadystatechange=null,i.onload=null,i.onerror=null},i.onerror=function(){t.error&&t.error(e(i.responseText),i.status),i.onreadystatechange=null,i.onerror=null,i.onload=null}),i.onreadystatechange=function(){try{4==i.readyState&&(i.status>=200&&i.status<300||304==i.status?t.success(e(i.responseText)):t.error(e(i.responseText),i.status),i.onreadystatechange=null,i.onload=null)}catch(n){i.onreadystatechange=null,i.onload=null}},i.open(t.type,t.url,!0);try{t.credentials&&(i.withCredentials=!0),o.isObject(t.header)&&o.each(t.header,function(t,e){i.setRequestHeader&&i.setRequestHeader(e,t)}),t.data&&(t.cors||i.setRequestHeader&&i.setRequestHeader("X-Requested-With","XMLHttpRequest"),"application/json"===t.contentType?i.setRequestHeader&&i.setRequestHeader("Content-type","application/json; charset=UTF-8"):i.setRequestHeader&&i.setRequestHeader("Content-type","application/x-www-form-urlencoded"))}catch(p){sd.log(p)}i.send(t.data||null)},getUuid:function(){var t=function(){for(var t=1*new Date,e=0;t==1*new Date;)e++;return t.toString(16)+e.toString(16)},e=function(){return Math.random().toString(16).replace(".","")};return function(){var n=t()+"-"+e()+"-"+e();return n?n:(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15)}},trim:function(t){return t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},isEmptyObject:function(t){var e=Object.prototype.hasOwnProperty;if(o.isObject(t)){for(var n in t)if(e.call(t,n))return!1;return!0}return!1},filter:function(t,e,n){var i=Object.prototype.hasOwnProperty;if(t.filter)return t.filter(e);for(var a=[],o=0;o<t.length;o++)if(i.call(t,o)){var r=t[o];e.call(n,r,o,t)&&a.push(r)}return a},isObject:function(t){return null!=t&&"[object Object]"==Object.prototype.toString.call(t)},getConvertNumberValue:function(t){return o.isString(t)&&(t=Number(t)),Math.floor(1e3*t)/1e3},isArray:Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)},isString:function(t){return"[object String]"==Object.prototype.toString.call(t)},isDate:function(t){return"[object Date]"==Object.prototype.toString.call(t)},isBoolean:function(t){return"[object Boolean]"==Object.prototype.toString.call(t)},isNumber:function(t){return"[object Number]"==Object.prototype.toString.call(t)&&/[\d\.]+/.test(String(t))},isFunction:function(t){if(!t)return!1;var e=Object.prototype.toString.call(t);return"[object Function]"==e||"[object AsyncFunction]"==e},getURLSearchParams:function(t){t=t||"";for(var e=function(t){return decodeURIComponent(t)},n={},i=t.substring(1),a=i.split("&"),o=0;o<a.length;o++){var r=a[o].indexOf("=");if(r!==-1){var s=a[o].substring(0,r),p=a[o].substring(r+1);s=e(s),p=e(p),n[s]=p}}return n},URL:function(t){var e={},n=["hash","host","hostname","href","origin","password","pathname","port","protocol","search","username"],i=function(){var t;try{return t=new URL("http://modernizr.com/"),"http://modernizr.com/"===t.href}catch(e){return!1}};if("function"==typeof window.URL&&i())e=new URL(t),e.searchParams||(e.searchParams=function(){var t=o.getURLSearchParams(e.search);return{get:function(e){return t[e]}}}());else{var a=/^https?:\/\/.+/;if(a.test(t)===!1)throw"Invalid URL";var r=document.createElement("a");r.href=t;for(var s=n.length-1;s>=0;s--){var p=n[s];e[p]=r[p]}e.hostname&&"string"==typeof e.pathname&&0!==e.pathname.indexOf("/")&&(e.pathname="/"+e.pathname),e.searchParams=function(){var t=o.getURLSearchParams(e.search);return{get:function(e){return t[e]}}}()}return e},contentLoaded:function(t,e){var n=!1,i=!0,a=t.document,o=a.documentElement,r=a.addEventListener,s=r?"addEventListener":"attachEvent",p=r?"removeEventListener":"detachEvent",u=r?"":"on",l=function(i){"readystatechange"==i.type&&"complete"!=a.readyState||(("load"==i.type?t:a)[p](u+i.type,l,!1),!n&&(n=!0)&&e.call(t,i.type||i))},c=function(){try{o.doScroll("left")}catch(t){return void setTimeout(c,50)}l("poll")};if("complete"==a.readyState)e.call(t,"lazy");else{if(!r&&o.doScroll){try{i=!t.frameElement}catch(_){}i&&c()}a[s](u+"DOMContentLoaded",l,!1),a[s](u+"readystatechange",l,!1),t[s](u+"load",l,!1)}},indexOf:function(t,e){var n=t.indexOf;if(n)return n.call(t,e);for(var i=0;i<t.length;i++)if(e===t[i])return i;return-1}};a._=o,a.isSupportPopup=function(){return o.localStorage.isSupport()},a.listenPageStateChange=function(){var t=!0;o.visibility({onVisible:function(){a.log("\u9875\u9762\u89e6\u53d1visible-",(new Date).getMinutes(),"\u5206",(new Date).getSeconds()),t===!1&&(a.updateDataAndSetListen.startState(),t=!0)},onHidden:function(){a.log("\u9875\u9762\u89e6\u53d1hidden-",(new Date).getMinutes(),"\u5206",(new Date).getSeconds()),t===!0&&(a.updateDataAndSetListen.stopAllState(),t=!1)}})},a.getWebSDK=function(){return!!(o.isObject(window.sensorsDataAnalytic201505)&&o.isObject(window.sensorsDataAnalytic201505.readyState)&&window.sensorsDataAnalytic201505.readyState.state>=3)&&window.sensorsDataAnalytic201505},a.getPopupInfo=function(t){function e(t){o.each(t.subviews,function(t){var i=t.properties||{};"title"===i.msgType?n.$sf_msg_title=i.text:"content"===i.msgType?n.$sf_msg_content=i.text:"image"===t.type&&(n.$sf_msg_image_url=i.image),t.subviews&&e(t)})}if(!o.isObject(t)||!o.isObject(t.template))return{};var n={$sf_msg_title:"",$sf_msg_content:"",$sf_msg_image_url:""};return e(t.template),n},a.getSFCampaign=function(t){t=o.isObject(t)?t:{};var e={planId:"",name:"",content:null,type:""};return e.planId=t.plan_id||"",e.name=t.cname||"",e.content=o.isObject(t.popup_window_content)?t.popup_window_content.content:"",e.type=o.isObject(t.popup_window_content)&&t.popup_window_content.popup_type?t.popup_window_content.popup_type:"PRESET",e},a.getImageList=function(t){if(!o.isArray(t))return!1;for(var e,n,i=new RegExp('("(backgroundImage|image)":"(http(s)?://.[^"]*)")',"g"),a=new RegExp('http(s)?://.[^S^"]*'),r={},s=t.length,p=[],u=!1,l=0;l<s;l++)if(o.isObject(t[l])&&"ACTIVE"===t[l].status.toLocaleUpperCase()&&t[l].is_audience===!0&&(u=t[l].strategy_id?t[l].is_trigger!==!1:t[l].is_control_group!==!0,u&&t[l].popup_window_content&&t[l].popup_window_content.content&&(e=t[l].popup_window_content.content.match(i))))for(var c=0,_=e.length;c<_;c++)n=e[c].match(a),n&&n.length>0&&(r[n[0]]||(r[n[0]]=1));return o.each(r,function(t,e){p.push(e)}),p},a.setIsLoad=function(){var t=window.self===window.top;if(t){if(window[a.config.loadedSign])return!1;if("undefined"==typeof window[a.config.loadedSign])return window[a.config.loadedSign]=!0,!0}else try{return!window.top[a.config.loadedSign]&&(window.top[a.config.loadedSign]=!0,!0)}catch(e){return a.log("\u975e\u540c\u57df\u540diframe\u5185\u5d4c\u4e0d\u80fd\u83b7\u53d6\u7236\u7ea7\u7a97\u4f53\u5185\u5bb9",e),!0}},a.handlerCampaign=function(t){var e=t,n=o.getUuid()(),i=e.plan.popup_window_content;if(!o.isObject(i))return e.popupFailed(1001,!1,{uuid:n,content:"",plan:e.plan}),!1;var r;if(i.content)try{r=JSON.parse(i.content)}catch(s){a.log(s)}var p=a.getSFCampaign(e.plan),u={state:"",isCustom:!1},l=!0;try{l=a.info.popup_campaign_listener.shouldStart(p)}catch(s){l=!1,a.log(s)}var c={uuid:n,content:r,plan:e.plan};switch(e.plan.is_trigger?l?"CUSTOMIZED"===i.popup_type?"withoutCampaignListener"===a.info.supportCustom?u.state="CAMPAIGN_CUSTOMIZED_NULL_LISTENER":"withoutStart"===a.info.supportCustom?u.state="CAMPAIGN_CUSTOMIZED_LISTENER_NULL_START":o.isString(i.content)?u.state="CAMPAIGN_TRIGGER_CUSTOMIZED_START":u.state="DIALOG_NOT_SHOW_JSON_FAILED":("PRESET"===i.popup_type&&a.log("\u6b64\u7248\u672csdk\u4e0d\u652f\u6301\u9884\u7f6e\u5f39\u7a97"),u.state="DIALOG_NOT_SHOW_JSON_FAILED"):u.state="CAMPAIGN_NOT_START_LISTENER_START":u.state="CAMPAIGN_NOT_START_TRIGGER",u.isCustom=!(!i.popup_type||"CUSTOMIZED"!==i.popup_type),a.log("campaign:",u,"plan:",e.plan.cname),u.state){case"CAMPAIGN_TRIGGER_CUSTOMIZED_START":e.customCampaign(c);break;case"CAMPAIGN_NOT_START_LISTENER_START":e.popupFailed(1004,u.isCustom,c);break;case"CAMPAIGN_CUSTOMIZED_NULL_LISTENER":e.popupFailed(1006,u.isCustom,c);break;case"CAMPAIGN_CUSTOMIZED_LISTENER_NULL_START":e.popupFailed(1006,u.isCustom,c);break;case"DIALOG_NOT_SHOW_JSON_FAILED":e.popupFailed(1001,u.isCustom,c);break;case"CAMPAIGN_NOT_START_TRIGGER":e.popupFailed(1005,u.isCustom,c);break;default:a.log("CampaignState\u5f02\u5e38")}},a.track={getPublicProps:function(t){var e=t.plan,n={$sf_lib_version:a.lib_version,$sf_plan_type:"\u8fd0\u8425\u8ba1\u5212",$sf_channel_service_name:"SENSORS_FOCUS",$sf_channel_category:"POPUP",$sf_platform_tag:a.info.platform,$sf_msg_id:t.$sf_msg_id};return o.isEmptyObject(e)||!o.isObject(e)?n:(n.$sf_plan_id=e.plan_id+"",n.$sf_plan_strategy_id=e.strategy_id?e.strategy_id:e.is_control_group?"-1":"0",e.audience_id&&(n.$sf_audience_id=e.audience_id+""),e.section_id&&(n.$sf_section_id=String(e.section_id),n.$sf_plan_type="\u65b0\u8d44\u6e90\u4f4d"),n)},popupDisplay:function(t){var e={$sf_msg_title:t.$sf_msg_title,$sf_msg_content:t.$sf_msg_content,$sf_msg_image_url:t.$sf_msg_image_url,$sf_succeed:t.$sf_succeed,$sf_fail_reason:t.$sf_fail_reason};this.trackEvent("$PlanPopupDisplay",e,t)},trackEvent:function(t,e,n){var i=a.track.getPublicProps(n);o.extend(e,i),o.each(e,function(t,n){""!==t&&void 0!==t||delete e[n]}),a.sa.track(t,e)},maskClick:function(t){if(!t.msg)return!1;var e={$sf_close_type:"POPUP_CLOSE_MASK",$sf_msg_title:t.msg.$sf_msg_title,$sf_msg_content:t.msg.$sf_msg_content,$sf_msg_image_url:t.msg.$sf_msg_image_url,$sf_msg_element_type:"mask",$sf_msg_action_id:t.properties.maskActionId};this.trackEvent("$PlanPopupClick",e,t.msg),t.destory()},elementClickCallback:function(t,e){var n=t.target,i=n.getAttribute("data-action"),r=n.getAttribute("data-info"),s=e.msg||{};if(!i)return!1;try{var p=JSON.parse(i)||{},u=p[0],l=JSON.parse(r)||{}}catch(t){a.log("elementClickCallback error",t)}var c={type:u.type,value:o.isString(u.value)?u.value:"",extra:o.isObject(u.value)?u.value:""},_=e.msg.plan?e.msg.plan.plan_id:"",d={$sf_msg_title:s.$sf_msg_title,$sf_msg_content:s.$sf_msg_content,$sf_msg_image_url:s.$sf_msg_image_url,$sf_msg_element_type:l.$sf_msg_element_type,$sf_msg_element_content:l.$sf_msg_element_content,$sf_msg_element_action:u.type,$sf_msg_action_id:u.id,$sf_close_type:"close"===u.type?u.$sf_close_type:""};this.trackEvent("$PlanPopupClick",d,s);try{a.info.popup_listener.onClick(_,c)}catch(t){a.log("popup_listener.onClick error",t)}if("close"===u.type)e.destory();else if(u.closeable?e.destory():null,"auto"===a.info.popup_listener.openlink&&"openlink"===u.type){if("http"!==u.value.slice(0,4))return!1;window.location.href=u.value}}};var r=a.log;a.changeCovertStatus=function(t){var e=JSON.parse(JSON.stringify(a.convertPlans));o.each(e,function(e,n){if(!e.is_in_convert_window)return!1;var i=e.is_in_convert_window.step,s=e.is_in_convert_window.uuid;return a.convertPlans[n].is_in_convert_window.step=Math.min(2*i,6e5),!!t&&void o.each(t,function(t){t.popup_display_uuid===s&&t.convert_time&&(r("--\u8f6c\u5316\u7a97\u53e3- \u76ee\u6807\u4e8b\u4ef6\u5df2\u7ecf\u5b8c\u6210 - \u6ee1\u8db3",a.convertPlans[n].plan_id),delete a.convertPlans[n].is_in_convert_window,a.convertPlans.splice(n,1))})}),a.updateDataAndSetListen.updateLocalData()},a.asyncConvert=function(t){function e(){if(o.isEmptyObject(a.localData)||!o.isArray(a.convertPlans)||0===a.convertPlans.length)return!1;var t=JSON.parse(JSON.stringify(a.convertPlans)),i=t[0].is_in_convert_window&&t[0].is_in_convert_window.step||5e3,s=[];return o.each(t,function(t,e){if(!t.is_in_convert_window)return!1;var n=(new Date).getTime(),o=t.is_in_convert_window.expire_time;return n>o?(r("--\u8f6c\u5316\u7a97\u53e3\u8d85\u65f6\u5df2\u7ecf\u8fc7\u671f - \u6ee1\u8db3",a.convertPlans[e].plan_id),delete a.convertPlans[e].is_in_convert_window,a.convertPlans.splice(e,1),a.updateDataAndSetListen.updateLocalData(),!1):(s.push(t.is_in_convert_window.uuid),t.is_in_convert_window.step||(t.is_in_convert_window.step=5e3,a.convertPlans[e].is_in_convert_window.step=5e3),void(i>t.is_in_convert_window.step&&(i=t.is_in_convert_window.step)))}),!!s.length&&(a.asyncConvert.timer&&clearTimeout(a.asyncConvert.timer),void(a.asyncConvert.timer=setTimeout(function(){o.ajax({url:a.info.api_base_url+"/sfo/popup_displays?project="+encodeURIComponent(n)+"&popup_display_uuids="+encodeURIComponent(s)+"&time="+(new Date).getTime(),type:"GET",cors:!0,credentials:!1,contentType:"application/json",success:function(t){a.changeCovertStatus(t),e()},error:function(){a.changeCovertStatus(),e()}})},i)))}var n=a.info.project,i=!1;return!(!t&&0===a.convertPlans.length)&&(t&&(o.each(a.convertPlans,function(e){e.plan_id===t.plan_id&&(i=!0)}),i||a.convertPlans.push(t)),void e())},a.ruleTime={getExpire:function(t,e){var n=e,i=Number(t.value)||0,a=Number(t.value)||0,o=String(t.unit).toLowerCase(),r=null,s={day:function(){return r=new Date(n),r.setHours(23),r.setMinutes(59),r.setSeconds(59),r.setMilliseconds(999),r=r.getTime()+864e5*(a-1)},week:function(){r=new Date(n);var t=r.getDay();0===t&&(t=7);var e=7-t;return r.setHours(23),r.setMinutes(59),r.setSeconds(59),r.setMilliseconds(999),r=r.getTime()+24*e*60*60*1e3+7*(a-1)*24*60*60*1e3},month:function(){r=new Date(n);var t=r.getMonth(),e=t+a;return e>=11?(r.setFullYear(r.getFullYear()+parseInt(e/12)),r.setMonth(e%12)):r.setMonth(e),r.setDate(1),r.setHours(0),r.setMinutes(0),r.setSeconds(0),r.setMilliseconds(0),r.getTime()},second:function(t){var e={month:2592e6,week:6048e5,day:864e5,hour:36e5,minute:6e4,second:1e3},a=null;return r=new Date(n),t in e&&(a=e[t]*i),r.getTime()+a}};return t.natural!==!0?s.second(o):o in s?s[o]():void 0},getLast:function(t,e){var n=Number(t.value)||0,i=Number(t.value)-1||0,a=String(t.unit).toLowerCase(),o=null,r={day:function(){return o=new Date(e),o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0),o=o.getTime()-864e5*i},week:function(){o=new Date(e);var t=o.getDay();return 0===t&&(t=7),--t,o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0),o=o.getTime()-(24*t*60*60*1e3+7*i*24*60*60*1e3)},month:function(){o=new Date(e);var t=o.getMonth()+1,n=t-i;return n<=0?(o.setFullYear(o.getFullYear()+(parseInt(n/12)-1)),o.setMonth(12+n%12-1)):o.setMonth(n-1),o.setDate(1),o.setHours(0),o.setMinutes(0),o.setSeconds(0),o.setMilliseconds(0),o.getTime()},second:function(t){var i={month:2592e6,week:6048e5,day:864e5,hour:36e5,minute:6e4,second:1e3},a=null;return o=new Date(e),t in i&&(a=i[t]*n),o.getTime()-a}};return t.natural!==!0?r.second(a):a in r?r[a]():void 0},getArrMatchCount:function(t,e){var n=0;for(n=0;n<t.length;n++)if(e>=t[n])return n;return t.length}},a.eventTriggerProcess=function(){if(!a.updateDataAndSetListen.active_state)return!1;if(!o.isArray(a.localData.eventQueue))return!1;if(0===a.localData.eventQueue.length)return!1;if(a.isRun)return!1;r("\u4e8b\u4ef6\u961f\u5217---eventQueue",a.localData.eventQueue);var t=!1,e=a.localData.eventQueue[0],n=a.eventRule[e.event];a.isRun=!0,a.localData.eventQueue.shift(),a.updateDataAndSetListen.updateLocalData(),o.isArray(n)&&o.isObject(n[0])&&n.length>0&&(r("--------------------\u89e6\u53d1\u4e8b\u4ef6\u5f00\u59cb--------------------"),o.each(n,function(t){o.isObject(t)&&"undefined"!=typeof t.match_state&&delete t.match_state,new a.RuleCheck(t,e)}),o.each(n,function(e){e.match_state===!0?t===!1?(t=!0,r("\u68c0\u67e5\u5b8c\u6bd5-\u4f18\u5148\u5f39\u7a97-\u5f00\u59cb",e.plan.cname),new a.PopupCheck(e,(!0))):t===!0&&(r("\u68c0\u67e5\u5b8c\u6bd5-\u975e\u4f18\u5148\u5f39\u7a97-\u4e0d\u6e32\u67d3",e.plan.cname),new a.PopupCheck(e,(!1))):r("\u68c0\u67e5\u5b8c\u6bd5-\u8ba1\u5212-\u4e0d\u6ee1\u8db3",e.plan.cname)}),t||a.completeWindowLifecycle(),r("--------------------\u89e6\u53d1\u4e8b\u4ef6\u7ed3\u675f--------------------"))},a.completeWindowLifecycle=function(){a.isRun=!1,a.eventTriggerProcess()},a.PopupCheck=function(t,e){this.plan=t.plan,this.current_time=(new Date).getTime(),e?this.renderPopup():this.hidePopup(),a.updateDataAndSetListen.updateLocalData()},a.PopupCheck.prototype.createPopupWindow=function(t,e){this.startConvertWindow(t),this.startPopupIntervalWindow(this.current_time),this.startPopupLimitWindow(),this.setGlobalLimit(),this.deletePlanAllWindow(),e&&a.completeWindowLifecycle()},a.PopupCheck.prototype.hidePopup=function(){this.deletePlanAllWindow()},a.PopupCheck.prototype.renderPopup=function(){a.handlerCampaign(this)},a.PopupCheck.prototype.popupFailed=function(t,e,n){var i={1001:"\u9884\u89c8\u4fe1\u606f\u89e3\u6790\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u8ba1\u5212\u914d\u7f6e",1003:"\u5bf9\u7167\u7ec4",1004:"campaignShouldStart \u63a5\u53e3\u8fd4\u56de false",1005:"\u8ba1\u5212\u4e0b\u53d1 is_trigger \u4e3a false",1006:"\u81ea\u5b9a\u4e49\u89e6\u8fbe\u8ba1\u5212\u672a\u5b9e\u73b0\u5f39\u7a97\u751f\u547d\u5468\u671f\u56de\u8c03"},r=i[t],s=a.getPopupInfo(n.content);s.$sf_msg_id=n.uuid,s.plan=n.plan,s.$sf_succeed=!1,s.$sf_fail_reason=r,a.track.popupDisplay(s),!e&&a.info.popup_listener&&o.isFunction(a.info.popup_listener.onLoadFailed)&&a.info.popup_listener.onLoadFailed(n.plan.plan_id,t,r),a.info.popup_campaign_listener.onFailed(a.getSFCampaign(n.plan),t,r),this.createPopupWindow(n.uuid,!0)},a.PopupCheck.prototype.customCampaign=function(t){var e=a.getSFCampaign(t.plan),n=a.getPopupInfo(t.content);n.$sf_msg_id=t.uuid,n.plan=t.plan,n.$sf_succeed=!0,a.track.popupDisplay(n),a.info.popup_campaign_listener.onStart(e),this.createPopupWindow(t.uuid,!0)},a.PopupCheck.prototype.showPopup=function(t){if(!a.ElementRender)return a.log("\u6682\u4e0d\u652f\u6301\u9884\u7f6e\u5f39\u7a97UI"),!1;var e=new a.ElementRender(t.content),n=a.getPopupInfo(t.content);n.$sf_msg_id=t.uuid,n.plan=t.plan,n.$sf_succeed=!0,o.extend(e.msg,n),e.popupCheckInstance=this,a.track.popupDisplay(n);var i=e.render();return i?(a.info.popup_campaign_listener.onStart(a.getSFCampaign(t.plan)),this.createPopupWindow(t.uuid),void a.info.popup_listener.onLoadSuccess(t.plan.plan_id)):(r("\u5f53\u524d\u9875\u9762\u5df2\u6709\u4e00\u4e2a\u5f39\u6846\u6b63\u5728\u6e32\u67d3\uff0c\u672c\u6b21\u5f39\u6846\u4e0d\u6e32\u67d3\uff01"),!1)},a.PopupCheck.prototype.startConvertWindow=function(t){r("--\u5f39\u7a97\u5c55\u793a-\u8f6c\u5316\u7a97\u53e3\u8bbe\u7f6e",this.plan.cname),o.isObject(this.plan.convert_window)&&this.plan.convert_window.value&&(this.plan.is_in_convert_window={expire_time:a.ruleTime.getExpire(this.plan.convert_window,this.current_time),start_time:this.current_time,uuid:t},a.asyncConvert(this.plan))},a.PopupCheck.prototype.startPopupIntervalWindow=function(t){o.isObject(this.plan.popup_interval)&&this.plan.popup_interval.value&&(this.plan.is_in_popup_interval_window=a.ruleTime.getExpire(this.plan.popup_interval,t))},a.PopupCheck.prototype.resetPopupIntervalWindow=function(){var t=(new Date).getTime();this.startPopupIntervalWindow(t),this.resetGlobalLimit(t),a.completeWindowLifecycle()},a.PopupCheck.prototype.startPopupLimitWindow=function(){r("--\u5f39\u7a97\u5c55\u793a-\u53c2\u4e0e\u9650\u5236\u7a97\u53e3\u8bbe\u7f6e\u91cd\u7f6e"),o.isObject(this.plan.re_enter)&&this.plan.re_enter.value&&(o.isObject(this.plan.is_in_popup_limit_window)?this.plan.is_in_popup_limit_window.count++:this.plan.is_in_popup_limit_window={expire_time:a.ruleTime.getExpire(this.plan.re_enter,this.current_time),count:1})},a.PopupCheck.prototype.setGlobalLimit=function(){r("--\u5f39\u7a97\u5c55\u793a-\u5168\u5c40\u5f39\u7a97\u6b21\u6570\u8bbe\u7f6e"),o.isArray(a.localData.global_popup_count)||(a.localData.global_popup_count=[]),a.localData.global_popup_count.unshift(this.current_time);for(var t=a.localData.global_popup_count,e=t[t.length-1];e+7776e6<this.current_time||t.length>3e3;)t.pop(),e=t[t.length-1]},a.PopupCheck.prototype.resetGlobalLimit=function(t){o.isArray(a.localData.global_popup_count)&&a.localData.global_popup_count.length>0&&(a.localData.global_popup_count.shift(),a.localData.global_popup_count.unshift(t))},a.PopupCheck.prototype.deletePlanAllWindow=function(){var t=this.plan.pattern_popup.matcher_list;o.isArray(t)&&o.each(t,function(t){t.is_in_window&&(r("--\u5f39\u7a97\u5c55\u793a-\u91cd\u7f6e\u5404\u4e2a\u89c4\u5219\u7684\u7a97\u53e3\u8ba1\u7b97-\u6210\u529f"),delete t.is_in_window)})},a.RuleCheck=function(t,e){this.plan_match=t,this.plan=t.plan,this.rule_arr=t.rule,this.event_data=e,this.current_time=(new Date).getTime();var n="-------------\u68c0\u67e5-\u8ba1\u5212-("+this.plan.cname+")";o.each(this.rule_arr,function(t){n+="--\u5305\u542b\u89c4\u5219-("+t.event_name+"\uff09-\u89e6\u53d1"+t.params[0]+"\u6b21"}),r(n),r(this.plan),this.checkPlanIsExpire(),a.updateDataAndSetListen.updateLocalData()},a.RuleCheck.prototype.checkPlanIsExpire=function(){!this.plan.expire_at||o.isNumber(this.plan.expire_at)&&this.current_time<this.plan.expire_at?(r("--\u8fc7\u671f-\u6ee1\u8db3",this.plan.cname),this.checkPlanIsAudience()):r("--\u8fc7\u671f-\u4e0d\u6ee1\u8db3",this.plan.cname)},a.RuleCheck.prototype.checkPlanIsAudience=function(){this.plan.is_audience===!0?(r("--\u662f\u5426\u53d7\u4f17-\u6ee1\u8db3",this.plan.cname),this.checkPlanSuspend()):r("--\u662f\u5426\u53d7\u4f17-\u4e0d\u6ee1\u8db3",this.plan.cname)},a.RuleCheck.prototype.checkPlanSuspend=function(){this.plan.status&&"SUSPEND"===this.plan.status?r("--\u6682\u505c-\u4e0d\u6ee1\u8db3",this.plan.cname):(r("--\u6682\u505c-\u6ee1\u8db3",this.plan.cname),this.checkConvert())},a.RuleCheck.prototype.checkConvert=function(){if(o.isObject(this.plan.is_in_convert_window)&&this.plan.is_in_convert_window.expire_time>this.current_time)r("--\u5b58\u5728\u8f6c\u5316\u7a97\u53e3 - \u4e0d\u6ee1\u8db3",this.plan.is_in_convert_window);else if(o.isObject(this.plan.is_in_convert_window)&&this.current_time>this.plan.is_in_convert_window.expire_time){r("--\u8f6c\u5316\u7a97\u53e3\u8d85\u65f6\u5df2\u7ecf\u8fc7\u671f - \u6ee1\u8db3",this.plan.plan_id),delete this.plan.is_in_convert_window;for(var t=0;t<a.convertPlans.length;t++)this.plan.plan_id===a.convertPlans[t].plan_id&&(a.convertPlans.splice(t,1),t--);this.checkGlobalPopupInterval()}else r("--\u4e0d\u5b58\u5728\u8f6c\u5316\u7a97\u53e3 - \u6ee1\u8db3",this.plan.is_in_convert_window),this.checkGlobalPopupInterval()},a.RuleCheck.prototype.checkGlobalPopupInterval=function(){var t=a.localData.global_popup_count;if(o.isArray(t)&&t.length>=1){var e=a.ruleTime.getLast(a.localData.popup_interval_global,this.current_time);e>t[0]?(r("--\u5168\u5c40\u5f39\u7a97\u95f4\u9694-\u6ee1\u8db3-"+e+">\u4e0a\u6b21\u5f39\u7a97\u65f6\u95f4"+t[0]),this.checkPopupInterval()):r("\u68c0\u67e5-\u5168\u5c40\u5f39\u7a97\u95f4\u9694-\u4e0d\u6ee1\u8db3-"+e+"<\u4e0a\u6b21\u5f39\u7a97\u65f6\u95f4"+t[0])}else r("--\u5168\u5c40\u5f39\u7a97\u95f4\u9694-\u6ca1\u6709\u5f39\u8fc7\u7a97-\u6ee1\u8db3"),this.checkPopupInterval()},a.RuleCheck.prototype.checkPopupInterval=function(){o.isNumber(this.plan.is_in_popup_interval_window)?this.current_time>this.plan.is_in_popup_interval_window?(r("--\u5f39\u7a97\u95f4\u9694-\u5f53\u524d\u65f6\u95f4\u5927\u4e8e\u56fa\u5b9a\u5f39\u7a97\u95f4\u9694-\u6ee1\u8db3"),this.plan.is_in_popup_interval_window=null,this.checkProperties()):r("--\u5f39\u7a97\u95f4\u9694-\u5f53\u524d\u65f6\u95f4\u5c0f\u4e8e\u56fa\u5b9a\u5f39\u7a97\u95f4\u9694-\u4e0d\u6ee1\u8db3"):(r("--\u5f39\u7a97\u95f4\u9694-\u7a97\u53e3\u4e0d\u5b58\u5728-\u65b0\u5f00"),this.plan.is_in_popup_interval_window=null,this.checkProperties())},a.RuleCheck.prototype.checkProperties=function(){var t={equal:function(t,e){if(!o.isNumber(t)&&!o.isString(t))return!1;for(var n=0,i=e.length;n<i;n++){if(!o.isNumber(e[n])&&!o.isString(e[n]))return!1;if(o.isString(t)){var a=o.isString(e[n])?e[n]:String(e[n]);if(t===a)return!0}else if(o.getConvertNumberValue(t)===o.getConvertNumberValue(e[n]))return!0}return!1},notEqual:function(t,e){if(!o.isNumber(t)&&!o.isString(t))return!1;for(var n=0,i=e.length;n<i;n++){if(!o.isNumber(e[n])&&!o.isString(e[n]))return!1;if(o.isString(t)){var a=o.isString(e[n])?e[n]:String(e[n]);if(t===a)return!1}else if(o.getConvertNumberValue(t)===o.getConvertNumberValue(e[n]))return!1}return!0},contain:function(t,e){return!!o.isString(t)&&t.indexOf(e[0])>=0},notContain:function(t,e){return!!o.isString(t)&&t.indexOf(e[0])===-1},isTrue:function(t){return t===!0},isFalse:function(t){return t===!1},isSet:function(t){return"undefined"!=typeof t},notSet:function(t){return"undefined"==typeof t},isEmpty:function(t){if(!o.isString(t)&&!o.isArray(t))return!1;if(o.isString(t))return""===t;for(var e=0;e<t.length;e++){var n=t[e].replace(/^\s+|\s+$/g,"");if(""!==n)return!1}return!0},isNotEmpty:function(t){if(!o.isString(t)&&!o.isArray(t))return!1;if(o.isString(t))return""!==t;for(var e=0;e<t.length;e++){var n=t[e].replace(/^\s+|\s+$/g,"");if(""===n)return!1}return!0},less:function(t,e){return!!o.isNumber(t)&&("undefined"!=typeof e[0]&&o.getConvertNumberValue(t)<o.getConvertNumberValue(e[0]))},greater:function(t,e){return!!o.isNumber(t)&&("undefined"!=typeof e[0]&&o.getConvertNumberValue(t)>o.getConvertNumberValue(e[0]))},between:function(t,e){if(!o.isNumber(t))return!1;if("undefined"==typeof e[0]&&"undefined"==typeof e[1])return!1;var n=o.getConvertNumberValue(t),i=o.getConvertNumberValue(e[0]),a=o.getConvertNumberValue(e[1]);return n>=i&&n<=a},isIn:function(t,e){if(!o.isArray(t))return!1;for(var n=0;n<t.length;n++)if(o.indexOf(e,t[n])>=0)return!0;return!1},notInclude:function(t,e){if(!o.isArray(t))return!1;for(var n=0;n<t.length;n++)if(o.indexOf(e,t[n])===-1)return!0;return!1},absolute_between:function(t,e){try{var n=new Date(e[0]),i=new Date(e[1]),a=new Date(t);return a>=n&&a<=i}catch(o){r("absolute_between Error",o)}},absoluteBetween:function(t,e){try{var n=new Date(e[0]),i=new Date(e[1]),a=new Date(t);return a>=n&&a<=i}catch(o){r("absolute_between Error",o)}}},e=this,n=o.filter(this.rule_arr,function(n){if(!n.filter||n.filter.conditions&&0===n.filter.conditions.length)return!0;var i=n.filter,a=i.relation,r="or"===String(a).toLowerCase(),s="and"===String(a).toLowerCase(),p=!!s,u=!0;return o.each(i.conditions,function(n){if(!u)return!1;if(!n.field)return!1;var i=n.field.lastIndexOf("."),a=n.params,o="in"===n["function"]?"isIn":n["function"];if(!t[o])return p=!1,u=!1,!1;if(i<0)return!1;var l=n.field.slice(i+1),c=e.event_data.properties,_=c[l];"$event_duration"===l&&void 0===_&&(_=c.event_duration);var d=t[o](_,a);r&&d&&(p=!0,u=!1),s&&!d&&(p=!1,u=!1)}),p});o.isArray(n)&&n.length>0?(this.checkWindowAndMatch(n),r("--\u5c5e\u6027\u5339\u914d-\u6ee1\u8db3",n)):r("--\u5c5e\u6027\u5339\u914d-\u4e0d\u6ee1\u8db3")},a.RuleCheck.prototype.checkWindowAndMatch=function(t){var e=this,n=[];o.each(t,function(t){if(!t.params||!t.params[0])return r("--\u7a97\u53e3\u671f\u548c\u6b21\u6570-\u89c4\u5219\u6570\u636e\u5f02\u5e38"),!1;var i=Number(t.params[0]);1===i?n.push(t):i>1&&o.isObject(t.window)&&t.window.value>0&&(!o.isObject(t.is_in_window)||!o.isNumber(t.is_in_window.expire_time)||t.is_in_window.expire_time<e.current_time?t.is_in_window={expire_time:a.ruleTime.getExpire(t.window,e.current_time),count:1}:t.is_in_window.count=t.is_in_window.count+1,t.is_in_window.count>=i?n.push(t):r("--\u7a97\u53e3\u671f\u548c\u6b21\u6570-\u89c4\u5219\u6570",t.is_in_window.count,"\u4e0d\u5339\u914d\u5f53\u524d\u6b21\u6570",i))}),n.length>0?(r("--\u7a97\u53e3\u671f\u548c\u6b21\u6570-\u6709\u5339\u914d\u6210\u529f\u7684\u89c4\u5219",n),this.checkGlobalPopupLimit()):r("--\u7a97\u53e3\u671f\u548c\u6b21\u6570-\u6ca1\u6709\u5339\u914d\u6210\u529f\u7684\u89c4\u5219",n)},a.RuleCheck.prototype.checkGlobalPopupLimit=function(){var t=a.localData.msg_limit_global,e=!0,n=this;o.isObject(t)&&t.is_in_use===!0&&o.isArray(t.limits)&&o.isArray(a.localData.global_popup_count)&&this.plan.global_msg_limit_enabled===!0?(o.each(t.limits,function(t){if(o.isObject(t)&&o.isNumber(t.limit)){var i=a.ruleTime.getLast(t,n.current_time),s=a.ruleTime.getArrMatchCount(a.localData.global_popup_count,i);r("--\u5168\u5c40\u5f39\u7a97\u9650\u5236-\u5df2\u7ecf\u5f39\u7a97\u6b21\u6570-"+s+"-\u9650\u5236\u7684\u6b21\u6570"+t.limit+"-\u9650\u5236\u65f6\u95f4-"+i),e=s<t.limit?e&&!0:e&&!1}}),e?(r("--\u5168\u5c40\u5f39\u7a97\u9650\u5236- \u6ee1\u8db3"),this.checkPopupLimit()):r("--\u5168\u5c40\u5f39\u7a97\u9650\u5236-\u4e0d\u6ee1\u8db3")):(r("--\u5168\u5c40\u5f39\u7a97\u9650\u5236- \u6ee1\u8db3"),this.checkPopupLimit())},a.RuleCheck.prototype.checkPopupLimit=function(){
return o.isObject(this.plan.re_enter)&&o.isNumber(this.plan.re_enter.value)&&o.isNumber(this.plan.re_enter.limit)?void(o.isObject(this.plan.is_in_popup_limit_window)&&o.isNumber(this.plan.is_in_popup_limit_window.expire_time)&&o.isNumber(this.plan.is_in_popup_limit_window.count)?this.plan.is_in_popup_limit_window.expire_time<this.current_time?(r("--\u53c2\u4e0e\u9650\u5236-\u8d85\u8fc7\u4e86\u53c2\u4e0e\u9650\u5236\u7a97\u53e3-\u5f00\u542f\u65b0\u7a97\u53e3-\u6ee1\u8db3",this.plan.is_in_popup_limit_window),delete this.plan.is_in_popup_limit_window,this.plan_match.match_state=!0):this.plan.is_in_popup_limit_window.count<this.plan.re_enter.limit?(r("--\u53c2\u4e0e\u9650\u5236-\u5728\u7a97\u53e3\u5185\u4e14\u5728\u53c2\u4e0e\u9650\u5236\u6b21\u6570\u5185-\u6ee1\u8db3",this.plan.is_in_popup_limit_window),this.plan_match.match_state=!0):r("--\u53c2\u4e0e\u9650\u5236-\u5728\u7a97\u53e3\u5185\u4f46\u662f\u8d85\u8fc7\u4e86\u53c2\u4e0e\u9650\u5236-\u4e0d\u6ee1\u8db3",this.plan.is_in_popup_limit_window):(this.plan.is_in_popup_limit_window?(r("--\u53c2\u4e0e\u9650\u5236-\u6709\u7a97\u53e3\u4f46\u662f\u7a97\u53e3\u6570\u636e\u5f02\u5e38-\u5f00\u65b0\u7a97\u53e3-\u6ee1\u8db3",this.plan.is_in_popup_limit_window),delete this.plan.is_in_popup_limit_window):r("--\u53c2\u4e0e\u9650\u5236-\u4e0d\u5b58\u5728\u7a97\u53e3-\u5f00\u65b0\u7a97\u53e3-\u6ee1\u8db3",this.plan.is_in_popup_limit_window),this.plan_match.match_state=!0)):(this.plan_match.match_state=!0,!1)};var s="dfm-enc-";return a.store={delete_time:2592e6,init:function(){this.migrateLocalData(),a.localData=this.getLocalData(),o.isNumber(a.localData.config_pull_interval_ms)&&a.localData.config_pull_interval_ms>0&&(a.updateDataAndSetListen.interval_time=a.localData.config_pull_interval_ms),this.removeLocalData(),a.log("\u521d\u59cb\u5316-\u83b7\u53d6-\u5185\u5b58-localData")},getJSONData:function(){var t=o.localStorage.get(a.config.storageName);o.isString(t)&&(t=e(t));try{t=JSON.parse(t)}catch(n){o.log(n)}return t},saveJSONData:function(t){t=JSON.stringify(t),a.info.encrypt_cookie&&(t=n(t)),o.localStorage.set(a.config.storageName,t)},migrateLocalData:function(){var t=this.getJSONData()||{},e=a.sa.store.getDistinctId();if(t.popup_sdk_users&&t.popup_sdk_plans)return!1;var n={popup_sdk_plans:{},popup_sdk_users:{}};n.popup_sdk_plans[e]=t,n.popup_sdk_users[e]={user_id:e},this.saveJSONData(n)},getLocalData:function(){var t=this.getJSONData(),e=a.sa.store.getDistinctId(),n=null;return t?(o.isObject(t.popup_sdk_users[e])&&t.popup_sdk_users[e].user_id&&(n=t.popup_sdk_users[e].user_id),n&&o.isObject(t.popup_sdk_plans[n])?(t.popup_sdk_plans[n].update_time=(new Date).getTime(),this.saveJSONData(t),t.popup_sdk_plans[n]):{}):{}},saveLocalData:function(){var t=this.getJSONData(),e=a.sa.store.getDistinctId(),n=null;return!!t&&void(t.popup_sdk_users&&o.isObject(t.popup_sdk_users[e])&&t.popup_sdk_users[e].user_id&&(n=t.popup_sdk_users[e].user_id,t.popup_sdk_plans[n]=a.localData,this.saveJSONData(t)))},removeLocalData:function(){var t=this.getJSONData(),e=this.delete_time;if(!t||!t.popup_sdk_plans||!t.popup_sdk_users)return!1;var n=JSON.parse(JSON.stringify(t.popup_sdk_plans)),i=JSON.parse(JSON.stringify(t.popup_sdk_users)),a=(new Date).getTime(),r=[];o.each(n,function(n,i){a-n.update_time>e&&(delete t.popup_sdk_plans[i],r.push(i))}),o.each(i,function(e,n){r.length>0&&o.each(r,function(i){e.user_id&&i===e.user_id&&delete t.popup_sdk_users[n]})}),this.saveJSONData(t)}},a.updateDataAndSetListen={active_state:!0,interval_time:6e5,save_interval:null,data_interval:null,image_list:null,local_data:null,filterConvertPlans:function(){var t=a.localData.popup_plans;if(!t||!o.isArray(t))return!1;var e=o.filter(t,function(t){return!!t.convert_window&&!!t.is_in_convert_window});a.convertPlans=e,a.log("\u521d\u59cb\u5316-\u5f02\u6b65\u7684convertWindow",a.convertPlans),a.asyncConvert()},diffData:function(){var t=a.localData,e=JSON.parse(JSON.stringify(a.serverData)),n=(new Date).getTime();if(!e||o.isEmptyObject(e))return!1;var i=n-e.server_current_time;if(Math.abs(i)>=6e5)return!1;if(!t||o.isEmptyObject(t)||!t.popup_plans||0===t.popup_plans.length)return o.extend(a.localData,e),!1;var r=e.popup_plans;o.each(r,function(e,n){var i=null;if(o.each(t.popup_plans,function(t){t.plan_id===e.plan_id&&(i=t,e.audience_id||delete i.audience_id,o.isObject(e.window_update)&&o.each(e.window_update,function(t,n){i.window_update&&i.window_update[n]===t||("trigger_window"===n?i.pattern_popup.matcher_list=e.pattern_popup.matcher_list:"convert_window"===n&&i.is_in_convert_window&&e.convert_window&&i.is_in_convert_window.start_time&&(i.is_in_convert_window.expire_time=a.ruleTime.getExpire(e.convert_window,i.is_in_convert_window.start_time)))}))}),!i)return!1;if(!e.window_update&&i.last_update_config_time!==e.last_update_config_time)return!1;var s=i.pattern_popup.matcher_list;o.extend2Lev(i,e),i.pattern_popup.matcher_list=s,r[n]=i}),o.extend(a.localData,e)},getEventRule:function(){var t=a.localData.popup_plans,e={};return!(!t||!o.isArray(t))&&(o.each(t,function(t){var n=t.pattern_popup.matcher_list;o.each(n,function(n){var i={plan:t,rule:[n]},a=n.event_name,r=!1;if(e[a]){if(o.each(e[a],function(e){e.plan.plan_id===t.plan_id&&(e.rule.push(n),r=!0)}),r)return!1;e[a].push(i)}else e[a]=[i]})}),o.each(e,function(t){t.sort(function(t,e){var n=e.plan.absolute_priority-t.plan.absolute_priority;return 0===n?e.plan.plan_id-t.plan.plan_id:n})}),a.eventRule=e,a.log("\u521d\u59cb\u5316-\u5f97\u5230\u4e8b\u4ef6\u548c\u8ba1\u5212\u7684\u5173\u7cfb"),void a.log("--------------------\u521d\u59cb\u5316\u5b8c\u6210--------------------\u7b49\u5f85\u4e8b\u4ef6\u89e6\u53d1\u8ba1\u5212--------------------"))},registerListen:function(){var t=this;a.sa.events.on("send",function(e){e.event&&a.eventRule[e.event]&&(o.isArray(a.localData.eventQueue)||(a.localData.eventQueue=[]),a.localData.eventQueue.push(e),t.updateLocalData(),a.eventTriggerProcess())}),a.sa.events.on("changeDistinctId",function(e){t.changeId()}),a.sa.events.isReady()},setListenEvent:function(){this.diffData(),this.filterConvertPlans(),this.getEventRule(),this.updateLocalData()},loadImage:function(t){function e(t){var e=new Image;e.src=t}if(t.length<1)return!1;if(JSON.stringify(t)===JSON.stringify(this.image_list))return!1;this.image_list=t;for(var n=0;n<t.length;n++)e(t[n])},getDataFromServer:function(t,e){var n=this,i=encodeURIComponent(a.sa.store.getDistinctId()),r=encodeURIComponent(a.info.platform),s=encodeURIComponent(a.info.project);t=o.isFunction(t)?t:function(){},e=o.isFunction(e)?e:function(){},o.ajax({url:a.info.api_base_url+"/sfo/user_popup_configs?distinct_id="+i+"&platform="+r+"&project="+s+"&time="+(new Date).getTime()+"&sdk_version="+a.lib_version,type:"GET",cors:!0,credentials:!1,contentType:"application/json",success:function(i){return n.active_state?(a.log("\u521d\u59cb\u5316-\u4fee\u6539-serverData-ajax\u83b7\u53d6"),o.isObject(i)&&i.server_current_time&&i.popup_plans&&/\d+\.\d+/.test(i.min_sdk_version_required)&&parseFloat(i.min_sdk_version_required)<=parseFloat(a.lib_version)?(a.serverData=i,o.isNumber(i.config_pull_interval_ms)&&i.config_pull_interval_ms>0&&(n.interval_time=i.config_pull_interval_ms),a.serverData.local_update_time=(new Date).getTime(),a.info.preload_image&&n.loadImage(a.getImageList(i.popup_plans)),n.updateUserPlans(),n.setListenEvent()):(a.log("\u521d\u59cb\u5316-\u6570\u636e\u5f02\u5e38-\u8bf7\u6c42\u8fd4\u56de\u7684\u6570\u636e\u9519\u8bef-\u4e2d\u6b62"),a.serverData={},a.localData={},n.updateLocalData()),t(),void n.setIntervalTime(n.interval_time)):(e(),!1)},error:function(){return n.active_state?(a.log("\u521d\u59cb\u5316-\u6570\u636e\u5f02\u5e38-\u8bf7\u6c42\u9519\u8bef-\u4e2d\u6b62"),a.serverData={},t(),void n.setIntervalTime(n.interval_time)):(e(),!1)}})},updateUserPlans:function(){var t=a.store.getJSONData(),e=a.sa.store.getDistinctId(),n=a.serverData.user_id;t.popup_sdk_users[e]={user_id:n||e},n?t.popup_sdk_plans[n]?a.localData=t.popup_sdk_plans[n]:t.popup_sdk_plans[e]&&(a.localData=t.popup_sdk_plans[e],delete t.popup_sdk_plans[e]):t.popup_sdk_plans[e]&&(a.localData=t.popup_sdk_plans[e]),a.localData.update_time=(new Date).getTime(),a.store.saveJSONData(t)},setIntervalTime:function(t){var e=this;this.data_interval=setTimeout(function(){a.log("10\u5206\u949f\u5b9a\u65f6\u66f4\u65b0\u6570\u636e\u5f00\u59cb-------"),e.getDataFromServer()},t)},setFirstListen:function(){var t=this;this.getDataFromServer(function(){t.registerListen()})},updateLocalData:function(){var t=JSON.stringify(a.localData);this.local_data!==t&&(this.local_data=t,a.store.saveLocalData())},initial:function(){a.store.init();var t=a.localData.local_update_time,e=(new Date).getTime();if(o.isNumber(t)){var n=e-t;n<=0||n>=this.interval_time?this.setFirstListen():(this.setIntervalTime(this.interval_time-n),this.setListenEvent(),this.registerListen(),a.info.preload_image&&this.loadImage(a.getImageList(a.localData.popup_plans)))}else this.setFirstListen()},changeId:function(){this.stopAllState(),this.startState({getLocalData:!1})},stopAllState:function(){this.active_state=!1,a.eventRule={},this.data_interval&&window.clearTimeout(this.data_interval),this.save_interval&&window.clearInterval(this.save_interval),a.asyncConvert.timer&&window.clearTimeout(a.asyncConvert.timer),a.convertPlans=[],a.localData={},this.resetState()},resetState:function(){return"WEB"!==a.info.platform&&void(!document.querySelector("div[data-sf-mask]")&&a.isRun&&(a.isRun=!1))},startState:function(t){this.active_state=!0,t=t||{getLocalData:!0},t.getLocalData&&(this.resetState(),a.localData=a.store.getLocalData()),this.getDataFromServer()}},a.testSend={hasParam:function(){var t=o.URL(window.location.href).searchParams,e=t.get("sf_popup_test")||"",n=t.get("popup_window_id")||"",i=t.get("platform");return!(!e||!n)&&{sf_popup_test:e,popup_window_id:n,platform:i}},start:function(){var t=this.hasParam().platform;return"WEB"!==t?(a.log("H5\u6d4b\u8bd5\u5f39\u7a97\u8bf7\u5728\u79fb\u52a8\u7aef\u67e5\u770b\uff01"),!1):void this.webCampaign()},webCampaign:function(){var t=a.info.project,e=a.info.platform,n=this.hasParam().popup_window_id,i=encodeURIComponent(a.sa.store.getDistinctId());o.ajax({url:a.info.api_base_url+"/sfo/popup_windows/"+n+"?project="+encodeURIComponent(t)+"&time="+(new Date).getTime()+"&sdk_version="+a.lib_version+"&platform="+encodeURIComponent(e)+"&distinct_id="+i,type:"GET",credentials:!1,cors:!0,contentType:"application/json",success:function(t){var e,n=o.getUuid();o.isObject(t)||(a.sa.log("\u6d4b\u8bd5\u5f39\u7a97-\u670d\u52a1\u7aef\u6570\u636e\u683c\u5f0f\u4e0d\u5408\u6cd5",t),t={});try{e=JSON.parse(t.content)}catch(i){a.sa.log("\u6d4b\u8bd5\u5f39\u7a97-content\u89e3\u6790\u5931\u8d25,content:",t,i)}var r=a.getPopupInfo(e);r.$sf_msg_id=n;var s={content:t.content,type:t.popup_type||"CUSTOMIZED"};o.isString(t.content)?"withoutCampaignListener"===a.info.supportCustom||"withoutStart"===a.info.supportCustom?(r.$sf_succeed=!1,r.$sf_fail_reason="\u81ea\u5b9a\u4e49\u89e6\u8fbe\u8ba1\u5212\u672a\u5b9e\u73b0\u5f39\u7a97\u751f\u547d\u5468\u671f\u56de\u8c03",a.track.popupDisplay(r),a.info.popup_campaign_listener.onFailed(s,1006,"\u81ea\u5b9a\u4e49\u89e6\u8fbe\u8ba1\u5212\u672a\u5b9e\u73b0\u5f39\u7a97\u751f\u547d\u5468\u671f\u56de\u8c03")):(r.$sf_succeed=!0,a.track.popupDisplay(r),a.info.popup_campaign_listener.onStart(s)):(r.$sf_succeed=!1,r.$sf_fail_reason="\u9884\u89c8\u4fe1\u606f\u89e3\u6790\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u8ba1\u5212\u914d\u7f6e",a.track.popupDisplay(r),a.info.popup_campaign_listener.onFailed(s,1001,"\u9884\u89c8\u4fe1\u606f\u89e3\u6790\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u8ba1\u5212\u914d\u7f6e"))},error:function(t){a.log("\u6d4b\u8bd5\u5f39\u7a97\u83b7\u53d6\u6570\u636e\u9519\u8bef",t)}})}},a.setPara=function(t){o.isObject(t)||(t={}),a.info=o.extend({},a.defaultPara,t);var e=a.sa;return e?(e.para.encrypt_cookie===!0&&(a.info.encrypt_cookie=!0),o.isString(a.info.api_base_url)&&"http"===a.info.api_base_url.slice(0,4)?"http:"===a.info.api_base_url.slice(0,5)&&"https:"===location.protocol?(a.log("\u60a8\u7684\u5f53\u524d\u9875\u9762\u662fhttps\u7684\u5730\u5740\uff0capi_base_url \u4e5f\u5fc5\u987b\u662fhttps\uff01"),!1):(a.info.api_base_url="/"===a.info.api_base_url.slice(-1)?a.info.api_base_url.slice(0,-1):a.info.api_base_url,o.isString(e.para.server_url)&&"http"===e.para.server_url.slice(0,4)?(a.info.project||(a.info.project=o.URL(e.para.server_url).searchParams.get("project")||"default"),a.info.supportCustom=!0,o.isObject(a.info.popup_campaign_listener)?(o.isFunction(a.info.popup_campaign_listener.shouldStart)||(a.info.popup_campaign_listener.shouldStart=function(){return!0}),o.isFunction(a.info.popup_campaign_listener.onStart)||(a.info.supportCustom="withoutStart",a.info.popup_campaign_listener.onStart=function(){}),o.isFunction(a.info.popup_campaign_listener.onEnd)||(a.info.popup_campaign_listener.onEnd=function(){}),o.isFunction(a.info.popup_campaign_listener.onFailed)||(a.info.popup_campaign_listener.onFailed=function(){})):(a.info.supportCustom="withoutCampaignListener",a.info.popup_campaign_listener={shouldStart:function(){return!0},onStart:function(){},onEnd:function(){},onFailed:function(){}}),!0):(a.log("server_url \u5fc5\u987b\u586b\u5199\u6709\u6548\u6570\u636e\u63a5\u6536\u5730\u5740"),!1)):(a.log("popup \u5fc5\u987b\u586b\u5199\u6709\u6548 api_base_url"),!1)):(a.log("web js sdk \u8fd8\u6ca1\u6709\u521d\u59cb\u5316\u5b8c\u6210"),!1)},a.init=function(){var t=window.sensorsDataAnalytic201505;if(a.sa=t,t&&t.readyState&&t.readyState.state>=3||!t.on)i.apply(this,arguments);else{var e=this,n=arguments;t&&t.on("sdkReady",function(){i.apply(e,n)})}},window.SensorsDataWebJSSDKPlugin&&"[object Object]"===Object.prototype.toString.call(window.SensorsDataWebJSSDKPlugin)?window.SensorsDataWebJSSDKPlugin.WebPopup=window.SensorsDataWebJSSDKPlugin.WebPopup||a:window.SensorsDataWebJSSDKPlugin={WebPopup:a},a});