Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
var Config={LIB_VERSION:"1.0.0",PAGE_SHOW:"page_show",PAGE_VIEW:"page_view",PAGE_HIDE:"page_hide",PAGE_CLOSE:"page_close",STORE_PREFIX:"tapdbweb_",TAB_STORE_PREFIX:"tapdbweb_tab_",CONFIG_NAME:"tapdb",MAX_REFERRER_STRING_LENGTH:200,SERVER_URL_PATH:"/event",SERVER_MULTI_PATH:"/batch",SERVER_DEBUG_PATH:"/data_debug"},ArrayProto=Array.prototype,ObjProto=Object.prototype,slice=ArrayProto.slice,toString=ObjProto.toString,hasOwnProperty=ObjProto.hasOwnProperty,nativeForEach=ArrayProto.forEach,breaker={},utmTypes=["utm_source","utm_medium","utm_campaign","utm_content","utm_term"],_={each:function(e,t,r){if(null!==e)if(nativeForEach&&e.forEach===nativeForEach)e.forEach(t,r);else if(e.length===+e.length){for(var i=0,n=e.length;i<n;i++)if(i in e&&t.call(r,e[i],i,e)===breaker)return}else for(var s in e)if(hasOwnProperty.call(e,s)&&t.call(r,e[s],s,e)===breaker)return},extend:function(r){return _.each(slice.call(arguments,1),function(e){for(var t in e)void 0!==e[t]&&(r[t]=e[t])}),r},formatDate:function(e){function t(e){return e<10?"0"+e:e}return e.getFullYear()+"-"+t(e.getMonth()+1)+"-"+t(e.getDate())+" "+t(e.getHours())+":"+t(e.getMinutes())+":"+t(e.getSeconds())+"."+((e=e.getMilliseconds())<10?"00"+e:e<100?"0"+e:e)},formatTimeZone:function(e,t){var r;return"number"!=typeof t?e:(r=e.getTime(),e=6e4*e.getTimezoneOffset(),new Date(r+e+36e5*t))},formatJsonString:function(t){try{return JSON.stringify(t,null,8)}catch(e){return JSON.stringify(t)}},searchObjDate:function(r,i){(_.check.isObject(r)||_.check.isArray(r))&&_.each(r,function(e,t){_.check.isObject(e)||_.check.isArray(e)?_.searchObjDate(r[t],i):_.check.isDate(e)&&(r[t]=_.formatDate(_.formatTimeZone(e,i)))})},check:{isUndefined:function(e){return void 0===e},isObject:function(e){return"[object Object]"===toString.call(e)&&null!==e},isEmptyObject:function(e){if(_.check.isObject(e)){for(var t in e)if(hasOwnProperty.call(e,t))return!1;return!0}return!1},isArray:function(e){return"[object Array]"===toString.call(e)},isString:function(e){return"[object String]"===toString.call(e)},isDate:function(e){return"[object Date]"===toString.call(e)},isNumber:function(e){return"[object Number]"===toString.call(e)},isBoolean:function(e){return"[object Boolean]"===toString.call(e)},isJSONString:function(e){try{JSON.parse(e)}catch(e){return!1}return!0}}};_.UUID=function(){function t(){for(var e=+new Date,t=0;e===+new Date;)t++;return e.toString(16)+t.toString(16)}return function(){var e=(e=String(screen.height*screen.width))&&/\d{5,}/.test(e)?e.toString(16):String(31242*Math.random()).replace(".","").slice(0,8),e=t()+"-"+Math.random().toString(16).replace(".","")+"-"+function(){var e,t,r=navigator.userAgent,n=[],i=0;function s(e,t){for(var r=0,i=0;i<t.length;i++)r|=n[i]<<8*i;return e^r}for(e=0;e<r.length;e++)t=r.charCodeAt(e),n.unshift(255&t),4<=n.length&&(i=s(i,n),n=[]);return(i=0<n.length?s(i,n):i).toString(16)}()+"-"+e+"-"+t();return e||(String(Math.random())+String(Math.random())+String(Math.random())).slice(2,15)}}(),_.UUIDv4=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)})},_.getReferrer=function(e){e=e||document.referrer;return"string"!=typeof e?"取值异常_referrer异常_"+String(e):"string"==typeof(e=(e=0===e.indexOf("https://www.baidu.com/")?e.split("?")[0]:e).slice(0,Config.MAX_REFERRER_STRING_LENGTH))?e:""},_.url=function(){function n(){return new RegExp(/(.*?)\.?([^\.]*?)\.(com|net|org|biz|ws|in|me|co\.uk|co|org\.uk|ltd\.uk|plc\.uk|me\.uk|edu|mil|br\.com|cn\.com|eu\.com|hu\.com|no\.com|qc\.com|sa\.com|se\.com|se\.net|us\.com|uy\.com|ac|co\.ac|gv\.ac|or\.ac|ac\.ac|af|am|as|at|ac\.at|co\.at|gv\.at|or\.at|asn\.au|com\.au|edu\.au|org\.au|net\.au|id\.au|be|ac\.be|adm\.br|adv\.br|am\.br|arq\.br|art\.br|bio\.br|cng\.br|cnt\.br|com\.br|ecn\.br|eng\.br|esp\.br|etc\.br|eti\.br|fm\.br|fot\.br|fst\.br|g12\.br|gov\.br|ind\.br|inf\.br|jor\.br|lel\.br|med\.br|mil\.br|net\.br|nom\.br|ntr\.br|odo\.br|org\.br|ppg\.br|pro\.br|psc\.br|psi\.br|rec\.br|slg\.br|tmp\.br|tur\.br|tv\.br|vet\.br|zlg\.br|br|ab\.ca|bc\.ca|mb\.ca|nb\.ca|nf\.ca|ns\.ca|nt\.ca|on\.ca|pe\.ca|qc\.ca|sk\.ca|yk\.ca|ca|cc|ac\.cn|net\.cn|com\.cn|edu\.cn|gov\.cn|org\.cn|bj\.cn|sh\.cn|tj\.cn|cq\.cn|he\.cn|nm\.cn|ln\.cn|jl\.cn|hl\.cn|js\.cn|zj\.cn|ah\.cn|gd\.cn|gx\.cn|hi\.cn|sc\.cn|gz\.cn|yn\.cn|xz\.cn|sn\.cn|gs\.cn|qh\.cn|nx\.cn|xj\.cn|tw\.cn|hk\.cn|mo\.cn|cn|cx|cz|de|dk|fo|com\.ec|tm\.fr|com\.fr|asso\.fr|presse\.fr|fr|gf|gs|co\.il|net\.il|ac\.il|k12\.il|gov\.il|muni\.il|ac\.in|co\.in|org\.in|ernet\.in|gov\.in|net\.in|res\.in|is|it|ac\.jp|co\.jp|go\.jp|or\.jp|ne\.jp|ac\.kr|co\.kr|go\.kr|ne\.kr|nm\.kr|or\.kr|li|lt|lu|asso\.mc|tm\.mc|com\.mm|org\.mm|net\.mm|edu\.mm|gov\.mm|ms|nl|no|nu|pl|ro|org\.ro|store\.ro|tm\.ro|firm\.ro|www\.ro|arts\.ro|rec\.ro|info\.ro|nom\.ro|nt\.ro|se|si|com\.sg|org\.sg|net\.sg|gov\.sg|sk|st|tf|ac\.th|co\.th|go\.th|mi\.th|net\.th|or\.th|tm|to|com\.tr|edu\.tr|gov\.tr|k12\.tr|net\.tr|org\.tr|com\.tw|org\.tw|net\.tw|ac\.uk|uk\.com|uk\.net|gb\.com|gb\.net|vg|sh|kz|ch|info|ua|gov|name|pro|ie|hk|com\.hk|org\.hk|net\.hk|edu\.hk|us|tk|cd|by|ad|lv|eu\.lv|bz|es|jp|cl|ag|mobi|eu|co\.nz|org\.nz|net\.nz|maori\.nz|iwi\.nz|io|la|md|sc|sg|vc|tw|travel|my|se|tv|pt|com\.pt|edu\.pt|asia|fi|com\.ve|net\.ve|fi|org\.ve|web\.ve|info\.ve|co\.ve|tel|im|gr|ru|net\.ru|org\.ru|hr|com\.hr|ly|xyz)$/)}function s(e,t){var r=e.charAt(0),t=t.split(r);return r===e?t:t[(e=parseInt(e.substring(1),10))<0?t.length+e:e-1]}function o(e,t){for(var r,i=e.charAt(0),n=t.split("&"),s=[],o={},a=e.substring(1),c=0,p=n.length;c<p;c++)if(""!==(s=(s=n[c].match(/(.*?)=(.*)/))||[n[c],n[c],""])[1].replace(/\s/g,"")){if(s[2]=(r=s[2]||"",_.decodeURIComponent(r.replace(/\+/g," "))),a===s[1])return s[2];(r=s[1].match(/(.*)\[([0-9]+)\]/))?(o[r[1]]=o[r[1]]||[],o[r[1]][r[2]]=s[2]):o[s[1]]=s[2]}return i===e?o:o[a]}return function(e,t){var r,i={};if("tld?"===e)return n();if(t=t||window.location.toString(),!e)return t;if(e=e.toString(),r=t.match(/^mailto:([^\/].+)/))i.protocol="mailto",i.email=r[1];else{if((r=(t=(r=t.match(/(.*?)\/#\!(.*)/))?r[1]+r[2]:t).match(/(.*?)#(.*)/))&&(i.hash=r[2],t=r[1]),i.hash&&e.match(/^#/))return o(e,i.hash);if((r=t.match(/(.*?)\?(.*)/))&&(i.query=r[2],t=r[1]),i.query&&e.match(/^\?/))return o(e,i.query);if((r=t.match(/(.*?)\:?\/\/(.*)/))&&(i.protocol=r[1].toLowerCase(),t=r[2]),(r=t.match(/(.*?)(\/.*)/))&&(i.path=r[2],t=r[1]),i.path=(i.path||"").replace(/^([^\/])/,"/$1").replace(/\/$/,""),(e=e.match(/^[\-0-9]+$/)?e.replace(/^([^\/])/,"/$1"):e).match(/^\//))return s(e,i.path.substring(1));if((r=(r=s("/-1",i.path.substring(1)))&&r.match(/(.*?)\.(.*)/))&&(i.file=r[0],i.filename=r[1],i.fileext=r[2]),(r=t.match(/(.*)\:([0-9]+)$/))&&(i.port=r[2],t=r[1]),(r=t.match(/(.*?)@(.*)/))&&(i.auth=r[1],t=r[2]),i.auth&&(r=i.auth.match(/(.*)\:(.*)/),i.user=r?r[1]:i.auth,i.pass=r?r[2]:void 0),i.hostname=t.toLowerCase(),"."===e.charAt(0))return s(e,i.hostname);n()&&(r=i.hostname.match(n()))&&(i.tld=r[3],i.domain=r[2]?r[2]+"."+r[3]:void 0,i.sub=r[1]||void 0);t=i.port?":"+i.port:"";i.protocol=i.protocol||window.location.protocol.replace(":",""),i.port=i.port||("https"===i.protocol?"443":"80"),i.protocol=i.protocol||("443"===i.port?"https":"http"),i.basic=i.protocol+"://"+i.hostname+t}return e in i?i[e]:"{}"===e?i:""}}(),_.hashCode=function(e){if("string"!=typeof e)return 0;var t=0;if(0!==e.length)for(var r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return t},_.decodeURIComponent=function(t){var r="";try{r=decodeURIComponent(t)}catch(e){r=t}return r},_.encodeURIComponent=function(t){var r="";try{r=encodeURIComponent(t)}catch(e){r=t}return r},_.utf8Encode=function(e){for(var t,r="",i=t=0,n=(e=(e+"").replace(/\r\n/g,"\n").replace(/\r/g,"\n")).length,s=0;s<n;s++){var o=e.charCodeAt(s),a=null;o<128?t++:a=127<o&&o<2048?String.fromCharCode(o>>6|192,63&o|128):String.fromCharCode(o>>12|224,o>>6&63|128,63&o|128),null!==a&&(i<t&&(r+=e.substring(i,t)),r+=a,i=t=s+1)}return i<t&&(r+=e.substring(i,e.length)),r},_.base64Encode=function(e){var t,r,i,n,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=0,a=0,c="",p=[];if(!e)return e;for(e=_.utf8Encode(e);t=(n=e.charCodeAt(o++)<<16|e.charCodeAt(o++)<<8|e.charCodeAt(o++))>>12&63,r=n>>6&63,i=63&n,p[a++]=s.charAt(n>>18&63)+s.charAt(t)+s.charAt(r)+s.charAt(i),o<e.length;);switch(c=p.join(""),e.length%3){case 1:c=c.slice(0,-2)+"==";break;case 2:c=c.slice(0,-1)+"="}return c},_.cookie={get:function(e){for(var t=e+"=",r=document.cookie.split(";"),i=0;i<r.length;i++){for(var n=r[i];" "===n.charAt(0);)n=n.substring(1,n.length);if(0===n.indexOf(t))return _.decodeURIComponent(n.substring(t.length,n.length))}return null},set:function(e,t,r,i,n){var s="",o="",a="",r=(r=null===r?73e3:r,i&&(s=(i=_.url("domain",location.href))?"; domain=."+i:""),r&&(i=new Date,"s"===String(r).slice(-1)?i.setTime(i.getTime()+1e3*Number(String(r).slice(0,-1))):i.setTime(i.getTime()+24*r*60*60*1e3),o="; expires="+i.toGMTString()),n&&(a="; secure"),e+"="+encodeURIComponent(t)+o+"; path=/"+s+a);return document.cookie=r},remove:function(e,t){_.cookie.set(e,"",-1,t)}},_.localStorage={get:function(e){try{return window.localStorage.getItem(e)}catch(e){_.localStorage.error(e)}},parse:function(e){var t;try{t=JSON.parse(_.localStorage.get(e))||null}catch(e){_.localStorage.error(e)}return t},set:function(e,t){try{window.localStorage.setItem(e,t)}catch(e){_.localStorage.error(e)}},remove:function(e){try{window.localStorage.removeItem(e)}catch(e){_.localStorage.error(e)}},error:function(e){console.error("localStorage error: "+e)},isSupported:function(){var t=!0;try{var e="__tapdbsupport__",r="testIsSupportStorage";_.localStorage.set(e,r),_.localStorage.get(e)!==r&&(t=!1),_.localStorage.remove(e)}catch(e){t=!1}return t}},_.stripEmptyProperties=function(e){var r={};return _.each(e,function(e,t){_.check.isString(e)&&0<e.length&&(r[t]=e)}),r},_.info={os:function(){var e=navigator.userAgent;return/Windows/i.test(e)?/Phone/.test(e)||/WPDesktop/.test(e)?"Windows Phone":"Windows":/(iPhone|iPad|iPod)/.test(e)?"iOS":/Android/.test(e)?"Android":/(BlackBerry|PlayBook|BB10)/i.test(e)?"BlackBerry":/Mac/i.test(e)?"Mac OS X":/Linux/.test(e)?"Linux":/CrOS/.test(e)?"Chrome OS":""},browser:function(){var e={type:"",version:""};try{var t,r,i=navigator.userAgent.toLowerCase(),n=[];null!==i.match(/baidubrowser/)?(e.type="baidu",n.push(/baidubrowser\/([\d.]+)/)):null!==i.match(/bidubrowser/)?(e.type="baidu",n.push(/bidubrowser\/([\d.]+)/)):null!==i.match(/edga/)?(e.type="edge",n.push(/edga\/([\d.]+)/)):null!==i.match(/edgios/)?(e.type="edge",n.push(/edgios\/([\d.]+)/)):null!==i.match(/liebaofast/)?(e.type="liebao",n.push(/liebaofast\/([\d.]+)/)):null!==i.match(/sogoumobilebrowser/)?(e.type="sogou",n.push(/sogoumobilebrowser\/([\d.]+)/)):null!==i.match(/lbbrowser/)?(e.type="liebao",n.push(/lbbrowser\/([\d.]+)/)):null!==i.match(/crios/)?(e.type="chrome",n.push(/crios\/([\d.]+)/)):null!==i.match(/qihoobrowser/)?(e.type="360",n.push(/qihoobrowser\/([\d.]+)/)):null!==i.match(/mxios/)?(e.type="maxthon",n.push(/mxios\/([\d.]+)/)):null!==i.match(/fxios/)?(e.type="firefox",n.push(/fxios\/([\d.\w]+)/)):null!==i.match(/edge/)?(e.type="edge",n.push(/edge\/([\d.]+)/)):null!==i.match(/metasr/)?(e.type="sogou",n.push(/metasr ([\d.]+)/)):null!==i.match(/micromessenger/)?(e.type="micromessenger",n.push(/micromessenger\/([\d.]+)/)):null!==i.match(/mqqbrowser/)?(e.type="qq",n.push(/mqqbrowser\/([\d.]+)/)):null!==i.match(/qqbrowserlite/)?(e.type="qq",n.push(/qqbrowserlite\/([\d.]+)/)):null!==i.match(/tencenttraveler/)?(e.type="qq",n.push(/tencenttraveler\/([\d.]+)/)):null!==i.match(/qqbrowser/)?(e.type="qq",n.push(/qqbrowser\/([\d.]+)/)):null!==i.match(/maxthon/)?(e.type="maxthon",n.push(/maxthon\/([\d.]+)/)):null!==i.match(/ubrowser/)?(e.type="uc",n.push(/ubrowser\/([\d.]+)/)):null!==i.match(/ucbrowser/)?(e.type="uc",n.push(/ucbrowser\/([\d.]+)/)):null!==i.match(/firefox/)?(e.type="firefox",n.push(/firefox\/([\d.]+)/)):null!==i.match(/opera/)?(e.type="opera",n.push(/opera\/([\d.]+)/)):null!==i.match(/opr/)?(e.type="opera",n.push(/opr\/([\d.]+)/)):null!==i.match(/chrome/)?(e.type="chrome",n.push(/chrome\/([\d.]+)/)):null!==i.match(/safari/)?(e.type="safari",n.push(/version\/([\d.]+)/)):null===i.match(/trident/)&&null===i.match(/msie/)||(e.type="ie"),"ie"===e.type?(t=i.match(/trident\/([\d.]+)/)?i.match(/trident\/([\d.]+)/)[1]:"",r=i.match(/msie ([\d.]+)/)?i.match(/msie ([\d.]+)/)[1]:"",""!==t?e.version=String(parseInt(t)+4):""!==r&&(e.version=r)):n&&(e.version=i.match(n[0])?i.match(n[0])[1]:"")}catch(e){Log.w("getting browser info failed due to ",e)}return e},properties:function(){var e=_.info.browser();return _.extend({"#os":_.info.os(),"#sdk_version":Config.LIB_VERSION,"#sdk_platform":"js","#screen_height":screen.height,"#screen_width":screen.width,"#browser":e.type,"#browser_version":e.version,"#system_language":_.check.isString(navigator.languages[1])?navigator.languages[1].toLowerCase():"取值异常","#ua":_.check.isString(navigator.userAgent)?navigator.userAgent.toLowerCase():"取值异常","#utm":_.getUtm()})},pageProperties:function(){var e=_.getReferrer();return _.stripEmptyProperties({"#referrer":e,"#referrer_host":e&&_.url("hostname",e),"#url":location.href,"#url_path":location.pathname,"#title":document.title})}},_.getUtm=function(){var r={};return _.each(utmTypes,function(e){var t=_.getQueryParam(location.href,e);t.length&&(r[e]=t)}),JSON.stringify(r)},_.getQueryParam=function(e,t){t=t.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]"),e=_.decodeURIComponent(e);t=new RegExp("[\\?&]"+t+"=([^&#]*)").exec(e);return null===t||t&&"string"!=typeof t[1]&&t[1].length?"":_.decodeURIComponent(t[1])},_.createString=function(e){for(var t=e,r=Math.random().toString(36).substr(2);r.length<t;)r+=Math.random().toString(36).substr(2);return r=r.substr(0,e)},_.createAesKey=function(){return _.createString(16)},_.generateEncryptyData=function(e,t){if(void 0!==t){var r=t.publicKey,t=t.version;if(void 0!==r&&void 0!==t&&"undefined"!=typeof CryptoJS&&"undefined"!=typeof JSEncrypt){var i=_.createAesKey();try{var n=CryptoJS.enc.Utf8.parse(i),s=CryptoJS.enc.Utf8.parse(JSON.stringify(e)),o=CryptoJS.AES.encrypt(s,n,{mode:CryptoJS.mode.ECB,padding:CryptoJS.pad.Pkcs7}).toString(),a=new JSEncrypt,c=(a.setPublicKey(r),a.encrypt(i));return!1===c?(Log.w("加密失败,返回原数据"),e):{pkv:t,ekey:c,payload:o}}catch(e){Log.w("加密失败,返回原数据")}}}return e},_.paramType=function(e){return Object.prototype.toString.call(e).replace("[object ","").replace("]","")},_.addEvent=function(e,t,r,i){if(document.addEventListener)if("Array"!==this.paramType(e)&&"HTMLCollection"!==this.paramType(e)||!e.length||e===window)e.addEventListener(t,r,i);else for(var n=0;n<e.length;n++)this.addEvent(e[n],t,r,i);else if(e.length&&e!==window)for(var s=0;s<e.length;s++)this.addEvent(e[s],t,r);else e.attachEvent("on"+t,function(){return r.call(e,window.event)})},_.getRandom=function(){return(new Date).getTime()+"_"+Math.floor(1e6*Math.random())},_.safeJSONParse=function(t){var e=null;try{e=JSON.parse(t)}catch(e){return t}return e},_.saveObjectVal=function(e,t){_.check.isString(t)||(t=JSON.stringify(t)),_.localStorage.set(e,t)},_.readObjectVal=function(e){e=_.localStorage.get(e);return e?_.safeJSONParse(e):null},_.indexOf=function(e,t){var r=e.indexOf;if(r)return r.call(e,t);for(var i=0;i<e.length;i++)if(t===e[i])return i;return-1},_.hasEncrypty=function(e){return!!_.check.isObject()&&"undefined"!==e.pkv&&"undefined"!==e.ekey&&"undefined"!==e.payload},_.addSiteEvent=function(e,t,r,p){function h(e){return e&&(e.preventDefault=h.preventDefault,e.stopPropagation=h.stopPropagation,e._getPath=h._getPath),e}h._getPath=function(){var e;return this.path||this.composedPath&&this.composedPath()||(e=this.target,new i(e).getParents())};var i=function(e){this.ele=e};h.preventDefault=function(){this.returnValue=!1},h.stopPropagation=function(){this.cancelBubble=!0};!function(e,t,r){var i,n,s,o,a,c;void 0===p&&"click"===t&&(p=!0),e&&e.addEventListener?e.addEventListener(t,function(e){e._getPath=h._getPath,r.call(this,e)},p):(n=e[i="on"+t],e[i]=(s=e,o=r,a=n,c=t,function(e){var t,r;if(e=e||h(window.event))return e.target=e.srcElement,t=!0,"function"==typeof a&&(r=a(e)),e=o.call(s,e),"beforeunload"!==c?!1!==r&&!1!==e&&t:void 0}))}.apply(null,arguments)},_.getURLSearchParams=function(e){for(var t={},r=(e=e||"").substring(1).split("&"),i=0;i<r.length;i++){var n,s=r[i].indexOf("=");-1!==s&&(n=r[i].substring(0,s),s=r[i].substring(s+1),n=_.decodeURIComponent(n),s=_.decodeURIComponent(s),t[n]=s)}return t},_.urlParse=function(e){function t(e){this._fields={Username:4,Password:5,Port:7,Protocol:2,Host:6,Path:8,URL:0,QueryString:9,Fragment:10},this._values={},this._regex=/^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/,void 0!==e&&this._parse(e)}return t.prototype.setUrl=function(e){this._parse(e)},t.prototype._initValues=function(){for(var e in this._fields)this._values[e]=""},t.prototype.addQueryString=function(e){if("object"!=typeof e)return!1;var t,r=this._values.QueryString||"";for(t in e)r=new RegExp(t+"[^&]+").test(r)?r.replace(new RegExp(t+"[^&]+"),t+"="+e[t]):"&"===r.slice(-1)?r+t+"="+e[t]:""===r?t+"="+e[t]:r+"&"+t+"="+e[t];this._values.QueryString=r},t.prototype.getUrl=function(){var e="";return(e+=this._values.Origin)+(this._values.Port?":"+this._values.Port:"")+this._values.Path+(this._values.QueryString?"?"+this._values.QueryString:"")+(this._values.Fragment?"#"+this._values.Fragment:"")},t.prototype._parse=function(e){this._initValues();this._regex.exec(e)||Log.i("URLParser::_parse -> Invalid URL");var t,e=e.split("#"),r=e[0],e=e.slice(1).join("#"),i=this._regex.exec(r);for(t in this._fields)void 0!==i[this._fields[t]]&&(this._values[t]=i[this._fields[t]]);this._values.Hostname=this._values.Host.replace(/:\d+$/,""),this._values.Origin=this._values.Protocol+"://"+this._values.Hostname,this._values.Fragment=e},new t(e)},_.trim=function(e){return e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")},_.URL=function(e){var t,r,i={};if("function"==typeof window.URL&&function(){try{return"http://modernizr.com/"===new URL("http://modernizr.com/").href}catch(e){return!1}}())(i=new URL(e)).searchParams||(i.searchParams=(r=_.getURLSearchParams(i.search),{get:function(e){return r[e]}}));else{_.check.isString(e)||(e=String(e)),e=_.trim(e);if(!1===/^https?:\/\/.+/.test(e))return void Log.w("Invalid URL");e=_.urlParse(e);i.hash=e._values.Fragment,i.host=e._values.Host?e._values.Host+(e._values.Port?":"+e._values.Port:""):"",i.href=e._values.URL,i.password=e._values.Password,i.pathname=e._values.Path,i.port=e._values.Port,i.search=e._values.QueryString?"?"+e._values.QueryString:"",i.username=e._values.Username,i.hostname=e._values.Hostname,i.protocol=e._values.Protocol?e._values.Protocol+":":"",i.origin=e._values.Origin?e._values.Origin+(e._values.Port?":"+e._values.Port:""):"",i.searchParams=(t=_.getURLSearchParams("?"+e._values.QueryString),{get:function(e){return t[e]}})}return i};class Log{static i(){if(!this.showLog)return!1;if(!0!==this.showLog&&"string"!==this.showLog||(arguments[0]=_.formatJsonString(arguments[0])),"object"==typeof console&&console.log)try{return console.log.apply(console,arguments)}catch(e){console.log(arguments[0])}}static w(){if(!this.showLog)return!1;if(!0!==this.showLog&&"string"!==this.showLog||(arguments[0]=_.formatJsonString(arguments[0])),"object"==typeof console&&console.warn)try{return console.warn.apply(console,arguments)}catch(e){console.warn(arguments[0])}}static e(){if(!this.showLog)return!1;if(!0!==this.showLog&&"string"!==this.showLog||(arguments[0]=_.formatJsonString(arguments[0])),"object"==typeof console&&console.error)try{return console.error.apply(console,arguments)}catch(e){console.error(arguments[0])}}}var KEY_NAME_MATCH_REGEX=/^[a-zA-Z#][a-zA-Z0-9_]{0,49}$/;class PropertyChecker{static stripProperties(e){return _.check.isObject(e)&&_.each(e,function(e,t){_.check.isString(e)||_.check.isNumber(e)||_.check.isDate(e)||_.check.isBoolean(e)||_.check.isArray(e)||_.check.isObject(e)||Log.w("您的数据-",t,e,"-格式不满足要求,可能无法正确入库. 属性值只支持 String, Number, Date, Boolean, Array,Object")}),e}static _checkPropertiesKey(e){var r=!0;return _.each(e,(e,t)=>{KEY_NAME_MATCH_REGEX.test(t)||(Log.w("不合法的 KEY 值: "+t),r=!1)}),r}static event(e){return!(!_.check.isString(e)||!KEY_NAME_MATCH_REGEX.test(e))||(Log.w("请检查参数格式, eventName 必须是英文字母或者 '_' 开头, 包含字母和数字的不超过50个字符的字符串: "+e),!1)}static propertyName(e){return!(!_.check.isString(e)||!KEY_NAME_MATCH_REGEX.test(e))||(Log.w("请检查参数格式, propertyName 必须是英文字母或者 '_' 开头, 包含字母和数字的不超过50个字符的字符串: "+e),!1)}static properties(e){return this.stripProperties(e),!(e&&(_.check.isObject(e)?!this._checkPropertiesKey(e)&&(Log.w("请检查参数格式, properties 的 key 只能以字母开头,包含数字、字母和下划线 _,长度最大为50个字符"),1):(Log.w("properties 可以没有,但有的话必须是对象"),1)))}static propertiesMust(e){return this.stripProperties(e),void 0===e||!_.check.isObject(e)||_.check.isEmptyObject(e)?(Log.w("properties必须是对象且有值"),!1):!!this._checkPropertiesKey(e)||(Log.w("请检查参数格式, properties 的 key 只能以字母开头,包含数字、字母和下划线 _,长度最大为50个字符"),!1)}static userId(e){return!(!_.check.isString(e)||!/^.{1,63}$/.test(e))||(Log.w("用户 id 必须是不能为空,且小于 64 位的字符串"),!1)}}var MASTER_INSTANCE_NAME=Config.CONFIG_NAME,DEFAULT_CONFIG={_name:MASTER_INSTANCE_NAME,appId:"",send_method:"ajax",persistence:"localStorage",persistencePrefix:Config.STORE_PREFIX,persistenceEnabled:!0,crossSubDomain:!0,maxReferrerStringLength:200,showLog:!1,dataSendTimeout:3e3,useAppTrack:!1,strict:!1,tryCount:3,inDBOrDC:"db",headers:{},textContent:"form",isUseCRC:!1,isUseSLS:!1,isInitDeviceLogin:!1},TapDBPersistence=function(e){this._state={},this.crossSubDomain=e.crossSubDomain,this.enabled=e.persistenceEnabled;var t,r=null;this.enabled&&(!1===e.crossSubDomain?(t=_.url("sub",location.href),this.name="string"==typeof t&&""!==t?e.persistencePrefix+t:e.persistencePrefix+"root"):this.name=e.persistencePrefix+"cross","cookie"!==(t=e.persistence)&&"localStorage"!==t&&(Log.i("Unknown persistence type "+t+"; falling back to cookie"),t=e.persistence="cookie"),"localStorage"===t&&_.localStorage.isSupported()?(this.storage=_.localStorage,(r=_.cookie.get(this.name))&&_.cookie.remove(this.name,this.crossSubDomain)):(Log.i("localStorage is not support by the browser; falling back to cookie"),this.storage=_.cookie)),this._load(r),this.getDistinctId()||(t=e.uuid||_.UUID(),this._setDeviceId(t),this.setDistinctId(t))},TapDBAPILib=(TapDBPersistence.prototype._load=function(e){var t;this.enabled&&(null!==(t=null!==e?e:this.storage.get(this.name))&&_.check.isJSONString(t)&&(this._state=_.extend({},JSON.parse(t))),null!==e)&&this._save()},TapDBPersistence.prototype.getDistinctId=function(){return this._state.distinct_id},TapDBPersistence.prototype.setDistinctId=function(e){this._set("distinct_id",e)},TapDBPersistence.prototype.setEnableTracking=function(e){this._set("enable_tracking",e)},TapDBPersistence.prototype.getEnableTracking=function(){return!!_.check.isUndefined(this._state.enable_tracking)||this._state.enable_tracking},TapDBPersistence.prototype.clear=function(){this._state={},this._save()},TapDBPersistence.prototype.setOptTracking=function(e){this._set("opt_tracking",e)},TapDBPersistence.prototype.getOptTracking=function(){return!!_.check.isUndefined(this._state.opt_tracking)||this._state.opt_tracking},TapDBPersistence.prototype.setDistinctId=function(e){this._set("distinct_id",e)},TapDBPersistence.prototype.getAccountId=function(){return this._state.account_id},TapDBPersistence.prototype.setAccountId=function(e){this._set("account_id",e)},TapDBPersistence.prototype.getDeviceId=function(){return this._state.device_id},TapDBPersistence.prototype.setSuperProperties=function(e){this._set("super_properties",e)},TapDBPersistence.prototype.getSuperProperties=function(){return this._state.super_properties||{}},TapDBPersistence.prototype.setEventTimer=function(e,t){var r=this._state.event_timers||{};r[e]=t,this._set("event_timers",r)},TapDBPersistence.prototype.clearEventTimer=function(){this._set("event_timers",{})},TapDBPersistence.prototype.removeEventTimer=function(e){var t=(this._state.event_timers||{})[e];return _.check.isUndefined(t)||(delete this._state.event_timers[e],this._save()),t},TapDBPersistence.prototype._setDeviceId=function(e){this._state.device_id?Log.w("Current device_id is ",this.getDeviceId(),", it couldn't been set to: ",e):this._set("device_id",e)},TapDBPersistence.prototype._save=function(){this.enabled&&this.storage.set(this.name,JSON.stringify(this._state),73e3,this.crossSubDomain)},TapDBPersistence.prototype._set=function(e,t){this._state=this._state||{},this._state[e]=t,this._save()},function(){});function BatchConsumer(e){this.config=e,this.timer=null,this.batchConfig=_.extend({size:5,interval:5e3,storageLimit:200},this.config.batch),this.batchConfig.size<1&&(this.batchConfig.size=1),30<this.batchConfig.size&&(this.batchConfig.size=30),this.prefix=this.config.persistencePrefix,this.tabKey=this.prefix+Config.TAB_STORE_PREFIX+this.config.appId,this.storageLimit=this.batchConfig.storageLimit}TapDBAPILib.prototype.trackLink=function(e,n,s){if(this._isCollectData()){let r=this._getConfig("strict");if(!PropertyChecker.properties(s)&&r)Log.w("trackLink failed due to invalid properties.");else if(e&&_.check.isObject(e)){let i=[];_.each(e,(e,r)=>{e&&_.check.isArray(e)&&_.each(e,e=>{switch(r){case"tag":_.each(document.getElementsByTagName(e),e=>{i.indexOf(e)<0&&i.push(e)});break;case"class":_.each(document.getElementsByClassName(e),e=>{i.indexOf(e)<0&&i.push(e)});break;case"id":var t=document.getElementById(e);null!==t&&i.indexOf(t)<0&&i.push(t)}})}),_.each(i,e=>{var t;null!==e&&((t=_.extend({},_.info.pageProperties(),s))["#element_type"]=e.nodeName.toLowerCase(),_.check.isUndefined(t.name)&&(t.name=e.getAttribute("db-name")||e.innerHTML||e.value||"未获取标识"),e.addEventListener("click",()=>{this._sendRequest({type:"track",event:n,properties:r?PropertyChecker.stripProperties(t):t})}))})}}},TapDBAPILib.prototype.setPageProperty=function(e){this._isCollectData()&&(PropertyChecker.properties(e)||!this._getConfig("strict")?_.extend(this.currentProps,e):Log.w("PageProperty 输入的参数有误"))},TapDBAPILib.prototype.getPageProperty=function(){return this.currentProps},TapDBAPILib.prototype.getPresetProperties=function(){var e=_.info.properties(),t={};t.os=e["#os"],t.screenWidth=e["#screen_width"],t.screenHeight=e["#screen_height"],t.browser=e["#browser"],t.browserVersion=e["#browser_version"],t.deviceId=this.getDeviceId();let r=0-(new Date).getTimezoneOffset()/60;return this._getConfig("zoneOffset")&&(r=this._getConfig("zoneOffset")),t.zoneOffset=r,t.toEventPresetProperties=function(){return{"#os":t.os,"#screen_width":t.screenWidth,"#screen_height":t.screenHeight,"#browser":t.browser,"#browser_version":t.browserVersion,"#device_id":t.deviceId,"#zone_offset":t.zoneOffset}},t},TapDBAPILib.prototype.login=function(e){this._isCollectData()&&("number"==typeof e&&(e=String(e)),PropertyChecker.userId(e)||!this._getConfig("strict")?e!==this.persistence.getAccountId()&&this.persistence.setAccountId(e):Log.e("login 的参数必须是字符串"))},TapDBAPILib.prototype.logout=function(e){this._isCollectData()&&(!0===e&&(e=_.UUID(),this.persistence.setDistinctId(e)),this.persistence.setAccountId(""))},TapDBAPILib.prototype.userSet=function(e,t){!this._isCollectData()||!PropertyChecker.propertiesMust(e)&&this._getConfig("strict")||this._sendRequest({type:"user_set",properties:e},t)},TapDBAPILib.prototype.userSetOnce=function(e,t){!this._isCollectData()||!PropertyChecker.propertiesMust(e)&&this._getConfig("strict")||this._sendRequest({type:"user_setOnce",properties:e},t)},TapDBAPILib.prototype.userUnset=function(e,t){var r;!this._isCollectData()||!PropertyChecker.propertyName(e)&&this._getConfig("strict")||((r={})[e]=0,this._sendRequest({type:"user_unset",properties:r},t))},TapDBAPILib.prototype._userAdd=function(e,t){var r;this._isCollectData()&&(_.check.isString(e)&&(r=e,(e={})[r]=1),PropertyChecker.propertiesMust(e))&&(!function(e){for(var t in e)if(!/-*\d+/.test(String(e[t])))return;return 1}(e)&&this._getConfig("strict")?Log.w("userAdd 属性中的值只能是数字"):this._sendRequest({type:"user_add",properties:e},t))},TapDBAPILib.prototype.userAppend=function(e,t){this._isCollectData()&&(PropertyChecker.propertiesMust(e)&&function(e){for(var t in e)if(!_.check.isArray(e[t]))return;return 1}(e)||!this._getConfig("strict")?this._sendRequest({type:"user_append",properties:e},t):Log.w("userAppend 属性中的值只能是 Array"))},TapDBAPILib.prototype.userUniqAppend=function(e,t){this._isCollectData()&&(PropertyChecker.propertiesMust(e)&&function(e){for(var t in e)if(!_.check.isArray(e[t]))return;return 1}(e)||!this._getConfig("strict")?this._sendRequest({type:"user_uniq_append",properties:e},t):Log.w("userUniqAppend 属性中的值只能是 Array"))},TapDBAPILib.prototype.flush=function(){this.batchConsumer&&!this._isDebug()&&this.batchConsumer.flush()},TapDBAPILib.prototype.userDel=function(e){this._isCollectData()&&this._sendRequest({type:"user_del"},e)},TapDBAPILib.prototype._sendRequest=function(t,e,r){var r=!this._getConfig("isUseSLS")&&r,i=_.check.isUndefined(t.time)||!_.check.isDate(t.time)?new Date:t.time,n={data:[{"#type":t.type,"#time":_.formatDate(_.formatTimeZone(i,this._getConfig("zoneOffset"))),"#distinct_id":this.persistence.getDistinctId()}]};if(this.persistence.getAccountId()&&(n.data[0]["#account_id"]=this.persistence.getAccountId()),"track"===t.type||"track_update"===t.type||"track_overwrite"===t.type){n.data[0]["#event_name"]=t.event,"track_update"===t.type||"track_overwrite"===t.type?n.data[0]["#event_id"]=t.extraId:t.firstCheckId&&(n.data[0]["#first_check_id"]=t.firstCheckId);let e=0-i.getTimezoneOffset()/60;this._getConfig("zoneOffset")&&(e=this._getConfig("zoneOffset")),n.data[0].properties=_.extend({},{"#zone_offset":e},_.info.properties(),this.getSuperProperties(),this.dynamicProperties?this.dynamicProperties():{},this.getPageProperty());var i=this.persistence.removeEventTimer(t.event);_.check.isUndefined(i)||(i=(new Date).getTime()-i,i=parseFloat((i/1e3).toFixed(3)),n.data[0].properties["#duration"]=i=86400<i?86400:i)}else n.data[0].properties={};if(_.check.isObject(t.properties)&&!_.check.isEmptyObject(t.properties)&&_.extend(n.data[0].properties,t.properties),_.searchObjDate(n.data[0],this._getConfig("zoneOffset")),"ajax"===this._getConfig("send_method")&&(n.data[0]=_.generateEncryptyData(n.data[0],this._getConfig("secretKey"))),n["#app_id"]=this._getConfig("appId"),n["#flush_time"]=_.formatTimeZone(new Date,this._getConfig("zoneOffset")).getTime(),Log.i(n),this._getConfig("isUseSLS")&&(n.data[0]["#event_time"]=n["#flush_time"]),this._getConfig("useAppTrack")){i=window.TapDB_APP_JS_Bridge||{};if("object"==typeof i&&i.tapdb_track)return i.tapdb_track(JSON.stringify(n)),void("function"==typeof e&&e());if(/db-sdk-ios/.test(navigator.userAgent)&&!window.MSStream)return(t=document.createElement("iframe")).setAttribute("src","tapdbanalytics://trackEvent?event="+_.encodeURIComponent(JSON.stringify(n))),document.documentElement.appendChild(t),t.parentNode.removeChild(t),t=null,void("function"==typeof e&&e())}r&&(n.data[0]["#uuid"]=_.UUIDv4());i=_collectTapDBReportData(this._getConfig("inDBOrDC"),this.getDeviceId(),n,this._getConfig("isUseSLS"));if(!this.batchConsumer||this._isDebug()||r)if(r&&navigator.sendBeacon)t=new FormData,this._isDebug()?(t.append("data",_.encodeURIComponent(JSON.stringify(i.data[0]))),t.append("source","client"),t.append("deviceId",this.getDeviceId()),t.append("appid",this._getConfig("appId")),t.append("version",Config.LIB_VERSION),"debug_only"===this._getConfig("mode")&&t.append("dryRun",1)):t.append("data",_.base64Encode(n)),navigator.sendBeacon(this._getConfig("serverUrl"),t);else{var s,o=i.data[0];switch(this.config.isUseCRC&&(r=_.base64Encode(o),o.crc=_.hashCode(r)),this._getConfig("textContent")){case"form":s=_.encodeURIComponent(JSON.stringify(o));break;case"json":s=o;break;case"protobuf":s=JSON.stringify(o)}this._isDebug()&&(s="data="+_.encodeURIComponent(JSON.stringify(o))+"&source=client&deviceId="+this.getDeviceId()+"&appid="+this._getConfig("appId")+"&version="+Config.LIB_VERSION,"debug_only"===this._getConfig("mode"))&&(s+="&dryRun=1"),"ajax"===this._getConfig("send_method")?new AjaxTask(s,this._getConfig("serverUrl"),this._getConfig("tryCount"),e,this._isDebug(),this._getConfig("headers"),this._getConfig("isUseSLS")).run():this._sendRequestWithImage(s,e)}else this.batchConsumer.add(i.data[0])},BatchConsumer.prototype={batchInterval:function(){var e=this;e.timer=setTimeout(function(){e.recycle(),e.send(),clearTimeout(e.timer),e.batchInterval()},this.batchConfig.interval)},add:function(e){var t=this.prefix+Config.STORE_PREFIX+this.config.appId+"_"+String(_.getRandom()),r=_.localStorage.get(this.tabKey);if((r=null!==r&&_.safeJSONParse(r)||[]).length<=this.storageLimit)r.push(t),_.localStorage.set(this.tabKey,JSON.stringify(r)),_.saveObjectVal(t,e);else{for(var i=r.splice(0,20),r=(Log.i("删除的数据:"+i),r.push(t),_.localStorage.set(this.tabKey,JSON.stringify(r)),_.saveObjectVal(t,e),{}),n=[],s=0;s<i.length;s++){var o=_.readObjectVal(i[s]);_.hasEncrypty(o)||(o=_.generateEncryptyData(o,this.config.secretKey)),n.push(o)}r.data=n,this.request(r,i)}},flush:function(){clearTimeout(this.timer),this.send(),this.batchInterval()},send:function(){var e=_.localStorage.get(this.tabKey);if(e&&(e=_.safeJSONParse(e)||[]).length){for(var t={},r=[],i=[],n=e.length<this.batchConfig.size?e.length:this.batchConfig.size,s=0;s<n;s++){var o=_.readObjectVal(e[s]);_.hasEncrypty(o)||(o=_.generateEncryptyData(o,this.config.secretKey)),r.push(o),i.push(e[s])}t.data=r,this.request(t,i)}},request:function(e,t){var r,i=this,n=(Log.i("flush data"),Log.i(e),e);switch(this.config.isUseCRC&&(e=_.base64Encode(n),n.crc=_.hashCode(e)),this.config.textContent){case"form":r=_.encodeURIComponent(JSON.stringify(n));break;case"json":r=n;break;case"protobuf":r=JSON.stringify(n)}new AjaxTask(r,this.config.serverUrl,this.config.tryCount,function(){i.remove(t)},!1,this.config.headers,this.config.isUseSLS).run()},remove:function(e){var t=_.localStorage.get(this.tabKey);if(t){for(var r=_.safeJSONParse(t)||[],i=0;i<e.length;i++){var n=_.indexOf(r,e[i]);-1<n&&r.splice(n,1),_.localStorage.remove(e[i])}_.localStorage.set(this.tabKey,JSON.stringify(r))}},recycle:function(){var e=_.localStorage.get(this.tabKey);if(e&&0===(e=_.safeJSONParse(e)||[]).length){for(var t=0;t<localStorage.length;t++){var r=localStorage.key(t);0===r.indexOf(this.prefix+Config.STORE_PREFIX+this.config.appId)&&e.push(r)}0<e.length&&_.localStorage.set(this.tabKey,JSON.stringify(e))}}};class AjaxTask{constructor(e,t,r,i,n,s,o){this.data=e,this.serverUrl=t,this.tryCount=r||3,this.callback=i,this.isDebug=n,this.headers=s,this.isUseSLS=o}transString(){var e,t={};for(e in this.data)"object"==typeof this.data[e]?t[e]=JSON.stringify(this.data[e]):t[e]=String(this.data[e]);return t}sendBeacon(e){return!(!navigator||!navigator.sendBeacon)&&navigator.sendBeacon(this.serverUrl+"?APIVersion=0.6.0",e)}sendUseXhr(e){var t=new window.XMLHttpRequest,e=(t.open("POST",this.serverUrl,!0),t.setRequestHeader("x-log-apiversion","0.6.0"),t.setRequestHeader("x-log-bodyrawsize",e.length.toString()),new Blob([e],{type:"application/x-protobuf"}));t.send(e)}run(){if(this.isUseSLS)try{var e=JSON.stringify({__logs__:[this.transString()]});this.sendBeacon(e)||this.sendUseXhr(e)}catch(e){this.onFailed()}else{var t=null,r=((t=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP")).open("post",this.serverUrl,!0),this.headers?Object.keys(this.headers).forEach(e=>{t.setRequestHeader(e,this.headers[e])}):t.setRequestHeader("Content-type","application/x-www-form-urlencoded"),this);t.onreadystatechange=function(){var e;4===t.readyState&&(200<=t.status&&t.status<300||304===t.status?(r.callback&&r.callback(),r.isDebug&&(0!==(e=JSON.parse(t.response)).errorLevel?Log.w(e):Log.i(e))):r.onFailed())},t.send(this.data)}}onFailed(){0<--this.tryCount&&this.run()}}TapDBAPILib.prototype._isDebug=function(){return"debug"===this._getConfig("mode")||"debug_only"===this._getConfig("mode")},TapDBAPILib.prototype._sendRequestWithImage=function(e,t){function r(e){e&&!e.hasCalled&&(e.hasCalled=!0,e.callback)&&e.callback()}var e=(-1!==this._getConfig("serverUrl").indexOf("?")?this._getConfig("serverUrl"):this._getConfig("serverUrl")+"?")+e,i=document.createElement("img");i.callback=t,setTimeout(r,this._getConfig("dataSendTimeout"),i),i.onload=function(){this.onload=null,r(this)},i.onerror=function(){this.onerror=null,r(this)},i.onabort=function(){this.onabort=null,r(this)},i.src=e},TapDBAPILib.prototype.track=function(e,t,r,i){this._isCollectData()&&([Config.PAGE_SHOW,Config.PAGE_HIDE].includes(e)||PropertyChecker.event(e)&&PropertyChecker.properties(t)||!this._getConfig("strict"))&&this._sendRequest({type:"track",event:e,time:_.check.isDate(r)?r:new Date,properties:t},i)},TapDBAPILib.prototype.trackUpdate=function(e){this._isCollectData()&&(_.check.isObject(e)?(PropertyChecker.event(e.eventName)&&PropertyChecker.properties(e.properties)||!this._getConfig("strict"))&&this._sendRequest({type:"track_update",event:e.eventName,time:_.check.isDate(e.eventTime)?e.eventTime:new Date,properties:e.properties,extraId:e.eventId},e.callback):Log.e("trackUpdate 参数不符合要求"))},TapDBAPILib.prototype.trackOverwrite=function(e){this._isCollectData()&&(_.check.isObject(e)?(PropertyChecker.event(e.eventName)&&PropertyChecker.properties(e.properties)||!this._getConfig("strict"))&&this._sendRequest({type:"track_overwrite",event:e.eventName,time:_.check.isDate(e.eventTime)?e.eventTime:new Date,properties:e.properties,extraId:e.eventId},e.callback):Log.e("trackOverwrite 参数不符合要求"))},TapDBAPILib.prototype.trackFirstEvent=function(e){this._isCollectData()&&(_.check.isObject(e)?(PropertyChecker.event(e.eventName)&&PropertyChecker.properties(e.properties)||!this._getConfig("strict"))&&this._sendRequest({type:"track",event:e.eventName,time:_.check.isDate(e.eventTime)?e.eventTime:new Date,properties:e.properties,firstCheckId:e.firstCheckId||this.getDeviceId()},e.callback):Log.e("trackFirstEvent 参数不符合要求"))},TapDBAPILib.prototype.trackWithBeacon=function(e,t,r,i){(e===Config.PAGE_HIDE||PropertyChecker.event(e)&&PropertyChecker.properties(t)||!this._getConfig("strict"))&&this._sendRequest({type:"track",event:e,time:_.check.isDate(r)?r:new Date,properties:t},i,!0)},TapDBAPILib.prototype.identify=function(e){this._isCollectData()&&("number"==typeof e&&(e=String(e)),PropertyChecker.userId(e)||!this._getConfig("strict")?e!==this.persistence.getDistinctId()&&this.persistence.setDistinctId(e):Log.e("identify 的参数必须是字符串"))},TapDBAPILib.prototype.getDistinctId=function(){return this.persistence.getDistinctId()},TapDBAPILib.prototype.getDeviceId=function(){return this.persistence.getDeviceId()},TapDBAPILib.prototype._isCollectData=function(){return this.persistence.getOptTracking()&&this.persistence.getEnableTracking()},TapDBAPILib.prototype.setSuperProperties=function(e){this._isCollectData()&&(PropertyChecker.propertiesMust(e)||!this._getConfig("strict")?this.persistence.setSuperProperties(_.extend({},this.getSuperProperties(),e)):Log.w("setSuperProperties 参数不合法"))},TapDBAPILib.prototype.getSuperProperties=function(){return this.persistence.getSuperProperties()},TapDBAPILib.prototype.clearSuperProperties=function(){this._isCollectData()&&this.persistence.setSuperProperties({})},TapDBAPILib.prototype.unsetSuperProperty=function(e){var t;this._isCollectData()&&_.check.isString(e)&&(delete(t=this.getSuperProperties())[e],this.persistence.setSuperProperties(t))},TapDBAPILib.prototype.setDynamicSuperProperties=function(e){this._isCollectData()&&("function"==typeof e?PropertyChecker.properties(e())||!this._getConfig("strict")?this.dynamicProperties=e:Log.w("动态公共属性必须返回合法的属性值"):Log.w("setDynamicSuperProperties 的参数必须是 function 类型"))},TapDBAPILib.prototype.timeEvent=function(e){this._isCollectData()&&(_.check.isUndefined(e)?Log.w("No event name provided to timeEvent"):this.persistence.setEventTimer(e,(new Date).getTime()))},TapDBAPILib.prototype.quick=function(e,t){var r;this._isCollectData()&&("string"==typeof e&&"autoTrack"===e?(r={},PropertyChecker.properties(t)&&_.extend(r,t),this._sendRequest({type:"track",event:Config.PAGE_VIEW,properties:_.extend(r,_.info.pageProperties())})):"string"==typeof e&&"siteLinker"===e?siteLinker.init(this,t):Log.w("quick方法中没有这个功能"+e))},TapDBAPILib.prototype._setConfig=function(e){_.check.isObject(e)&&(_.extend(this.config,e),this._getConfig("persistencePrefix")||(this.config.persistencePrefix=this.config.cookiePrefix),this.persistence)},TapDBAPILib.prototype._getConfig=function(e){return this.config[e]},TapDBAPILib.prototype.init=function(e){var t;_.check.isUndefined(this.config)?(this.config={},this.currentProps=this.currentProps||{},this._setConfig(_.extend({},DEFAULT_CONFIG,e)),this.persistence=new TapDBPersistence(this.config),t=this._getConfig("appId"),_.check.isUndefined(t)||this._setConfig({appId:t.replace(/\s*/g,"")}),Log.showLog=this._getConfig("showLog"),"image"!==(t=this._getConfig("send_method"))&&"ajax"!==t&&"beacon"!==t&&(Log.i("send_method",t,"is not supported. Changed to image as default value"),this._setConfig({send_method:"image"})),new PageLifeCycle(this,this._getConfig("autoTrack")).start(),this._isDebug()?this._setConfig({serverUrl:e.serverUrlDebug}):void 0!==this._getConfig("batch")&&!1!==this._getConfig("batch")&&_.localStorage.isSupported()?(this._setConfig({serverUrl:e.serverUrlBatch}),this.batchConsumer=new BatchConsumer(this.config),this.batchConsumer.batchInterval()):this._setConfig({serverUrl:e.serverUrl}),this._getConfig("isInitDeviceLogin")&&this.trackEvent("device_login")):Log.i("The library has been initialized.")};class PageLifeCycle{constructor(e,t){this.taLib=e,"Object"===_.paramType(t)&&"Boolean"===_.paramType(t.pageShow)?this.autoPageShow=t.pageShow:this.autoPageShow=!1,"Object"===_.paramType(t)&&"Boolean"===_.paramType(t.pageHide)?this.autoPageHide=t.pageHide:this.autoPageHide=!1}start(){var e=this;"onpageShow"in window?(_.addEvent(window,"pageShow",function(){e.trackPageShowEvent()}),_.addEvent(window,"pageHide",function(){})):(_.addEvent(window,"load",function(){e.trackPageShowEvent()}),_.addEvent(window,"beforeunload",function(){})),"onvisibilitychange"in document&&_.addEvent(document,"visibilitychange",function(){document.hidden?e.trackPageHideEvent():e.trackPageShowEvent()})}trackPageShowEvent(){this.autoPageShow&&this.taLib.track(Config.PAGE_SHOW,_.info.pageProperties()),this.taLib.timeEvent(Config.PAGE_HIDE)}trackPageHideEvent(){this.autoPageHide&&this.taLib.trackWithBeacon(Config.PAGE_HIDE,_.info.pageProperties())}trackPageHideEventOnClose(){this.autoPageHide&&this.isPageShow&&this.taLib.trackWithBeacon(Config.PAGE_HIDE,_.info.pageProperties())}}TapDBAPILib.prototype.initInstance=function(e,t){if(!_.check.isString(e)||!_.check.isUndefined(t)&&!_.check.isObject(t))return Log.w("invalid parameter of initInstance(string, object)."),null;if(this._getConfig("_name")!==MASTER_INSTANCE_NAME)return Log.w("This function is allowed for master instance only"),null;if(e===MASTER_INSTANCE_NAME||this[e])return Log.w("The name ",e," couldn't be used for create new instance."),null;_.check.isUndefined(t)&&(t={});var r=new TapDBAPILib,t=_.extend({},this.config,{_name:e,persistenceEnabled:!1,uuid:this.getDeviceId()},t);t.persistenceEnabled&&(t.persistencePrefix=t.persistencePrefix+"_"+e),r.init(t),this[e]=r},TapDBAPILib.prototype.enableTracking=function(e){"boolean"==typeof e&&this.persistence.setEnableTracking(e)},TapDBAPILib.prototype.optOutTracking=function(){this.persistence.setSuperProperties({}),this.persistence.setAccountId(""),this.persistence.clearEventTimer(),this.persistence.setOptTracking(!1)},TapDBAPILib.prototype.optInTracking=function(){this.persistence.setOptTracking(!0)},TapDBAPILib.prototype.setTrackStatus=function(e){_.check.isObject(e)&&("pause"===(e=e.status)?this.enableTracking(!1):"stop"===e?this.optOutTracking():"normal"===e&&(this.enableTracking(!0),this.optInTracking()))};var dbMaster,siteLinker={};function initAsModule(){return dbMaster=new TapDBAPILib}function _replaceTapdbBeginChar(e){return 0===e.indexOf("#")?e.substring(1):"#"+e}function _resetTapdbProperties(t){const r={};return t&&_.check.isObject(t)&&Object.keys(t).forEach(e=>{r[_replaceTapdbBeginChar(e)]=t[e]}),r}function _collectTapDBReportData(t,r,i,n){var s;const o=i["data"];if(o[0]["#type"]){let e=o[0]["#type"];switch(o[0]["#type"]){case"tapdb_device_initialize":case"tapdb_user_initialize":e="initialise";break;case"tapdb_device_add":case"tapdb_user_add":e="add";break;case"tapdb_device_update":case"tapdb_user_update":e="update"}["track","track_update","track_overwrite"].includes(o[0]["#type"])?(s={device_id:r,type:"track",name:o[0]["#event_name"],properties:{}},n&&(s.event_uuid=_.UUIDv4(),s.event_time=o[0]["#event_time"]),o[0]["#account_id"]&&(s.user_id=o[0]["#account_id"])):s=["tapdb_device_init","tapdb_device_add","tapdb_device_update"].includes(o[0]["#type"])?{device_id:r,type:e,properties:{}}:{user_id:o[0]["#account_id"],type:e,properties:{}},Object.keys(o[0].properties).forEach(e=>{0===e.indexOf("#")?s.properties[e.substring(1)]=o[0].properties[e]:s.properties["#"+e]=o[0].properties[e]}),"db"===t?s.index=i["#app_id"]:s.client_id=i["#app_id"]}return{"#app_id":i["#app_id"],data:[s]}}siteLinker.getPartUrl=function(e){var t=this.option.length;if(t)for(var r=0;r<t;r++)if(-1<e.indexOf(this.option[r].part_url))return!0;return!1},siteLinker.getPartHash=function(e){var t=this.option.length;if(t)for(var r=0;r<t;r++)if(-1<e.indexOf(this.option[r].part_url))return this.option[r].after_hash;return!1},siteLinker.getCurrenId=function(){var e=this.db.getDistinctId();return encodeURIComponent("d"+e)},siteLinker.rewriteUrl=function(e,t){var r,i,n,s=/([^?#]+)(\?[^#]*)?(#.*)?/.exec(e),o="";if(s)return r=s[1]||"",i=s[2]||"",s=s[3]||"",o=this.getPartHash(e)?(n=s.indexOf("_dbsdk"),-1<s.indexOf("?")?-1<n?r+i+"#"+s.substring(1,n)+"_dbsdk="+this.getCurrenId():r+i+"#"+s.substring(1)+"&_dbsdk="+this.getCurrenId():r+i+"#"+s.substring(1)+"?_dbsdk="+this.getCurrenId()):(n=i.indexOf("_dbsdk"),/^\?(\w)+/.test(i)?-1<n?r+"?"+i.substring(1,n)+"_dbsdk="+this.getCurrenId()+s:r+"?"+i.substring(1)+"&_dbsdk="+this.getCurrenId()+s:r+"?"+i.substring(1)+"_dbsdk="+this.getCurrenId()+s),t&&(t.href=o),o},siteLinker.addClickListen=function(){function e(e){var t,r=(e=e.target).tagName.toLowerCase(),i=e.parentNode;("a"===r&&e.href||i&&i.tagName&&"a"===i.tagName.toLowerCase()&&i.href)&&(r="a"===r&&e.href?(t=e.href,e):(t=i.href,i),"http:"!==(e=_.URL(t).protocol)&&"https:"!==e||n.getPartUrl(t)&&n.rewriteUrl(t,r))}var n=this;_.addSiteEvent(document,"mousedown",e),window.PointerEvent&&"maxTouchPoints"in window.navigator&&0<=window.navigator.maxTouchPoints&&_.addSiteEvent(document,"pointerdown",e)},siteLinker.getUrlId=function(){var e=location.href.match(/_dbsdk=([aufd][^\?\#\&\=]+)/);return _.check.isArray(e)&&e[1]?decodeURIComponent(e[1]):""},siteLinker.setRefferId=function(){var e,t=this.db.getDistinctId(),r=this.getUrlId();return""!==r&&(e="d"===r.substring(0,1),(r=r.substring(1))!==t)&&void(r&&e&&this.db.identify(r))},siteLinker.init=function(e,t){this.isInited||(this.isInited=!0,this.db=e,this.setRefferId(),_.check.isObject(t)&&_.check.isArray(t.linker)&&0<t.linker.length&&(this.addClickListen(),this.option=t.linker,this.option=function(e){for(var t=e.length,r=[],i=0;i<t;i++)/[A-Za-z0-9]+\./.test(e[i].part_url)&&"[object Boolean]"===Object.prototype.toString.call(e[i].after_hash)?r.push(e[i]):Log.w("linker配置的第 "+(i+1)+" 项格式不正确,请检查参数格式");return r}(this.option)))},TapDBAPILib.prototype.registerStaticProperties=function(e){this.setSuperProperties(_resetTapdbProperties(e))},TapDBAPILib.prototype.unregisterStaticProperty=function(e){this.unsetSuperProperty(_replaceTapdbBeginChar(e))},TapDBAPILib.prototype.clearStaticProperties=function(){this.clearSuperProperties()},TapDBAPILib.prototype.registerDynamicProperties=function(e){this.setDynamicSuperProperties(e)},TapDBAPILib.prototype.trackEvent=function(e,t){this.track(e,_resetTapdbProperties(t))},TapDBAPILib.prototype.setUser=function(e,t){this.login(e),this.trackEvent("user_login",_resetTapdbProperties(t)),this.deviceUpdate({has_user:!0})},TapDBAPILib.prototype.clearUser=function(){this.logout()},TapDBAPILib.prototype.setName=function(e,t){this._sendRequest({type:"tapdb_user_update",properties:_resetTapdbProperties({"#user_name":e})},t)},TapDBAPILib.prototype.deviceInitialize=function(e,t){this._sendRequest({type:"tapdb_device_initialize",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.deviceUpdate=function(e,t){this._sendRequest({type:"tapdb_device_update",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.deviceAdd=function(e,t){this._sendRequest({type:"tapdb_device_add",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.userInitialize=function(e,t){this._sendRequest({type:"tapdb_user_initialize",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.userUpdate=function(e,t){this._sendRequest({type:"tapdb_user_update",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.userAdd=function(e,t){this._sendRequest({type:"tapdb_user_add",properties:_resetTapdbProperties(e)},t)},TapDBAPILib.prototype.trackLinkEvent=function(e,t,r){this.trackLink(e,t,_resetTapdbProperties(r))},TapDBAPILib.prototype.trackLinkClickEvent=function(e,t){this.trackLinkEvent(e,"click",t)},TapDBAPILib.prototype.pvEvent=function(e){this.quick("autoTrack",_resetTapdbProperties(e))},TapDBAPILib.prototype.setPagePropertyEvent=function(e){this._isCollectData()&&this.setPageProperty(_resetTapdbProperties(e))},TapDBAPILib.prototype.getPagePropertyEvent=function(){return _resetTapdbProperties(this.getPageProperty())};var db=initAsModule();export default db;