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