From fbbe68c00bd7077b63b2f1ab32d13e72c3895280 Mon Sep 17 00:00:00 2001 From: iFish Date: Tue, 9 Sep 2014 15:56:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=8F=90=E4=BA=A4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E7=9A=84=E8=B7=A8=E5=A4=A9=E6=97=A5=E6=9C=9F=E6=9C=89?= =?UTF-8?q?=E9=94=99=E4=BB=A5=E5=8F=8A=E5=BC=95=E5=AF=BC=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Web12306/js/boot.js | 49 ++++++++++++++++++++------ Web12306/js/otn/queryticket.js | 6 ++-- Web12306/js/ui/extesniondisabled.js | 20 +++++++++++ Web12306/js/ui/widget_message_popup.js | 2 +- 4 files changed, 62 insertions(+), 15 deletions(-) create mode 100644 Web12306/js/ui/extesniondisabled.js diff --git a/Web12306/js/boot.js b/Web12306/js/boot.js index 52e7686..d9bcf79 100644 --- a/Web12306/js/boot.js +++ b/Web12306/js/boot.js @@ -101,6 +101,9 @@ var notInstallExtension = function () { seajs.use("ui/noextension"); }; + var extensionDisabled = function () { + seajs.use("ui/extesniondisabled"); + }; window.targetExtensionId = null; $(function () { //确保内容脚本启动 @@ -115,8 +118,11 @@ }); }); - start.fail(function () { - notInstallExtension(); + start.fail(function (reason) { + if (reason === "disabled") + extensionDisabled(); + else + notInstallExtension(); }); start.always(function () { var page = location.pathname; @@ -150,18 +156,39 @@ //完成! start.resolve(); }; + var timeout = 3000; - if (document.body.dataset["mobileSupportInitialized"]) { - checkExtensionInfo(); - } else { - var timer = setTimeout(function () { - start.reject(); - }, 1500); - document.addEventListener("mobileSupportInitialized", function () { - window.clearTimeout(timer); + var waitForStart = function () { + if (document.body.dataset["mobileSupportInitialized"]) { checkExtensionInfo(); - }); + } else { + var timer = setTimeout(function () { + start.reject(); + }, timeout); + document.addEventListener("mobileSupportInitialized", function () { + window.clearTimeout(timer); + checkExtensionInfo(); + }); + } + }; + + var extJson = null; + if (window.external.GetExtensionInfoListJson && (extJson = window.external.GetExtensionInfoListJson())) { + var ext = _.findWhere(JSON.parse(extJson), { id: "gkbheeokbgmmnbjhhlphckobccejghjn" }); + if (ext) { + if (!ext.enabled) + start.reject("disabled"); + else { + timeout = 10000; + waitForStart(); + } + } else { + waitForStart(); + } + } else { + waitForStart(); } + }); })(window, document); diff --git a/Web12306/js/otn/queryticket.js b/Web12306/js/otn/queryticket.js index e0c6a8a..97fff39 100644 --- a/Web12306/js/otn/queryticket.js +++ b/Web12306/js/otn/queryticket.js @@ -44,7 +44,7 @@ return data; }; - var transferData = function (data, noProcess, noAction) { + var transferData = function (date, data, noProcess, noAction) { var result = data; if (!Array.isArray(result.data) || !result.data.length || !result.data[0].queryLeftNewDTO) { exports.events.fireEvent("requestFailed"); @@ -91,7 +91,7 @@ saleTime: t.queryLeftNewDTO.sale_time, secureStr: t.secretStr, selltime: null, - date: t.queryLeftNewDTO.start_train_date.replace(/(\d{4})(\d{2})(\d{2})/, "$1-$2-$3"), + date: date, limitSellInfo: t.buttonTextInfo && t.buttonTextInfo.indexOf("暂售") != -1 ? t.buttonTextInfo.replace(/<[^>]+>/i, "") : null }; var kp = getTicketInfo(t.queryLeftNewDTO.yp_info); @@ -165,7 +165,7 @@ queryTicketUrl = this.model.c_url; sendQueryRequest(); } else { - var data = transferData(this.model, noProcess, noAction); + var data = transferData(date, this.model, noProcess, noAction); def.resolveWith(data); } }, function () { diff --git a/Web12306/js/ui/extesniondisabled.js b/Web12306/js/ui/extesniondisabled.js new file mode 100644 index 0000000..ffccd3a --- /dev/null +++ b/Web12306/js/ui/extesniondisabled.js @@ -0,0 +1,20 @@ +define(function (require, exports, module) { + require("./widget_modalDialog.js"); + + var btns = [ + { + text: "刷新", + type: "primary", + callback: function () { + self.location.reload(); + return false; + } + } + ]; + + $.showModalDialog("您启用12306订票助手扩展才可以使用极速版订票,当前已禁用。请进入“我的应用”中启用 :-(", { + image: "/images/cat.png", + buttons: btns, + closeOnAction: false + }); +}); diff --git a/Web12306/js/ui/widget_message_popup.js b/Web12306/js/ui/widget_message_popup.js index c376e0b..5716b6c 100644 --- a/Web12306/js/ui/widget_message_popup.js +++ b/Web12306/js/ui/widget_message_popup.js @@ -169,7 +169,7 @@ }); } - $.showModalDialog("您需要安装" + (isLb ? "" : "猎豹浏览器和") + "最新版12306订票助手扩展才可以使用极速版订票。请安装后刷新此页面 :-)", { + $.showModalDialog("您需要安装" + (isLb ? "" : "猎豹浏览器并") + "启用最新版12306订票助手扩展才可以使用极速版订票。请安装后刷新此页面。如果已安装,请检查是否不小心禁用了 :-(", { image: "/images/cat.png", buttons: btns, closeOnAction: false