扩展版本更新

This commit is contained in:
iFish 2014-12-02 21:13:25 +08:00
parent a772510681
commit 36e4424749
9 changed files with 130 additions and 27 deletions

View File

@ -94,6 +94,9 @@
})();
$(function () {
var enableDirectAccess = false;
var directAccessCounter = 0;
//监听ajax事件
document.addEventListener("ajaxproxy", function (e) {
var detail = e.detail;
@ -125,26 +128,40 @@ $(function () {
if (!data.headers["Fish-Referer"])
data.headers["Fish-Referer"] = null;
if (!enableDirectAccess || data.url.indexOf("leftTicket/query") === -1 || (directAccessCounter++) % 3 === 0) {
$.ajax(data).done(function (result, status, xhr) {
handle.success = true;
handle.status = xhr.status;
handle.statusText = xhr.statusText;
handle.text = xhr.responseText;
handle.model = result;
handle.headers = xhr.getAllResponseHeaders();
$.ajax(data).done(function (result, status, xhr) {
handle.success = true;
handle.status = xhr.status;
handle.statusText = xhr.statusText;
handle.text = xhr.responseText;
handle.model = result;
handle.headers = xhr.getAllResponseHeaders();
notifyAjaxComplete(handle);
}).fail(function (xhr) {
handle.success = false;
handle.status = xhr.status;
handle.statusText = xhr.statusText || "";
handle.text = xhr.responseText || "";
handle.model = null;
handle.headers = xhr.getAllResponseHeaders();
notifyAjaxComplete(handle);
}).fail(function (xhr) {
handle.success = false;
handle.status = xhr.status;
handle.statusText = xhr.statusText || "";
handle.text = xhr.responseText || "";
handle.model = null;
handle.headers = xhr.getAllResponseHeaders();
notifyAjaxComplete(handle);
});
} else {
chrome.runtime.sendMessage({ action: "directAccess", data: data }, function(args) {
(function(success, status, statusText, text, headers, model) {
handle.success = success;
handle.status = status;
handle.statusText = statusText || "";
handle.text = text || "";
handle.model = model;
handle.headers = headers;
notifyAjaxComplete(handle);
});
notifyAjaxComplete(handle);
}).apply(this, args);
});
}
e.preventDefault && e.preventDefault();
e.stopPropagation && e.stopPropagation();
});
@ -205,4 +222,14 @@ $(function () {
document.body.dataset["browserVersion"] = m.bv;
document.dispatchEvent(new CustomEvent("mobileSupportInitialized"));
});
chrome.runtime.sendMessage({ action: "servervalid" }, function (vm) {
console.log("liebao detected: " + vm.valid);
if (!vm.valid)
return;
chrome.runtime.sendMessage({ action: "getServerStatus" }, function (m) {
enableDirectAccess = m.enableDirectAccess;
console.log("direct access: " + enableDirectAccess);
});
});
});

View File

@ -651,6 +651,7 @@ window.cbl = function (u, h) {
(function () {
/// <summary>服务器IP</summary>
var valid = window.external.LieBaoLookupDnsAddress ? 1 : 0;
var enableDirectAccess = typeof (chrome.tabs.httpRequest) === "function";
chrome.runtime.onMessage.addListener(function (m, s, r) {
if (m && m.action === "servervalid")
@ -674,7 +675,8 @@ window.cbl = function (u, h) {
failed: 0,
lastUpdate: null,
validList: [],
status: 0
status: 0,
enableDirectAccess: enableDirectAccess
};
var serverlist = [],
testedServer = [],
@ -1012,6 +1014,7 @@ window.cbl = function (u, h) {
var checkAndStart = function () {
if (localStorage['serverStorage']) {
serverStorage = JSON.parse(localStorage['serverStorage']);
serverStorage.enableDirectAccess = enableDirectAccess;
}
if (!serverStorage.lastUpdate || (new Date().getTime() / 3600000) - new Date(serverStorage.lastUpdate).getTime() / 3600000 >= 12 || serverStorage.validList.length < 5) {
inupdateMode = true;
@ -1055,8 +1058,74 @@ window.cbl = function (u, h) {
entry12306 = true;
}
chrome.runtime.onMessage.addListener(function (m, s, r) {
if (m && m.action === 'triggerUpdate') {
if (!m || !m.action)
return;
if (m.action === 'triggerUpdate') {
triggerUpdate();
} else if (m.action === "directAccess") {
var data = m.data;
var host = /^https?:\/\/([^\/]+)\//.exec(data.url) && RegExp.$1;;
var hostip = null;
var hostindex = 0;
if (enableDirectAccess && host && serverStorage.validList && serverStorage.validList[host] && serverStorage.validList[host].length) {
var hosts = serverStorage.validList[host];
hostindex = Math.floor(Math.random() * hosts.length);
hostip = hosts[hostindex];
data.url = data.url.replace("//" + host, "//" + hostip.ip);
}
if (hostip) {
//build header
var headers = [];
if (data.headers) {
for (var i in data.headers) {
var key = i;
if (key.indexOf("Fish-") === 0)
key = key.substr(5);
headers.push(key + ": " + data.headers[i]);
}
}
headers.push("Host: " + host);
//using direct access
if (data.data) {
data.url += "?" + $.param(data.data);
}
chrome.tabs.httpRequest(
data.url,
headers.join("\r\n"),
20000,
function (response) {
(function (success, status, text, rHeader, base64) {
if (!success || status !== 200) {
//failed.
r([false, status, status, text, rHeader || "", null]);
//block error ip
hostip.failedCount = (hostip.failedCount || 0) + 1;
console.log("bad response for host [" + hostip.ip + "], increase failed counter. current at " + hostip.failedCount);
if (hostip.failedCount > 3) {
//block error ip
serverStorage.validList.splice(hostindex, 1);
console.log("bad response for host [" + hostip.ip + "] failed too many times, removed from validlist.");
localStorage["serverStorage"] = JSON.stringify(serverStorage);
}
} else {
r([true, status, status, text, rHeader || "", JSON.parse(text)]);
}
}).apply(this, JSON.parse(response));
}
);
} else {
//doing a regular access
$.ajax(data).done(function (result, status, xhr) {
r([true, xhr.status, xhr.statusText, xhr.responseText, xhr.getAllResponseHeaders(), result]);
}).fail(function (xhr) {
r([false, xhr.status, xhr.statusText, xhr.responseText, "", null]);
});
}
return true;
}
});
chrome.runtime.onMessageExternal.addListener(function (m, s, r) {

View File

@ -56,7 +56,7 @@
"description": "12306订票助手 v7: 帮您订票的小助手 by 木鱼,全力为您的车票购买献计献策!",
"key": "7k6gnXVACvUPU2DfslJgSrWJTHqIg5uwd+Kgl/5zSg==",
"name": "猎豹抢票党/12306订票助手 V7",
"version": "7.2.1",
"version": "7.3.1",
"manifest_version": 2,
"icons": {
"16": "icons/icon_16.png",

View File

@ -29,7 +29,10 @@ namespace TrainInfomationProviderService
public static void WebLoader()
{
RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt)" }, new[] { "TrainInfomationProviderService.Web" });
if (ConfigurationManager.AppSettings["local_disable_train_provider"] == "1")
return;
RouteTable.Routes.MapRoute("traintransit", "tt/{action}/{id}", new { area = "", controller = "Transit", id = UrlParameter.Optional }, new { action = "(keepalive|ls|ss|tor|dt|ls2)" }, new[] { "TrainInfomationProviderService.Web" });
Task.Run(() =>
{
try

View File

@ -36,7 +36,7 @@ namespace TrainInfomationProviderService.Web.Controllers
if (string.IsNullOrEmpty(data))
return null;
return LogSameStation(Encoding.UTF8.GetString(Convert.FromBase64String(data)));
return LogSameStation(Server.UrlDecode(Encoding.UTF8.GetString(Convert.FromBase64String(data))));
}
[ActionName("ls")]

View File

@ -13,6 +13,8 @@
<add key="12306_trainsuggestion_maxradio" value="0.7" />
<add key="dataStoragePath" value="~/App_Data/12306"/>
<add key="12306_keepaliveurl" value="http://test.fishlee.net/tt/keepalive"/>
<add key="local_disable_train_provider" value="1"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
@ -29,9 +31,9 @@
<add name="TrainSuggestHandler" path="ts" verb="*" type="Web12306.TrainSuggestion" />
<add name="CrxHandler" path="crx" verb="*" type="Web12306.CrxHandler" />
</handlers>
<staticContent>
<mimeMap fileExtension=".crx" mimeType="application/octet-stream" />
</staticContent>
<staticContent>
<mimeMap fileExtension=".crx" mimeType="application/octet-stream" />
</staticContent>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

View File

@ -259,7 +259,7 @@
rptData.push(_.pluck(fromStations, "code"));
if (toStations)
rptData.push(_.pluck(toStations, "code"));
$.post("http://service.fishlee.net/ls.aspx", {
$.post("http://12306.fishlee.net/tt/ls2", {
data: btoa(escape(JSON.stringify(rptData)))
});
};

View File

@ -101,8 +101,9 @@ define(function (require, exports, module) {
var param = requestMap[data.index];
delete requestMap[data.index];
if (data.status === 404) {
if (data.status === 404 && data.url.indexOf("leftTicket") === -1) {
//404是个比较特殊的错误这个错误一般是证书有问题
//但是切CDN也有可能导致这个问题所以忽略查票请求的这个错误
document.dispatchEvent(new CustomEvent("networkOrCertificationError"));
}

View File

@ -25,6 +25,7 @@ BuildTools\SourceFileUtility.exe deploy\manifest.json ".1""," ".0"","
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem"
ren deploy.crx 12306订票助手(猎豹浏览器专版)_B29.crx
BuildTools\SourceFileUtility.exe deploy\manifest.json ", ""experimental""" ""
BuildTools\SourceFileUtility.exe deploy\manifest.json "44/44/update_lb.xml" "44/44/update_chrome.xml"
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem"