From d3be7ba71d3aa234f518f6586accbc66678e4a9d Mon Sep 17 00:00:00 2001 From: iFish Date: Sun, 8 Feb 2015 23:31:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E5=90=8C=E6=AD=A5=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- RwTicketAssistantV2/app/background.js | 56 ++++++++++++++++------ RwTicketAssistantV2/app/manifest.json | 2 +- Web12306/CrxHandler.cs | 36 ++++++++++++++ Web12306/Properties/AssemblyInfo.cs | 2 +- Web12306/TrainSuggestion.cs | 15 ++++++ Web12306/Web12306.csproj | 2 +- Web12306/css/index.css | 2 + Web12306/index.html | 22 ++++++--- Web12306/js/boot.js | 11 +---- Web12306/js/otn/trainstationsuggest.js | 8 ++-- Web12306/js/platform/extensionPort.js | 15 ++++++ Web12306/js/ui/chat/roomsession.js | 4 +- Web12306/js/ui/index.js | 11 +---- Web12306/js/ui/ui-autorefresh.js | 2 +- Web12306/js/ui/widget_sell_notification.js | 27 +++++++++-- Web12306/js/utility.js | 16 +++++-- build.cmd | 23 +++++---- 17 files changed, 188 insertions(+), 66 deletions(-) create mode 100644 Web12306/CrxHandler.cs diff --git a/RwTicketAssistantV2/app/background.js b/RwTicketAssistantV2/app/background.js index 175d597..04ffa42 100644 --- a/RwTicketAssistantV2/app/background.js +++ b/RwTicketAssistantV2/app/background.js @@ -730,6 +730,38 @@ window.cbl = function (u, h) { } }; + var ajaxWrapper = function (url, host) { + var def = new $.Deferred(); + + chrome.tabs.httpRequest(url, "User-Agent: MSIE 9.0\r\nHost: " + host, 3000, function (result) { + var resp = null; + try { + resp = JSON.parse(result); + } catch (e) { + + } + if (!resp) { + def.reject(0, 'unknown error.'); + return; + } + var a = resp[0]; + var b = resp[1]; + var c = resp[2]; + if (!a) { + if (b === 10001) { + //timeout + def.reject(0, 'timeout'); + } else { + def.reject(b, c); + } + } else { + def.resolve(c, b); + } + }); + + return def.promise(); + }; + var testServer = function (server, callback) { server = server[0]; server.host = server.host || "kyfw.12306.cn"; @@ -737,15 +769,8 @@ window.cbl = function (u, h) { var url = "https://" + server.ip + "/otn/"; var time = new Date(); - $.ajax(url, { - timeout: 4000, - method: "GET", - headers: { - "Host": server.host - }, - dataType: "text" - }).done(function (text) { - if (text.indexOf("客运服务") !== -1) + ajaxWrapper(url, server.host).done(function (text) { + if (!text || text.indexOf("客运服务") !== -1) server.speed = new Date() - time; else { server.speed = -2; @@ -972,12 +997,7 @@ window.cbl = function (u, h) { return; } //测试是否有代理服务器 - $.ajax("https://" + localDns['kyfw.12306.cn'][0] + "/otn/", { - method: "GET", - headers: { - Host: "kyfw.12306.cn" - } - }).done(function () { + ajaxWrapper("https://" + localDns['kyfw.12306.cn'][0] + "/otn/", "kyfw.12306.cn").done(function () { checkAndStart(); }).fail(function () { valid = -1; @@ -1339,6 +1359,7 @@ window.cbl = function (u, h) { var socket = null; var that = this; var heratBeatTimer = null; + var roomId; var sendHeartBeat = function () { if (socket && socket.readyState === 1) { @@ -1348,6 +1369,7 @@ window.cbl = function (u, h) { var connect = function (room) { currentRoom = room; var url = currentRoom.url; + roomId = room.id; if (socket !== null && socket.url !== url) disconnect(); @@ -1357,6 +1379,7 @@ window.cbl = function (u, h) { socket.onclose = function () { socket = null; postMessageToPort({ action: "chatRoomDisconnected" }); + $.post("http://12306.liebao.cn/index.php?r=Api/GetRoomOnlineNum", { roomId: roomId }); }; socket.onopen = function () { postMessageToPort({ action: "chatRoomConnected" }); @@ -1364,6 +1387,9 @@ window.cbl = function (u, h) { if (currentRoom.heartbeat && !heratBeatTimer) { heratBeatTimer = setInterval(sendHeartBeat, currentRoom.heartbeat); }; + + //trigger + $.post("http://12306.liebao.cn/index.php?r=Api/GetRoomOnlineNum", { roomId: roomId }); }; socket.onmessage = function (e) { var tmsg = e.data; diff --git a/RwTicketAssistantV2/app/manifest.json b/RwTicketAssistantV2/app/manifest.json index ce1746e..db68bbf 100644 --- a/RwTicketAssistantV2/app/manifest.json +++ b/RwTicketAssistantV2/app/manifest.json @@ -56,7 +56,7 @@ "description": "12306订票助手 v6: 帮您订票的小助手 by 木鱼,全力为您的车票购买献计献策!", "key": "7k6gnXVACvUPU2DfslJgSrWJTHqIg5uwd+Kgl/5zSg==", "name": "12306订票助手V6/猎豹抢票党", - "version": "6.3.0", + "version": "7.0.0", "manifest_version": 2, "icons": { "16": "icons/icon_16.png", diff --git a/Web12306/CrxHandler.cs b/Web12306/CrxHandler.cs new file mode 100644 index 0000000..81101c0 --- /dev/null +++ b/Web12306/CrxHandler.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace Web12306 +{ + public class CrxHandler:IHttpHandler + { + #region Implementation of IHttpHandler + + /// + /// 通过实现 接口的自定义 HttpHandler 启用 HTTP Web 请求的处理。 + /// + /// 对象,它提供对用于为 HTTP 请求提供服务的内部服务器对象(如 Request、Response、Session 和 Server)的引用。 + public void ProcessRequest(HttpContext context) + { + var request = context.Request; + var response = context.Response; + + response.Redirect("http://www.fishlee.net/service/download/383"); + } + + /// + /// 获取一个值,该值指示其他请求是否可以使用 实例。 + /// + /// + /// 如果 实例可再次使用,则为 true;否则为 false。 + /// + public bool IsReusable { + get { return false; } + } + + #endregion + } +} \ No newline at end of file diff --git a/Web12306/Properties/AssemblyInfo.cs b/Web12306/Properties/AssemblyInfo.cs index 97dc5a2..a92f117 100644 --- a/Web12306/Properties/AssemblyInfo.cs +++ b/Web12306/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ using System.Runtime.InteropServices; // // 你可以指定所有值,也可以让修订版本和内部版本号采用默认值, // 方法是按如下所示使用 "*": -[assembly: AssemblyVersion("1.0.14244.60")] +[assembly: AssemblyVersion("1.0.15002.62")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Web12306/TrainSuggestion.cs b/Web12306/TrainSuggestion.cs index 7e7a8f8..198bba7 100644 --- a/Web12306/TrainSuggestion.cs +++ b/Web12306/TrainSuggestion.cs @@ -652,6 +652,12 @@ namespace Web12306 public DateTime Date { get; set; } + [JsonProperty("tt")] + public string[] SelectedTrain { get; set; } + + [JsonProperty("ts")] + public string[] SelectedSeats { get; set; } + public Dictionary Stops { get; set; } /// @@ -665,6 +671,15 @@ namespace Web12306 if (Stops.Values.Any(s => (s.TrainInfo.code == s.TrainInfo.from.code && s.TrainInfo.to.code == s.TrainInfo.end.code) || s.TrainInfo.available < 0)) return true; + //add 2014年9月4日 - 检测非法席别 + if (SelectedSeats == null) + return true; + if (SelectedSeats.Length > 0) + { + if (Stops.Values.Any(s => !SelectedSeats.Any(x => s.TrainInfo.ticketMap.ContainsKey(x[0])))) + return true; + } + return false; } diff --git a/Web12306/Web12306.csproj b/Web12306/Web12306.csproj index d4a8ce7..b6f039c 100644 --- a/Web12306/Web12306.csproj +++ b/Web12306/Web12306.csproj @@ -128,6 +128,7 @@ + Global.asax @@ -165,7 +166,6 @@ - diff --git a/Web12306/css/index.css b/Web12306/css/index.css index 98fb1b3..989095d 100644 --- a/Web12306/css/index.css +++ b/Web12306/css/index.css @@ -103,6 +103,8 @@ #wx_sell_notification p.code span { color: red; + font-weight: bold; + text-transform: uppercase; } #wx_sell_notification span.hand { diff --git a/Web12306/index.html b/Web12306/index.html index e590491..8005ac0 100644 --- a/Web12306/index.html +++ b/Web12306/index.html @@ -436,7 +436,7 @@ 关闭 - 购票提示 + @@ -1112,5 +1112,13 @@ + diff --git a/Web12306/js/boot.js b/Web12306/js/boot.js index 545667e..7a65cf4 100644 --- a/Web12306/js/boot.js +++ b/Web12306/js/boot.js @@ -94,16 +94,7 @@ } }); seajs.config({ - base: basePath, - alias: { - "jquery": "modules/jquery/jquery.js", - "underscore": "modules/underscore/underscore.js" - }, - vars: { - 'locale': 'zh-cn' - }, - charset: "utf-8", - debug: true + base: basePath }); //检测扩展 diff --git a/Web12306/js/otn/trainstationsuggest.js b/Web12306/js/otn/trainstationsuggest.js index e268acc..a9f91b7 100644 --- a/Web12306/js/otn/trainstationsuggest.js +++ b/Web12306/js/otn/trainstationsuggest.js @@ -56,6 +56,8 @@ _w.v = JSON.stringify({ key: "stupid360", from: cp.fromCode, + tt: cp.selectedTrain || [], + ts: cp.selectedSeatType || [], to: cp.toCode, date: cp.depDate, stops: trainStops @@ -179,7 +181,7 @@ this.checkTrainSuggestion = function () { var suggestKey = cp.fromCode + cp.toCode + ((cp.selectedTrain || []).join("|")) + ((cp.selectedSeatType || []).join("|")); - if (suggestKey === cachedSuggest.key) { + if (suggestKey === cachedSuggest.key && cachedSuggest.data) { if (!lastQuerySuggest || (new Date() - lastQuerySuggest) > data.suggestRefreshInterval) { lastQuerySuggest = new Date(); loadTrainTickets(_.clone(cachedSuggest.data)); @@ -201,7 +203,7 @@ //如果设置了席别,并且设置的席别都没有,则不考虑 if (cp.selectedSeatType && cp.selectedSeatType.length) { - if (!cp.selectedSeatType.some(function(x) { return t.tickets[x] || false; })) + if (!cp.selectedSeatType.some(function (x) { return t.ticketMap[x] || false; })) return false; } @@ -210,7 +212,7 @@ if (!alltrains.length) return; //如果没有选择车次并且此时车次数量多于10趟,则不予检测。 - if ((!cp.selectedTrain || !cp.selectedTrain.length) && alltrains.length > 15) + if ((!cp.selectedTrain || !cp.selectedTrain.length) && alltrains.length > 30) return; loadTrainStops(); diff --git a/Web12306/js/platform/extensionPort.js b/Web12306/js/platform/extensionPort.js index 060ebb8..455d12b 100644 --- a/Web12306/js/platform/extensionPort.js +++ b/Web12306/js/platform/extensionPort.js @@ -63,6 +63,21 @@ values: values } }, function () { }); + + //百度统计 + if (window._hmt) { + try { + var data = ""; + if (values) { + data = values.map(function(s) { + return encodeURIComponent(s); + }).join("&"); + } + window._hmt.push(['_trackEvent', '12306', type, data]); + } catch (e) { + + } + } }; window.port = exports; diff --git a/Web12306/js/ui/chat/roomsession.js b/Web12306/js/ui/chat/roomsession.js index 235072d..52e5ee2 100644 --- a/Web12306/js/ui/chat/roomsession.js +++ b/Web12306/js/ui/chat/roomsession.js @@ -145,10 +145,10 @@ that.fireEvent("chatRoomDisconnected"); page.find("button.button-primary").prop("disabled", true); }); - port.on("chatUpdateOnline", function () { + port.on("chatUpdateOnline", function (e, d) { if (!room) return; - room.onlinecount = this.detail.count; + room.onlinecount = d.count; //更新显示 that.refreshOnlineCount(); }); diff --git a/Web12306/js/ui/index.js b/Web12306/js/ui/index.js index d33408d..e833ba9 100644 --- a/Web12306/js/ui/index.js +++ b/Web12306/js/ui/index.js @@ -165,7 +165,7 @@ return; } cnt.find("li:first span:first").html(this.value); - cnt.find("li:last time:last").html(utility.format24hTo12h(stationData.sellTime[v]) || "----"); + cnt.find("li:last time:last").html(utility.format24hTo12h(stationData.sellTime[v]).join("
") || "----"); cnt.show(); }; $("#from_city").change(showSellTime); @@ -222,7 +222,7 @@ cp.depDate, cp.studentTicket + '', (cp.selectedSeatType && cp.selectedSeatType.length) || 0, - (cp.selectedTrain && cp.selectedTrain.length) || 0 + (cp.selectedTrain && cp.selectedTrain.length) || 0, (cp.passengers && cp.passengers.length) || 0, (cp.dateloop && cp.dateloop.length) || 0, cp.hideNoTicket ? 1 : 0, @@ -280,13 +280,6 @@ //服务器加速 require("./ui-dnsspeeding.js"); - setTimeout(function () { - $("#wx_sell_notification").showModalDialog({ - title: "成功订阅提醒", - width: 'auto' - }); - }, 1000); - //$("#passenger_editor").showModalDialog({ // title: "新增联系人", // buttons: [ diff --git a/Web12306/js/ui/ui-autorefresh.js b/Web12306/js/ui/ui-autorefresh.js index 29f4bd5..83286f3 100644 --- a/Web12306/js/ui/ui-autorefresh.js +++ b/Web12306/js/ui/ui-autorefresh.js @@ -169,7 +169,7 @@ cp.depDate, cp.studentTicket + '', (cp.selectedSeatType && cp.selectedSeatType.length) || 0, - (cp.selectedTrain && cp.selectedTrain.length) || 0 + (cp.selectedTrain && cp.selectedTrain.length) || 0, (cp.passengers && cp.passengers.length) || 0, (cp.dateloop && cp.dateloop.length) || 0, cp.hideNoTicket ? 1 : 0, diff --git a/Web12306/js/ui/widget_sell_notification.js b/Web12306/js/ui/widget_sell_notification.js index 1c76d54..768fb0a 100644 --- a/Web12306/js/ui/widget_sell_notification.js +++ b/Web12306/js/ui/widget_sell_notification.js @@ -45,7 +45,7 @@ var times = container.find("time"); times.filter(":eq(0)").html(utility.formatDate(time, "MM月dd日")); times.filter(":eq(1)").html(utility.formatDate(bs, "MM月dd日")); - times.filter(":eq(2)").html(utility.format24hTo12h(sellTimes)); + times.filter(":eq(2)").html(utility.format24hTo12h(sellTimes).join(" / ")); container.find("span:eq(0)").html(cp.fromText + "站"); container[0].dataset.sellday = bs.getTime(); @@ -135,20 +135,31 @@ } var args = [0, 0, 0]; + wxData = { + from: cp.fromCode, + to: cp.toCode, + fromName: cp.fromText, + toName: cp.toText, + date: cp.depDate, + tasks: [] + }; if ($("#selltip_selection :checkbox:eq(2)").is(":checked:visible")) { args[0] = 1; //动车 assignTimeGroup(baseTime.getTime() + 11 * 60 * 60 * 1000, "动车/城铁"); + wxData.tasks.push({ type: 3, time: '11:00' }); } if ($("#selltip_selection :checkbox:eq(1)").is(":checked:visible")) { args[1] = 1; //高铁 assignTimeGroup(baseTime.getTime() + 14 * 60 * 60 * 1000, "高铁"); + wxData.tasks.push({ type: 2, time: '14:00' }); } if ($("#selltip_selection :checkbox:eq(3)").is(":checked:visible")) { args[2] = 1; //普通车次 assignTimeGroup(baseTime.getTime() + sellTime, "普通车次"); + wxData.tasks.push({ type: 1, time: container[0].dataset.timeset }); } port.sendMessage({ action: "setAlarmTask", detail: tasks }); @@ -209,8 +220,18 @@ }); port.track(data.trackTypes.SHOW_NOTIFICATION_SELECT); }; - var showWx = function() { - + var showWx = function () { + $.post("http://12306.liebao.cn/index.php?r=Api/SendDataToKey", { + data: JSON.stringify(wxData) + }).done(function (str) { + if (str.resCode === 0) { + $("#wx_sell_notification .code span").html(str.dataKey); + $("#wx_sell_notification").showModalDialog({ + title: "成功订阅提醒", + width: 'auto' + }); + } + }); }; var init = function () { sessMgr.on("save", function () { diff --git a/Web12306/js/utility.js b/Web12306/js/utility.js index 2ea02c0..2dac11c 100644 --- a/Web12306/js/utility.js +++ b/Web12306/js/utility.js @@ -72,14 +72,20 @@ return time2 - time1; } - exports.format24hTo12h = function (t) { + exports.format24hTo12h = function (str) { /// 将24小时制式时间转换为12小时制式 + if (!str) + return ''; - if (!/0?(\d{1,2}):(\d{1,2})/.exec(t)) - return ""; + var args = str.split('/'); + return args.map(function (t) { + if (!/0?(\d{1,2}):(\d{1,2})/.exec(t)) + return ""; - var h = parseInt(RegExp.$1, 10); - return h < 13 ? "上午" + h + ":" + RegExp.$2 : "下午" + (h - 12) + ":" + RegExp.$2; + var h = parseInt(RegExp.$1, 10); + return h < 13 ? "上午" + h + ":" + RegExp.$2 : "下午" + (h - 12) + ":" + RegExp.$2; + + }); }; exports.selectTrain = function (trainList, trainFilter, seatOrder, seatFirst, count) { var seat, train; diff --git a/build.cmd b/build.cmd index 18a71b1..c6bd66c 100644 --- a/build.cmd +++ b/build.cmd @@ -10,17 +10,24 @@ cd .. copy tools\onInstall.js deploy\air\js\background\onInstall.js /Y "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem" -ren deploy.crx 12306Ʊ(Աר)_ҳ.crx +ren deploy.crx 12306Ʊ(Աר)_B34_UP.crx -copy tools\onInstall_open12306.js deploy\air\js\background\onInstall.js /Y +rem copy tools\onInstall_open12306.js deploy\air\js\background\onInstall.js /Y +rem "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem" +rem ren deploy.crx 12306Ʊ(Աר)_12306.crx + +rem copy tools\onInstall_openWelcome.js deploy\air\js\background\onInstall.js /Y +rem "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem" +rem ren deploy.crx 12306Ʊ(Աר)_򿪻ӭҳ.crx + +tools\SourceFileUtility.exe deploy\manifest.json ", ""infobars""" ", ""experimental""" "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem" -ren deploy.crx 12306Ʊ(Աר)_12306.crx +ren deploy.crx 12306Ʊ(Աר)_B29.crx -copy tools\onInstall_openWelcome.js deploy\air\js\background\onInstall.js /Y -"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "--pack-extension=%~dp0deploy" "--pack-extension-key=%~dp0src_lb.pem" -ren deploy.crx 12306Ʊ(Աר)_򿪻ӭҳ.crx - -tools\SourceFileUtility.exe deploy\manifest.json """infobars"", " "" +tools\SourceFileUtility.exe deploy\manifest.json ", ""experimental""" "" tools\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" ren deploy.crx 12306Ʊ_Chrome.crx + + +rem experimental