//12306入口引导脚本 (function (window, document) { var basePath = window.location.protocol + "//" + window.location.host + "/js/"; var pagename = /\/(\w+?)\.html/.exec(location.pathname) && RegExp.$1 || "index"; var loadScript = function (path, callback) { var script = document.createElement("script"); script.src = basePath + path; script.onload = function () { callback(); document.head.removeChild(script); }; document.head.appendChild(script); }; //extend jquery $.fn.extend({ searchDelay: function (opts) { var SearchDelay = function (e, opt) { var __ = this; this.$element = e; this.timer = null; this.opt = $.extend(SearchDelay.defaults, opt); this.$element.keyup(function () { __.reset(); __.timer = setTimeout(function () { __.search.apply(__); }, __.opt.delay); }); }; SearchDelay.defaults = { delay: 300 }; SearchDelay.prototype.search = function () { this.$element.trigger("search", this.$element.val()); }; SearchDelay.prototype.reset = function () { if (this.timer) clearTimeout(this.timer); }; SearchDelay.prototype.cancel = function () { this.reset(); this.$element.val(""); this.search(); }; this.each(function () { var key = "fish.searchdelay"; var $ele = $(this); var target = $ele.data(key); if (!target) { target = new SearchDelay($ele, opts); $ele.data(key, target); } if (typeof (opts) === "string") { target[opts].apply(target, $.makeArray(arguments).slice(1)); } }); return this; } } ); //extend underscore _.mixin({ mapObject: function (array, keySelector) { var obj = {}; _.each(array, function (e) { obj[keySelector(e)] = e; }); return obj; } }); seajs.config({ base: basePath, alias: { "jquery": "modules/jquery/jquery.js", "underscore": "modules/underscore/underscore.js" }, vars: { 'locale': 'zh-cn' }, charset: "utf-8", debug: true }); //检测扩展 var notInstallExtension = function () { //TODO 没有安装扩展的提示 alert("没有检测到安装的订票助手扩展!"); //seajs.use("ui/noextension"); }; var targetExtension = [ "bpbefagpafkfgoihbmcgeileodldkpnf", "gkbheeokbgmmnbjhhlphckobccejghjn" ]; window.targetExtensionId = null; for (var id in targetExtension) { var port = chrome.runtime.connect(targetExtension[id]); try { port.postMessage(""); port.disconnect(); window.targetExtensionId = targetExtension[id]; break; } catch (e) { } } if (!window.targetExtensionId) { notInstallExtension(); } else { //确保内容脚本启动 var start = $.Deferred(); start.done(function () { chrome.runtime.sendMessage(window.targetExtensionId, { action: "getStorage" }, function (m) { window.storage = m.detail; seajs.use("ui/" + pagename); }); }); start.fail(function () { notInstallExtension(); }); if (document.body.dataset["mobileSupportInitialized"]) { start.resolve(); } else { var timer = setTimeout(function () { start.reject(); }, 3000); document.addEventListener("mobileSupportInitialized", function () { window.clearTimeout(timer); start.resolve(); }); } } })(window, document);