(function(q,v){"object"===typeof exports&&"undefined"!==typeof module?v(exports):"function"===typeof define&&define.amd?define("DCAgent",["exports"],v):v(q.DCAgent={})})(this,function(q){function v(a){return"undefined"!==typeof g[a]}function t(){}function P(a){return"function"===typeof a}function $(a){var b,c;b=Date.now();c="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var c;c=(b+16*Math.random())%16|0;b=Math.floor(b/16);return"x"===a?c.toString(16):(c&7|8).toString(16)});return(a|| "")+c.replace(/-/g,"").toUpperCase()}function Ba(a){var b,c;for(b in a)c=a[b],a[b]=c;(2<=arguments.length?[].slice.call(arguments,1):[]).forEach(function(d){var f;f=[];for(b in d)c=d[b],f.push(a[b]=c);return f});return a}function p(a,b,c){if(P(a))try{return a.apply(b,c)}catch(d){h("attemp error for "+a.toString(),d.stack)}}function Ca(a,b,c){function d(){!1!==p(a)&&F(d,b)}c?d():F(d,b)}function h(a,b){console.log("#DCAgent: "+a);b&&console.log(b)}function Da(a){try{return a.setItem(".","."),a.removeItem("."), !0}catch(b){return!1}}function Ea(a){return a?(a=a.match(/^(https?\:)\/\/(([^:\/?#]*)(?:\:([0-9]+))?)(\/[^?#]*)(\?[^#]*|)(#.*|)$/))&&a[3]:""}function z(a,b){a=m(a);n.setItem(a,b);aa.set(a,b,365);return b}function G(a){a=m(a);return n.getItem(a)||aa.get(a)}function m(a){if(Q||R===a)return a;e.appId||h("appid should not be empty when you are in native env");return e.appId+"."+a}function Fa(a){var b=s.hash,c="!"+a;if(b){var d=/![0-9A-Z]{32,128}/gi;(b=b.match(d))?(b=b[0].slice(1),a===b||G(ba)||(e.parentId= b,z(ba,b)),a=s.href.replace(d,c),s.replace(a)):s.replace(s.href+c)}else s.replace(s.href+"#"+c)}function ca(a){a=m(a);try{var b=JSON.parse(n.getItem(a));return Array.isArray(b)?b:[]}catch(c){return n.removeItem(a),[]}}function Ga(a,b){b=m(b);var c=ca(b);Array.isArray(a)?a.forEach(function(a){return c.push(a)}):c.push(a);n.setItem(b,JSON.stringify(c))}function Ha(){n.removeItem(m(w));n.removeItem(m(B))}function Ia(){g.addEventListener&&g.addEventListener("error",function(a){p(function(){if(u.isReportAllowed(a.filename)){u.count+= 1;var b={};["colno","filename","lineno","message"].forEach(function(c){return b[c]=a[c]||"1"});var c=a.error||{};b.stack=encodeURIComponent(c.stack||c.stacktrace||"");b.type=c.name||"Error";b.timestamp=parseInt(a.timeStamp/1E3);if(P(e.getErrorScene)&&(c=p(e.getErrorScene,c,[a]))){if(c&&"[object Object]"===da.call(c)){var d="",f;for(f in c)d+="\t"+f+"="+c[f]+"\n";c=d}else c=String(c);b.stack+="\n\nError scene:\n"+encodeURIComponent(c)}x.updateStorageByKey(b,B)}})},!1)}function Ja(){if(H)return H;S+= 1;if(!(4a?I:Math.min(a,I)}function fa(a){var b= ga();b.timeout=I;b.open("POST",a.url,!0);b.setRequestHeader("Content-Type","text/plain; charset=UTF-8");var c=Date.now();b.onreadystatechange=function(){if(4===this.readyState){var b="success"===this.responseText,f=U(Date.now()-c);p(b?a.success:a.error,this,[this,f]);p(a.complete,this,[this,f]);this.ontimeout=this.onreadystatechange=null}};b.ontimeout=function(){var b=U(Date.now()-c);p(a.error,this,[this,b,!0]);p(a.complete,this,[this,b]);this.ontimeout=this.onreadystatechange=null};b.send(JSON.stringify(a.data))} function La(a){var b=new egret.URLLoader,c=Date.now();b.addEventListener(egret.Event.COMPLETE,function(b){var d=U(Date.now()-c);b=b.target;p("success"===b.data?a.success:a.error,b,[b,d,d>=I]);p(a.complete,b,[b,d])});var d=new egret.URLRequest(a.url);d.method=egret.URLRequestMethod.POST;d.data=JSON.stringify(a.data);b.load(d)}function ha(a,b){if(a.data){a.data.errors&&a.data.errors.length>u.max&&(e.debug&&h("sending too many errors, only "+u.max+" allowed"),a.data.errors=a.data.errors.slice(0,u.max)); for(var c in a.data)"number"===typeof a.data[c]&&(a.data[c]=String(a.data[c]));c=Math.abs(e.onlinetime);c>Ma||0>=c?e.debug&&h("illegal online time: "+c):(c=Ba({headers:Ka()},a.data),Na({url:b,data:c,success:function(b,c){r.succ=1;r.fail=0;r.total=c;p(a.success,b,[b,c])},error:function(b,c,g){r.succ=0;r.fail+=1;r.total+=c;p(a.error,b,[b,c,g]);g&&e.debug&&h("report timeout, network infomation",r)},complete:function(b,c){x.updateStorageByKey({eventid:Oa,labelmap:JSON.stringify(r),duration:"1"},w);p(a.complete, b,[b,c])}}),e.debug&&h("report data:",c))}}function ia(a,b,c,d){var f={data:{online:{},events:a||[],errors:b||[]},success:d};c&&(f.data.reg=c);a=x.getStorageByKey(w);b=x.getStorageByKey(B);if(a.length||b.length)x.clear(),f.data.events=f.data.events.concat(a),f.data.errors=f.data.errors.concat(b),f.error=function(){e.debug&&h("report failed, restoring data to localStorage");x.updateStorageByKey(f.data.events,w);x.updateStorageByKey(f.data.errors,B)};ha(f,ja)}function ka(a,b,c){a={page:encodeURIComponent(a|| Pa),optime:parseInt(e.initializedOn),ottime:parseInt(Date.now()/1E3),lttime:parseInt(e.loginTime/1E3)};ia([{eventid:"_DESelf_PV",labelmap:JSON.stringify(a),duration:"1"}],null,b,c)}function Qa(){p(function(){if(g[J])g[J]=null;else if("function"===typeof define&&define.amd)require.undef(J);else if("object"===typeof q&&"undefined"!==typeof module){var a=require.resolve(J);delete require.cache[a]}else h("unknown module system, unload DCAgent manually please");h("DCAgent has been destroyed.")})}function Ra(){if(la)return Qa(), !1;ma&&l[ma]||(e.intervalCount+=1,D.setItem(m(V),e.intervalCount),ia());return!0}function W(a,b){if(!y.isAgentReady()){var c=[a];[].forEach.call(b,function(a){return c.push(a)});K.push(c);return!0}}function na(a){a=m(a);try{var b=JSON.parse(n.getItem(a));return Array.isArray(b)?b:[]}catch(c){return n.removeItem(a),[]}}function Sa(a,b){b=m(b);var c=na(b);Array.isArray(a)?a.forEach(function(a){return c.push(a)}):c.push(a);n.setItem(b,JSON.stringify(c))}function Ta(){n.removeItem(m(w));n.removeItem(m(B))} function oa(a,b,c){if(!a)h("invoke failed, missing eventId");else if(!W("onEvent",arguments)){if(null==b||1>b)b=1;var d;if(c&&"[object Object]"===da.call(c)){for(d in c)c[d.replace("%","_")]=encodeURIComponent(c[d]);d=JSON.stringify(c)}else d="";pa.updateStorageByKey({eventid:a,duration:String(b),labelmap:d},w)}}function qa(a){W("onPageView",arguments)||ka(a)}function ra(a){a&&a.hasOwnProperty("amount")&&!W("onPayment",arguments)&&(a.amount=parseFloat(a.amount)||0,ha({data:{payment:{currencyAmount:a.amount.toFixed(2), currencyType:a.currencyType||"CNY",payType:String(a.payType||""),iapid:String(a.iapid||""),orderId:String(a.orderId||""),payTime:String(a.payTime||"")}}},ja))}function sa(a,b,c,d){b&&z(R,a);e.deviceId=a;e.accountId=e.accountId||a;var f=D.getItem(m(ta));f||(f=Date.now(),D.setItem(m(ta),f));e.loginTime=f;f=D.getItem(m(V));f||(f="0",D.setItem(m(V),f));e.intervalCount=parseInt(f);e.interval=1E3*Math.max(10,parseFloat(c.interval||e.interval));e.virus&&Ua(a);e.errorReport&&(c.excludes&&(u.excludes=u.excludes.concat(c.excludes)), Ia());c=null;b&&(c={isact:b,isreg:1},e.parentId&&(c.parentid=e.parentId),k.localStorage||(c.localstorage=1));e.initializedOn=Date.now()/1E3;G(A)||z(A,e.initializedOn);ka(null,c);y.setReadyState(3);b={onEvent:oa,onPageView:qa,onPayment:ra};c=0;for(f=K.length;cc.length){for(var b=c,c=Math.ceil(32-c.length)/2,c=void 0===c?0:c,d="",f=0;f