var dianshangji_bg={name_:"ext",version_:"2015-03-29",debug_:!1,debugframe_:!1,loadframe_:!1,kernel_:null,publicTempVar:{name:"",value:""},clientid_:"",script:null,debug:function(a){this.debug_&&console.debug(a)},log:function(a){this.debug_&&console.log(a)},sendRequest:function(a,c,b,f){typeof c=="undefined"&&(c={});typeof f!="undefined"?jQuery.ajax({type:"POST",url:a,data:f,dataType:"text",headers:c,success:function(a){b(a)},error:function(){b(null)}}):jQuery.ajax({type:"GET",url:a,dataType:"text",
headers:c,success:function(a){b(a)},error:function(){b(null)}})},onRequest:function(a,c,b){this.debug((new Date).toString()+" "+a);try{a=JSON.parse(a)}catch(f){a={url:a}}if(a.url.indexOf("getbgname://")==0)b(this.name_);else if(a.url.indexOf("getversion://")==0)b(this.version_);else if(a.url.indexOf("getstorage://")==0){var a=a.url.substr(13),d=localStorage.getItem(a);null==d&&(d="");b(d)}else if(a.url.indexOf("setstorage://")==0)d=a.url.substr(13),c=d.indexOf("/"),a=d.substr(0,c),d=d.substr(c+1),
localStorage.setItem(a,d),b("");else if(a.url.indexOf("gettemp://")==0)a=a.url.substr(10),this.publicTempVar.name!=a?b(""):b(this.publicTempVar.value);else if(a.url.indexOf("settemp://")==0)d=a.url.substr(10),c=d.indexOf("/"),c<0?b(""):(a=d.substr(0,c),d=d.substr(c+1),this.publicTempVar={name:a,value:d},b(a));else if(a.url.indexOf("getmytab://")==0)typeof c.tab!="undefined"?b(JSON.stringify(c.tab)):b("");else if(a.url.indexOf("opennewtab://")==0)a=a.url.substr(13),opennewtab(a,function(a){b(a)});
else if(a.url.indexOf("closetab://")==0){var e=a.url.substr(11);removetab(parseInt(e),function(){b(e)})}else if(a.url.indexOf("reloadtab://")==0)e=a.url.substr(12),reloadtab(parseInt(e),function(){b(e)});else if(a.url.indexOf("gettab://")==0)e=a.url.substr(9),gettab(parseInt(e),function(a){b(JSON.stringify(a))});else if(a.url.indexOf("querytab://")==0)querytab(a.postData.queryInfo,function(a){b(JSON.stringify(a))});else if(a.url.indexOf("getalltabs://")==0)getalltabs(function(a){b(JSON.stringify(a))});
else if(a.url.indexOf("updatetab://")==0)d=a.postData.updateProperties,e=a.postData.tabId,updatetab(e,d,function(a){b(JSON.stringify(a))});else if(a.url=="calltab://")e=a.postData.tabId,0==e?b(""):calltab(e,a.postData.code,function(a){b(a)});else if(a.url=="callmytab://")typeof c.tab=="undefined"?b(""):(e=c.tab.id,calltab(e,a.postData.code,function(a){b(a)}));else if(a.url.indexOf("loadscript://")==0){b("");try{if(this.script){try{document.body.removeChild(this.script)}catch(i){}this.script=null}var h=
a.url.substr(13),g=document.createElement("script");g.charset="utf-8";g.src=h;document.body.appendChild(g);this.script=g}catch(j){}}else if(a.url.indexOf("eval://")==0){a=a.url.substr(7);try{d=eval(a),b(JSON.stringify(d))}catch(k){b("")}}else this.sendRequest(a.url,a.hdr,function(a){try{null==a?b(""):b(a)}catch(c){}},a.postData)},verify:function(a,c){var b=new KJUR.crypto.Signature({alg:"SHA256withECDSA",prov:"cryptojs/jsrsa"});b.initVerifyByPublicKey({ecpubhex:"045fe3f9c1b72210711f9b8ac4e15f2ae0b530aa54f2d69e54d0754c2e991ee82aa9ad3ea74d646dfb783cfb68623f265d330dc5e96043db08b2723d4eb707e9f8baf7a31d0004474265409652b2abfd9758e955e3f3642ece159f1dadd53c6fba",
eccurvename:"secp384r1"});b.updateString(a);return b.verify(c)?!0:!1},loopUpdate:function(){var a=this;setTimeout(function(){a.loopUpdate()},864E5);a.checkUpdate()},loadKernel:function(a){try{eval(a)}catch(c){}},checkUpdate:function(){var a=this,c=localStorage.getItem("_extsign"),b=localStorage.getItem("_extpack");c&&b&&a.verify(b,c)&&a.loadKernel(b);var c="http://update.dianshangji.com/dianshangji/extupdate.sign?_="+a.clientid_+"&__="+(new Date).getTime(),f="http://update.dianshangji.com/dianshangji/extupdate.pack?_="+
a.clientid_+"&__="+(new Date).getTime();a.sendRequest(c,{},function(b){try{null==b?setTimeout(function(){a.checkUpdate()},6E5):localStorage.getItem("_extsign")!=b&&a.sendRequest(f,{},function(c){try{null==c?setTimeout(function(){a.checkUpdate()},6E5):!1!=a.verify(c,b)&&(localStorage.setItem("_extsign",b),localStorage.setItem("_extpack",c),a.loadKernel(c))}catch(e){}})}catch(c){}})},getCodeUpdate:function(a,c,b){var f=this,d="http://update.dianshangji.com/dianshangji/"+a+".sign?_="+f.clientid_+"&__="+
(new Date).getTime(),e="http://update.dianshangji.com/dianshangji/"+a+"?_="+f.clientid_+"&__="+(new Date).getTime();b?f.sendRequest(e,{},function(a){try{null==a?c(null):c(a)}catch(b){c(null)}}):f.sendRequest(d,{},function(a){try{null==a?c(null):f.sendRequest(e,{},function(b){try{null==b?c(null):!1==f.verify(b,a)?c(null):c(b)}catch(d){c(null)}})}catch(b){c(null)}})},blobToBase64:function(a,c){var b=new FileReader;b.onload=function(){var a=b.result.split(",")[1];c(a)};b.readAsDataURL(a)},base64ToBlob:function(a,
c){for(var b=atob(a),f=b.length,d=new ArrayBuffer(f),d=new Uint8Array(d),e=0;e<f;e++)d[e]=b.charCodeAt(e);c(new Blob([d]))}},myid=localStorage.getItem("_clientid");if(null==myid){var now=(new Date).getTime();setTimeout(function(){var a=(new Date).getTime();myid=(now.toString()+a.toString()+Math.random()*1E8+"_________________________").substr(0,32);localStorage.setItem("_clientid",myid);dianshangji_bg.clientid_=myid},now%1E3+Math.random()*1E3)}else dianshangji_bg.clientid_=myid;
if(dianshangji_bg.loadframe_){var frameserver;frameserver=dianshangji_bg.debugframe_?"test.dianshangji.com":"www.dianshangji.com";var bgframeUrl_="http://"+frameserver+"/dianshangji/bgframe.htm?version="+dianshangji_bg.version_,bgframe=document.createElement("div");bgframe.innerHTML='<iframe src="'+bgframeUrl_+'" id="bgframe">';document.body.appendChild(bgframe);window.addEventListener("message",function(a){if(a.source==bgframe.contentWindow){var c=a.data;dianshangji_bg.onRequest(c,{},function(b){a.source.postMessage(c+
"\t"+b,"http://www.dianshangji.com")})}})}ontabrequested(function(a,c,b){return dianshangji_bg.onRequest(a,c,b)});dianshangji_bg.loopUpdate();localStorage.setItem("_appconf",JSON.stringify(appconf));
