1 var $doc=$(document);(function(){var n=!1,t=function(n){var t="";switch(n){case 0:t="<span class='label label-primary'>正常运行中...<\/span>";break;case 1:t="<span class='label label-success'>正在从服务器更新节点列表...<\/span>";break;case 2:t="<span class='label label-primary'>正在对节点测速中...<\/span>";break;case 3:t="<span class='label label-primary'>正在筛选节点...<\/span>"}t&&$("#currentStatus").html(t)},i=function(n){var t=["<tr>"];_.each(n,function(n,i){var r=n.status<0?"danger":n.status?"success":"active",u=n.ip.replace(/\./g,"_");t.push("<td class='"+r+"' id='s_"+u+"'>");t.push(n.ip);t.push("<\/td><td class='"+r+"'>");n.status?t.push(n.status==-1?"连接失败":n.status==-2?"速度过慢":"速度 "+n.speed/1e3+" 秒"):t.push("等待测速...");t.push("<\/td>");i%4==3&&t.push("<\/tr><tr>")});n.length||t.push("<td colspan='8'>当前没有服务器在等待速度测试。<\/td>");t.push("<\/tr>");$("#serverList tr:gt(0)").remove();$("#serverList").append(t.join(""))};$doc.bind("refreshCurrentServer",function(){chrome.runtime.sendMessage({action:"getCurrentServer"},function(n){var t=n["kyfw.12306.cn"];t?$("#currentServerOtn").html("正在使用 <code>"+(t.ip?t.ip:"系统默认服务器")+"<\/code> 延迟 <code>"+(t.speed>0?t.speed+"毫秒":"未知")+"<\/code>"+(t.count>0?" 已过慢或失败 <code>"+t.count+"<\/code> 次":"")):$("#currentServerOtn").html("<em>--状态未知--<\/em>");$("#currentServer").html(n.ip?n.ip:"系统默认服务器");$("#currentServerSpeed").html(n.speed>0?n.speed/1e3+"毫秒":"未知")})});$doc.bind("refreshServerStatus",function(){chrome.runtime.sendMessage({action:"getServerStatus"},function(i){if($("#currentServerStorage").html(["<span class='label label-primary'>总节点数 ",i.count,"<\/span> ","<span class='label label-success'>可用节点数 ",i.valid,"<\/span> ","<span class='label label-danger'>超时节点数 ",i.timeout,"<\/span> ","<span class='label label-default'>无效节点数 ",i.failed,"<\/span> "].join("")),i.status===0){var r=_.map(_.flatten(i.validList),function(n){return"<code>"+n.ip+"<\/code> "});$("#currentServerValidList").html(r.length?r.join(""):"<em>暂无节点<\/em>")}else $("#currentServerValidList").html("<em>节点列表正在更新中....<\/em>");n||(n=!0,(i.status===2||i.status===3)&&$doc.trigger("reloadServer"));t(i.status)})});$doc.bind("reloadServer",function(){chrome.runtime.sendMessage({action:"getServerList"},function(n){i(n)});$doc.trigger("refreshServerStatus")});message.addAction("serverStateChange",function(){t(this.state);(this.state===2||this.state===3)&&$doc.trigger("reloadServer");$doc.trigger("refreshServerStatus");$doc.trigger("refreshCurrentServer")});message.addAction("serverTestResult",function(){var t=this.ip.replace(/\./g,"_"),n=this.status<0?"danger":this.status?"success":"active",i=this.status==-1?"连接失败":this.status==-2?"速度过慢":"速度 "+this.speed/1e3+" 秒";$("#s_"+t).removeClass().addClass(n).next().removeClass().addClass(n).html(i);$doc.trigger("refreshServerStatus")});$doc.trigger("refreshServerStatus");$doc.trigger("refreshCurrentServer")})(),function(){message.sendAction("servervalid",null,function(n){n.valid===0&&($("div.container").hide(),$("#notValid").show());n.valid===-1&&($("div.container").hide(),$("#inProxy").show());n.valid===-2&&($("div.container").hide(),$("#greenMode").show())})}()