var dianshangji_externalPort=null,dianshangji_bg={debug_:!1,version_:"2015-12-11_1",clientid_:"",interfaces_:[],localAddress_:"",localPort_:0,proxyAddress_:"",proxyPort_:0,defaultListenPort_:56888,defaultProxyPort_:56889,redirectHost_:null,methods_:{},serverSocketId_:0,clientSocketIds_:{},onAccept_:null,onReceive_:null,onReceiveError_:null,httpRequests_:{},debug:function(a){this.debug_&&console.debug(a)},log:function(a){this.debug_&&console.log(a)},postInfo:function(){dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"info",
response:{addr:this.localAddress_,port:this.localPort_,proxyAddress:this.proxyAddress_,proxyPort:this.proxyPort_,interfaces:this.interfaces_}})},onMessageExternal:function(a,d,b){try{if(this.methods_.hasOwnProperty(a.id))return this.methods_[a.id](a,d,b),!1;switch(a.id){case "version":return b(this.version_),!1;case "info":b({addr:this.localAddress_,port:this.localPort_,proxyAddress:this.proxyAddress_,proxyPort:this.proxyPort_,interfaces:this.interfaces_});break;case "proxy":processProxyResponse(a);
break;case "httpget":this.processHttpResponse(a);break;case "runtime.lastError":return b(chrome.runtime.lastError),!1;case "storage.local.get":chrome.storage.local.get(a.keys,function(a){chrome.runtime.lastError?b(chrome.runtime.lastError):b(a)});break;case "storage.local.getBytesInUse":chrome.storage.local.getBytesInUse(a.keys,function(a){chrome.runtime.lastError?b(chrome.runtime.lastError):b(a)});break;case "storage.local.set":chrome.storage.local.set(a.items,function(){chrome.runtime.lastError?
b(chrome.runtime.lastError):b("ok")});break;case "storage.local.clear":chrome.storage.local.clear(function(){chrome.runtime.lastError?b(chrome.runtime.lastError):b("ok")});break;case "storage.local.remove":chrome.storage.local.remove(a.keys,function(){chrome.runtime.lastError?b(chrome.runtime.lastError):b("ok")});break;case "tcp.create":chrome.sockets.tcp.create(a.properties,function(a){b(a)});break;case "tcp.update":chrome.sockets.tcp.update(a.socketId,a.properties,function(){b("ok")});break;case "tcp.setPaused":chrome.sockets.tcp.setPaused(a.socketId,
a.paused,function(){b("ok")});break;case "tcp.setKeepAlive":chrome.sockets.tcp.setKeepAlive(a.socketId,a.enable,a.delay,function(a){b(a)});break;case "tcp.setNoDelay":chrome.sockets.tcp.setNoDelay(a.socketId,a.noDelay,function(a){b(a)});break;case "tcp.connect":chrome.sockets.tcp.connect(a.socketId,a.peerAddress,a.peerPort,function(a){b(a)});break;case "tcp.disconnect":chrome.sockets.tcp.disconnect(a.socketId,function(){b("ok")});break;case "tcp.secure":chrome.sockets.tcp.secure(a.socketId,a.options,
function(a){b(a)});break;case "tcp.send":chrome.sockets.tcp.send(a.socketId,(new Uint8Array(a.data)).buffer,function(a){b(a)});break;case "tcp.close":chrome.sockets.tcp.close(a.socketId,function(){b("ok")});break;case "tcp.getInfo":chrome.sockets.tcp.getInfo(a.socketId,function(a){b(a)});break;case "tcp.getSockets":chrome.sockets.tcp.getSockets(function(a){b(a)});break;case "tcpServer.create":chrome.sockets.tcpServer.create(a.properties,function(a){b(a)});break;case "tcpServer.update":chrome.sockets.tcpServer.update(a.socketId,
a.properties,function(){b("ok")});break;case "tcpServer.setPaused":chrome.sockets.tcpServer.setPaused(a.socketId,a.paused,function(){b("ok")});break;case "tcpServer.listen":chrome.sockets.tcpServer.listen(a.socketId,a.address,a.port,a.backlog,function(a){b(a)});break;case "tcpServer.disconnect":chrome.sockets.tcpServer.disconnect(a.socketId,function(){b("ok")});break;case "tcpServer.close":chrome.sockets.tcpServer.close(a.socketId,function(){b("ok")});break;case "tcpServer.getInfo":chrome.sockets.tcpServer.getInfo(a.socketId,
function(a){b(a)});break;case "tcpServer.getSockets":chrome.sockets.tcpServer.getSockets(function(a){b(a)});break;case "udp.create":chrome.sockets.udp.create(a.properties,function(a){b(a)});break;case "udp.update":chrome.sockets.udp.update(a.socketId,a.properties,function(){b("ok")});break;case "udp.setPaused":chrome.sockets.udp.setPaused(a.socketId,a.paused,function(){b("ok")});break;case "udp.bind":chrome.sockets.udp.bind(a.socketId,a.address,a.port,function(a){b(a)});break;case "udp.send":chrome.sockets.udp.send(a.socketId,
(new Uint8Array(a.data)).buffer,a.address,a.port,function(a){b(a)});break;case "udp.close":chrome.sockets.udp.close(a.socketId,function(){b("ok")});break;case "udp.getInfo":chrome.sockets.udp.getInfo(a.socketId,function(a){b(a)});break;case "udp.getSockets":chrome.sockets.udp.getSockets(function(a){b(a)});break;case "udp.joinGroup":chrome.sockets.udp.joinGroup(a.socketId,a.address,function(a){b(a)});break;case "udp.leaveGroup":chrome.sockets.udp.leaveGroup(a.socketId,a.address,function(a){b(a)});
break;case "udp.setMulticastTimeToLive":chrome.sockets.udp.setMulticastTimeToLive(a.socketId,a.ttl,function(a){b(a)});break;case "udp.setMulticastLoopbackMode":chrome.sockets.udp.setMulticastLoopbackMode(a.socketId,a.enabled,function(a){b(a)});break;case "udp.getJoinedGroups":chrome.sockets.udp.getJoinedGroups(a.socketId,function(a){b(a)});break;case "udp.setBroadcast":chrome.sockets.udp.setBroadcast(a.socketId,a.enabled,function(a){b(a)});break;default:return b("unknown method id: "+a.id),!1}}catch(c){return b("exception: "+
c),!1}return!0},setupLocalWeb:function(a,d,b){var c=this;if(b)c.redirectHost_=b;(function(){var b=chrome.sockets.tcpServer,g=chrome.sockets.tcp,h=null,e=function(a){for(var b=new ArrayBuffer(a.length),b=new Uint8Array(b),f=0;f<a.length;f++)b[f]=a.charCodeAt(f);return b},m=function(a){for(var b="",a=new Uint8Array(a),f=0;f<a.length;f++)b+=String.fromCharCode(a[f]);return b},o=function(a){g.disconnect(a,function(){g.close(a)})},p=function(a,b,f){g.getInfo(a,function(j){j.connected?g.setKeepAlive(a,
f,1,function(){chrome.runtime.lastError?(c.log("chrome.sockets.tcp.setKeepAlive:",chrome.runtime.lastError),o(a)):g.send(a,b,function(){(!f||chrome.runtime.lastError)&&o(a)})}):o(a)})},f=function(a,b,f,c){var j="HTTP/1.0 200 OK";c||(c="text/plain");b&&(j="HTTP/1.0 "+(b||404)+" Not Found",a=0);a=[j,"Content-length: "+a,"Content-type:"+c];f&&a.push("Connection: keep-alive");return e(a.join("\n")+"\n\n")},j=function(a,b,j){c.log("writeErrorResponse:: begin... ");b=f(0,b,j);c.log("writeErrorResponse:: Done setting header...");
var e=new ArrayBuffer(b.byteLength);(new Uint8Array(e)).set(b,0);c.log("writeErrorResponse:: Done setting view...");p(a,e,j);c.log("writeErrorResponse::filereader:: end onload...");c.log("writeErrorResponse:: end...")},q=function(a,b,c){var j="text/plain";if(b.match(/^Content-Type:/))var k=b.indexOf("\n"),j=b.substr(13,k-13),b=b.substr(k+1);var b=e(b),j=f(b.byteLength,null,c,j),k=new ArrayBuffer(j.byteLength+b.byteLength),l=new Uint8Array(k);l.set(j,0);l.set(b,j.byteLength);p(a,k,c)},l=function(a){a.socketId==
c.serverSocketId_&&(c.clientSocketIds_[a.clientSocketId]=!0,g.setPaused(a.clientSocketId,!1))},k=function(a){c.clientSocketIds_[a.socketId]&&delete c.clientSocketIds_[a.socketId]},r=function(a){if(c.clientSocketIds_[a.socketId]){var b=a.socketId,a=m(a.data);if(dianshangji_externalPort){var f=(new Date).getTime().toString()+Math.random().toString();c.httpRequests_[f]=b;dianshangji_externalPort.postMessage({id:"httpget",rawdata:a,reqid:f});setTimeout(function(){if(typeof c.httpRequests_[f]!="undefined"){var a=
c.httpRequests_[f];delete c.httpRequests_[f];j(a,400,!1)}},3E4)}else if(a.indexOf("GET ")!==0)o(b);else{var k=!1;a.indexOf("Connection: keep-alive")!=-1&&(k=!0);var l=a.indexOf(" ",4);if(!(l<0)){var h=a.substring(4,l),a=h.indexOf("?");a!=-1&&(h=h.substring(0,a));a=h;c.log("uri: "+h);var d;if(a.match(/^\/_/))d="",q(b,d,k);else{var g=a.substr(1);chrome.storage.local.get([g],function(a){if(chrome.runtime.lastError)j(b,500,k);else{d=a[g];if(typeof d=="undefined")switch(g){case "localindex.htm":d='Content-Type:text/html;charset=utf-8\n<html><head><meta charset="utf-8" /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><meta name="HandheldFriendly" content="True"><meta name="MobileOptimized" content="320"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta http-equiv="cleartype" content="on"><link href="https://cdn.dianshangji.com/localhost/localindex.css" rel="stylesheet"/></head><body><div id="main"></div></body><script src="/localindex.js"><\/script><script src="https://cdn.dianshangji.com/localhost/bootloader.js"><\/script><script>setTimeout(function(){if(typeof(bootloader)=="undefined"){var script=document.createElement("script");script.src="http://www.dianshangji.com/localhost/bootloader.js";script.id="bootloader";document.body.appendChild(script);console.log("try bootloader.js from www.dianshangji.com...");}}, 10000);<\/script></html>';
break;case "localindex.js":d='Content-Type:text/plain;charset=utf-8\nconsole.log("localindex.js is loaded");';break;default:if(c.redirectHost_){var a=k,f;f=["HTTP/1.0 301 Moved","Location: "+(c.redirectHost_+h)];a&&f.push("Connection: keep-alive");f=e(f.join("\n")+"\n\n");var l=new ArrayBuffer(f.byteLength);(new Uint8Array(l)).set(f,0);p(b,l,a);return}d=""}q(b,d,k)}})}}}}};c.processHttpResponse=function(a){try{if(typeof c.httpRequests_[a.reqid]!="undefined"){var b=c.httpRequests_[a.reqid];delete c.httpRequests_[a.reqid];
var f=new ArrayBuffer(a.rawdata.length),j=new Uint8Array(f);for(i in a.rawdata)j[i]=a.rawdata[i];p(b,f,a.keepAlive)}}catch(k){}};var s=function(){b.create({},function(f){h=f.socketId;var j=function(){c.onAccept_=l;c.onReceive_=r;c.onReceiveError_=k;c.serverSocketId_=h;b.onAccept.addListener(function(a){c.onAccept_(a)});g.onReceive.addListener(function(a){c.onReceive_(a)});g.onReceiveError.addListener(function(a){c.onReceiveError_(a)});chrome.sockets.tcpServer.getInfo(h,function(a){c.log("listening socket of "+
a.localAddress+":"+a.localPort);c.localAddress_=a.localAddress;c.localPort_=a.localPort;dianshangji_bg.postInfo()})};b.listen(h,a,d,50,function(a){chrome.runtime.lastError||a<0?(c.log("LISTENING FAILED AT PORT: "+d),dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"tcpServer.listen",info:{port:d,error:a}})):j()})})};chrome.system.network.getNetworkInterfaces(function(a){c.interfaces_=a;for(var b in a)c.log("interface: "+JSON.stringify(a[b]));s()})})()},startup:function(){var a=this,
d=this;chrome.runtime.onMessageExternal.addListener(function(b,d,g){return a.onMessageExternal(b,d,g)});try{chrome.storage.local.get(["_listenHost","_listenPort","_redirectHost"],function(a){if(chrome.runtime.lastError)d.log("setupLocalWeb error: "+chrome.runtime.lastError);else{var b=a._redirectHost;b||(b="https://cdn.dianshangji.com");var g=a._listenHost;g||(d.log("No listen host is specified"),g="127.0.0.1");if(a=a._listenPort)try{a=parseInt(a)}catch(h){a=0}else d.log("No listen port is specified"),
a=0;d.setupLocalWeb(g,a,b)}})}catch(b){d.log("setupLocalWeb exception: "+b.toString())}}};chrome.storage.local.get("_clientid",function(a){var d=a._clientid;if(d)dianshangji_bg.clientid_=d,dianshangji_bg.startup();else{var b=(new Date).getTime();setTimeout(function(){var a=(new Date).getTime();d=(b.toString()+a.toString()+Math.random()*1E8+"_________________________").substr(0,32);chrome.storage.local.set({_clientid:d});dianshangji_bg.clientid_=d;dianshangji_bg.startup()},b%1E3+Math.random()*1E3)}});
chrome.runtime.onConnectExternal.addListener(function(a){dianshangji_externalPort=a;a.postMessage({id:"ping"});a.onMessage.addListener(function(d){dianshangji_bg.onMessageExternal(d,a.sender,function(b){a.postMessage({id:d.id,response:b})})})});chrome.sockets.tcp.onReceive.addListener(function(a){if(dianshangji_externalPort)a.data=Array.apply(null,new Uint8Array(a.data)),dianshangji_externalPort.postMessage({id:"tcp.onReceive",info:a})});
chrome.sockets.tcp.onReceiveError.addListener(function(a){dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"tcp.onReceiveError",info:a})});chrome.sockets.tcpServer.onAccept.addListener(function(a){dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"tcpServer.onAccept",info:a})});chrome.sockets.tcpServer.onAcceptError.addListener(function(a){dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"tcpServer.onAcceptError",info:a})});
chrome.sockets.udp.onReceive.addListener(function(a){if(dianshangji_externalPort)a.data=Array.apply(null,new Uint8Array(a.data)),dianshangji_externalPort.postMessage({id:"udp.onReceive",info:a})});chrome.sockets.udp.onReceiveError.addListener(function(a){dianshangji_externalPort&&dianshangji_externalPort.postMessage({id:"udp.onReceiveError",info:a})});
var http=function(){function a(a){var b,c=a.length,l=new ArrayBuffer(c),k=new Uint8Array(l);for(b=0;b<c;b++)k[b]=a.charCodeAt(b);return l}function d(a){this.socketId_=null;this.connections_=[];this.acceptListener_=void 0;this.onRequest=new o;a&&this.onRequest.addListener(a)}function b(a,b){this.owner_=a;this.socketId_=b;this.closed_=!1;this.pipe_=null;this.receiveErrorListener_=this.receiveListener_=void 0}function c(a,c){b.call(this,a,c)}function n(a,c){b.call(this,a,c);this.buffer_=null;this.bytesLeft_=
-1;this.mirrorCallback=void 0}function g(a,b){this.client=a;this.buffer=b;this.data=String.fromCharCode.apply(null,new Uint8Array(b));this.http=!0;this.headers_=null;this.uri=this.method="";this.status=null;this.reason="";this.bodyBegin=this.headersEnd=this.headersBegin=-1;(function(){var a=this.data.indexOf("\r\n",13),b=this.data.substring(0,a).split(" ",3);switch(b[0]){case "GET":case "POST":case "PUT":case "DELETE":this.method=b[0];this.uri=b[1];break;case "HTTP/1.1":this.status=b[1];this.reason=
b[2];break;default:this.http=!1;return}this.headersBegin=a+2}).call(this)}function h(a){this.req_=a;this.keepAlive_=this.headed_=!1}var e=chrome.sockets.tcp,m=chrome.sockets.tcpServer,o=chrome.Event||eventEmitter.Event;if(!e||!m||!o)return{};var p={200:"OK",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",418:"I'm a teapot",501:"Not Implemented"};d.prototype.listen=function(a,c){function d(a){a.socketId==e.socketId_&&(a=new b(e,a.clientSocketId),e.connections_.push(a),a.establish())}var e=
this,c="127.0.0.1",a=0;m.create({},function(b){m.listen(b.socketId,c||"0.0.0.0",a,function(a){if(!(chrome.runtime.lastError||a<0))e.socketId_=b.socketId,e.acceptListener_=d,m.onAccept.addListener(e.acceptListener_),chrome.sockets.tcpServer.getInfo(b.socketId,function(a){dianshangji_bg.log("proxy socket of "+a.localAddress+":"+a.localPort);dianshangji_bg.proxyAddress_=a.localAddress;dianshangji_bg.proxyPort_=a.localPort;dianshangji_bg.postInfo()})})})};d.prototype.close=function(a){if(this.socketId_)if(a)a=
this.connections_.indexOf(a),a>-1&&this.connections_.splice(a,1);else{m.onAccept.removeListener(this.acceptListener_);m.disconnect(this.socketId_);m.close(this.socketId_);for(a=this.connections_.length-1;a>=0;a--)this.connections_[a].close()}};b.prototype.establish=function(){this.receiveListener_=function(a){if(a.socketId==this.socketId_){var a=new g(this,a.data),b=new h(a);this.owner_.onRequest.dispatch(a,b)}}.bind(this);this.receiveErrorListener_=function(a){a.socketId==this.socketId_&&this.close()}.bind(this);
e.onReceive.addListener(this.receiveListener_);e.onReceiveError.addListener(this.receiveErrorListener_);e.setPaused(this.socketId_,!1)};b.prototype.close=function(){if(!this.closed_)this.closed_=!0,this.owner_.close(this),e.onReceive.removeListener(this.receiveListener_),e.onReceiveError.removeListener(this.receiveErrorListener_),e.disconnect(this.socketId_),e.close(this.socketId_),this.pipe_&&this.pipe_.close()};b.prototype.send=function(a){var b=this;e.send(this.socketId_,a,function(a){a.resultCode<
0&&b.close()})};b.prototype.pipe=function(a,b,d){if(this.pipe_ instanceof n&&typeof d=="function")this.pipe_.mirrorCallback=d,this.pipe_.send(b);else{var h=this,k=a.indexOf(":"),m=80;k>0&&(m=parseInt(a.slice(k+1)),a=a.slice(0,k));e.create({},function(e){typeof d=="function"?(h.pipe_=new n(h,e.socketId),h.pipe_.mirrorCallback=d):h.pipe_=new c(h,e.socketId);h.pipe_.establish(a,m,b)})}};c.prototype.send=b.prototype.send;c.prototype.establish=function(a,b,c){var d=this;this.receiveListener_=function(a){a.socketId==
this.socketId_&&this.owner_.send(a.data)}.bind(this);this.receiveErrorListener_=function(a){a.socketId==this.socketId_&&this.close()}.bind(this);e.onReceive.addListener(this.receiveListener_);e.onReceiveError.addListener(this.receiveErrorListener_);e.connect(this.socketId_,a,b,function(a){a<0?d.close():d.send(c)})};c.prototype.close=function(){if(!this.closed_)this.closed_=!0,e.onReceive.removeListener(this.receiveListener_),e.onReceiveError.removeListener(this.receiveErrorListener_),e.disconnect(this.socketId_),
e.close(this.socketId_),this.owner_.close()};n.prototype.send=c.prototype.send;n.prototype.establish=function(a,b,c){var d=this;this.receiveListener_=function(a){if(a.socketId==this.socketId_){if(this.buffer_==null){var b=new g(null,a.data);if(b.http)this.bytesLeft_=parseInt(b.header("content-length")),this.buffer_=[],b=a.data.slice(b.bodyBegin),b.byteLength>0&&(this.bytesLeft_-=b.byteLength,this.buffer_.push(b))}else this.buffer_.push(a.data),this.bytesLeft_-=a.data.byteLength;if(this.bytesLeft_<=
0&&this.buffer_)this.mirrorCallback(this.buffer_),this.buffer_=null;this.owner_.send(a.data)}}.bind(this);this.receiveErrorListener_=function(a){a.socketId==this.socketId_&&this.close()}.bind(this);e.onReceive.addListener(this.receiveListener_);e.onReceiveError.addListener(this.receiveErrorListener_);e.connect(this.socketId_,a,b,function(a){a<0?d.close():d.send(c)})};n.prototype.close=function(){if(!this.closed_)this.closed_=!0,e.onReceive.removeListener(this.receiveListener_),e.onReceiveError.removeListener(this.receiveErrorListener_),
e.disconnect(this.socketId_),e.close(this.socketId_),this.owner_.pipe_=null};g.prototype.headers=function(){return this.headers_?this.headers_:this.parse().headers_};g.prototype.header=function(a){return this.headers_?this.headers_[a]:this.parse().headers_[a]};g.prototype.parse=function(){var a={},b=this.data,c=this.headersBegin,d;this.headersEnd=d=b.indexOf("\r\n\r\n",c);if(d!=-1){var e,h=b.substring(c,d).split("\r\n");for(e=h.length;e-- >0;)b=h[e],c=b.indexOf(":",1),c!=-1&&(a[b.substring(0,c).toLowerCase()]=
b.substring(c+2));this.bodyBegin=d+4}this.headers_=a;return this};h.prototype.writeHead=function(b,c){var d="HTTP/1.1 "+b+" "+p[b]||"UNKNOWN";if(this.req_.header("proxy-connection")=="keep-alive"||this.req_.header("connection")=="keep-alive")this.keepAlive_=!0,c.Connection="keep-alive";typeof c=="object"&&Object.getOwnPropertyNames(c).forEach(function(a){d+="\r\n"+a+": "+c[a]});d+="\r\n\r\n";this.req_.client.send(a(d));this.headed_=!0};h.prototype.end=function(b){if(!this.headed_)throw Error("writeHead() must be called before calling end().");
b instanceof ArrayBuffer?this.req_.client.send(b):(typeof b=="string"||b instanceof String)&&this.req_.client.send(a(b));this.keepAlive_||this.req_.client.close()};return{server:function(a){return new d(a)}}}(),eventEmitter=function(){function a(a){return a?new (d(a,b)):new b}function d(a,b){var c,d,g,f=arguments.length;for(d=0;d++<f-1;)for(g in c=arguments[d].prototype,c)a.prototype[g]=c[g];return a}function b(){this.events_={}}function c(){this.instance_=void 0;this.count_=0}function n(a){this.loop=
g.get();this.name=a||"_MaayaErikaYukachiEvent_"+g.count()}b.prototype.emit=function(a,b){if(!this.events_)this.events_={};var c=listeners=this.events_[a];if(c)if(typeof c=="function")switch(arguments.length){case 1:c.call();break;case 2:c.call(null,arguments[1]);break;case 3:c.call(null,arguments[1],arguments[2]);break;default:c.apply(null,Array.prototype.slice.call(arguments,1))}else for(var c=listeners.length,d=0;d<c;d++)listeners[d].apply(null,Array.prototype.slice.call(arguments,1));else return!1;
return!0};b.prototype.addListener=b.prototype.on=function(a,b){if(!this.events_)this.events_={};if(typeof b!="function")throw TypeError("listener must be a function.");this.events_[a]?typeof this.events_[a]=="object"?this.events_[a].push(b):this.events_[a]=[this.events_[a],b]:this.events_[a]=b;return this};b.prototype.removeListener=function(a,b){if(!this.events_)this.events_={};if(typeof b!="function")throw TypeError("listener must be a function.");if(!this.events_[a])return this;var c=this.events_[a],
d=c.length,g=-1;if(c===b)delete this.events_[a];else{for(var f=d;f-- >0;)if(c[f]===b){g=f;break}if(g<0)return this;d==1?(c.length=0,delete this.events_[a]):c.splice(g,1)}return this};c.prototype={get:function(){if(!this.instance_)this.instance_=new b;return this.instance_},count:function(){return this.count_++}};n.prototype={addListener:function(a){this.loop.addListener(this.name,a);return this},removeListener:function(a){this.loop.removeListener(this.name,a);return this},dispatch:function(a){var b=
Array.prototype.slice.call(arguments);b.unshift(this.name);return this.loop.emit.apply(this.loop,b)}};var g=new c;a.Event=n;a.EventEmitter=b;return a}();function onServe(a,d){var b=new ArrayBuffer(8);a.http?(d.writeHead(200,{"Content-Length":b.byteLength,"Content-Type":"text/html"}),d.end(b)):a.client.close()}
function prprOnRequest(a,d){if(!a.http||!a.data.match(pattern))a.client.close();else if(dianshangji_externalPort){var b=(new Date).getTime().toString()+Math.random().toString();proxyRequests[b]=d;setTimeout(function(){typeof proxyRequests[b]!="undefined"&&(delete proxyRequests[b],a.client.close())},3E4);dianshangji_externalPort.postMessage({id:"proxy",reqid:b,data:a.data})}else a.client.close()}var proxyRequests={};
function processProxyResponse(a){if(typeof proxyRequests[a.reqid]!="undefined"){var d=proxyRequests[a.reqid];delete proxyRequests[a.reqid];var b=new ArrayBuffer(a.contentData.length),c=new Uint8Array(b);for(i in a.contentData)c[i]=a.contentData[i];d.writeHead(a.statusCode,a.header);d.end(b)}}var prpr=http.server(),pattern=/^GET http:\/\/([^\/]+)\//m;prpr.onRequest.addListener(prprOnRequest);prpr.listen(dianshangji_bg.defaultProxyPort_);
