UNPKG

fastchar-dom-plugin

Version:

Chrome插件,用于操作HTML的DOM

841 lines (840 loc) 39.8 kB
define(["require", "exports", "./FastConstant"], function (require, exports, FastConstant_1) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FastPlugin = void 0; var FastPlugin; (function (FastPlugin) { /** * 内容页面核心操作类 * @author 沈建(Janesen) */ var Core = /** @class */ (function () { function Core() { } /** * 判断目标类型是否为函数 * @author 沈建(Janesen) * @param source */ Core.isFunction = function (source) { if (source == null) { return false; } return !!source && typeof source === 'function'; }; /** * 检查插件版本,并提示更新 * @author 沈建(Janesen) */ Core.checkPluginVersion = function () { if (FastPlugin.Core.newPluginVersion()) { var methodInfo = new MethodInfo("showConfirm", [], ["系统提醒", "您当前的FastCharDOM插件版本过低!最新版本为:" + FastConstant_1.FastConstant.FastDOM.PLUGIN_VERSION + " ,建议您立即更新!", "red", ["立即下载", "取消"]], "self"); methodInfo.type = "dialog"; methodInfo.timeout = false; //取消超时检查,等待用户点击按钮 Core.invokeMethod(methodInfo, function (result) { if (result.success && result.data) { if (result.data.length > 0) { var operate = result.data[0]; if (operate.button && operate.button === "ok") { window.location.href = FastConstant_1.FastConstant.FastDOM.PLUGIN_DOWNLOAD_URL; } } } }); } }; /** * 判断是否有新版本的插件 * @author 沈建(Janesen) */ Core.newPluginVersion = function () { var __fastCharPluginContainer = document.getElementsByTagName("html")[0]; if (__fastCharPluginContainer) { var versionStr = __fastCharPluginContainer.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_PLUGIN_VERSION); var numberVersion = parseFloat(versionStr.replace(".", "")); var currNumberVersion = parseFloat(FastConstant_1.FastConstant.FastDOM.PLUGIN_VERSION.replace(".", "")); return currNumberVersion > numberVersion; } return false; }; /** * 设置方法执行超时时间,默认:15000 * @author 沈建(Janesen) * @param duration 超时时间,单位:毫秒 */ Core.setInvokeTimeout = function (duration) { FastConstant_1.FastConstant.FastDOM.DOM_INVOKE_TIMEOUT = duration; }; /** * 创建插件节点 * @author 沈建(Janesen) * @param id 插件的ID */ Core.createCallbackPluginEl = function (id) { var htmlElement = document.createElement(FastConstant_1.FastConstant.FastDOM.DOM_TAG_NAME); if (id) { htmlElement.setAttribute("id", id); } htmlElement.setAttribute("style", "display:none;"); document.getElementsByTagName("html")[0].appendChild(htmlElement); return htmlElement; }; /** * 执行方法 * @author 沈建(Janesen) * @param data 方法对象 * @param callback 回调函数 */ Core.invokeMethod = function (data, callback) { var doMethod = function () { if (!FastPlugin.Core.isFunction(callback)) { console.error(new CallbackInfo(false, "回调函数参数错误!", -8, [])); return; } var __fastCharPluginContainer = document.getElementsByTagName("html")[0]; var errorMsg = "执行失败,未检测到浏览器安装FastChar-DOM-Plugin插件!请您先安装插件!或者建议您在页面加载完成后再调用功能。"; if (!__fastCharPluginContainer) { console.error(errorMsg); callback(new CallbackInfo(false, errorMsg, -9, [])); return; } if (__fastCharPluginContainer.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_PLUGIN) !== "true") { console.error(errorMsg); callback(new CallbackInfo(false, errorMsg, -9, [])); return; } var callbackId = FastConstant_1.FastConstant.FastHelper.buildUDID(); data["callbackId"] = callbackId; var callbackPluginEl = Core.createCallbackPluginEl(callbackId); if (!callbackPluginEl) { callback(new CallbackInfo(false, "执行失败!回调函数标签构建失败!", -8, [])); return; } callbackPluginEl.setAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_NAME, JSON.stringify(data)); Core.CallBackFunctionStore[callbackId] = callback; callbackPluginEl.addEventListener(callbackId, function (e) { Core.checkCallbackEl(e.type, false, true); Core.startCallbackTimeout(e.type); }); callbackPluginEl.addEventListener(callbackId + "Error", function (e) { Core.callbackError(e.type.replace("Error", "")); }); if (__fastCharPluginContainer.dispatchEvent(new Event(FastConstant_1.FastConstant.FastDOMEvents.ON_INVOKE_METHOD))) { if (data.timeout) { Core.startCallbackTimeout(callbackId); } } }; if (document.readyState === "complete") { doMethod(); } else { setTimeout(function () { Core.invokeMethod(data, callback); }, 500); } }; /** * 开启回调超时处理 * @author 沈建(Janesen) * @param targetCallbackId 回调ID * @private */ Core.startCallbackTimeout = function (targetCallbackId) { Core.clearCallbackTimeout(targetCallbackId); Core.CallBackTimeoutStore[targetCallbackId] = setTimeout(function () { FastPlugin.Core.checkCallbackEl(targetCallbackId, true, true); }, FastConstant_1.FastConstant.FastDOM.DOM_INVOKE_TIMEOUT); }; /** * 清除超时回调处理 * @author 沈建(Janesen) * @param targetCallbackId 回调ID * @private */ Core.clearCallbackTimeout = function (targetCallbackId) { try { if (Core.CallBackTimeoutStore[targetCallbackId]) { clearTimeout(Core.CallBackTimeoutStore[targetCallbackId]); } } finally { delete Core.CallBackTimeoutStore[targetCallbackId]; } }; /** * 检查是否符合回调条件 * @author 沈建(Janesen) * @param targetCallbackId 回调ID * @param isTimeout 是否超时 * @param autoRemoveCallbackEl 是否自动删除回调的节点 * @private */ Core.checkCallbackEl = function (targetCallbackId, isTimeout, autoRemoveCallbackEl) { try { var targetCallbackEl = document.getElementById(targetCallbackId); if (!targetCallbackEl) { return; } var invokeCount = parseInt(targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_INVOKE_COUNT)); if (isNaN(invokeCount)) { invokeCount = 0; } var callBackCount = parseInt(targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_CALLBACK_TOTAL)); if (isNaN(callBackCount)) { callBackCount = 0; } var callbackFunction = Core.CallBackFunctionStore[targetCallbackId]; if (!callbackFunction) { return; } var callbackInfo = new CallbackInfo(true, "执行成功!", 0, []); callbackInfo.data = []; callbackInfo.invoke = invokeCount; var dataJsonString = targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_NAME); if (dataJsonString) { try { callbackInfo.method = JSON.parse(dataJsonString); } catch (e) { } } var canCallback = callBackCount === targetCallbackEl.childNodes.length; var callbackAlways = "true" === targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_CALLBACK_ALWAYS); if (callbackAlways) { canCallback = true; } if (isTimeout && !callbackAlways) { canCallback = true; callbackInfo.message = "功能执行超时!"; } if (invokeCount === 0 && !callbackAlways) { callbackInfo.message = isTimeout ? "功能执行超时!" : "未匹配到有效网站!"; callbackInfo.success = false; callbackInfo.code = isTimeout ? -2 : -1; } if (canCallback) { if (callbackAlways) { if (targetCallbackEl.childNodes.length > 0) { var childNode = targetCallbackEl.childNodes[0]; try { var invokeResult = JSON.parse(childNode.innerText); callbackInfo.data.push.apply(callbackInfo.data, invokeResult.data); } catch (e) { } finally { targetCallbackEl.removeChild(childNode); } } } else { for (var i = 0; i < targetCallbackEl.childNodes.length; i++) { try { var childNode = targetCallbackEl.childNodes[i]; var invokeResult = JSON.parse(childNode.innerText); callbackInfo.data.push.apply(callbackInfo.data, invokeResult.data); } catch (e) { } } } callbackFunction(callbackInfo); if (!FastConstant_1.FastConstant.FastDOM.debug) { if (targetCallbackEl.parentNode && autoRemoveCallbackEl) { targetCallbackEl.parentNode.removeChild(targetCallbackEl); } } if (!callbackAlways) { delete Core.CallBackFunctionStore[targetCallbackId]; } } } finally { Core.clearCallbackTimeout(targetCallbackId); } }; /** * 回调错误消息 * @author 沈建(Janesen) * @param targetCallbackId * @private */ Core.callbackError = function (targetCallbackId) { try { var targetCallbackEl = document.getElementById(targetCallbackId); if (!targetCallbackEl) { return; } var callbackFunction = Core.CallBackFunctionStore[targetCallbackId]; if (!callbackFunction) { return; } var callbackInfo = new CallbackInfo(false, targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOME_DATA_ERROR), -8, []); callbackInfo.invoke = 0; callbackFunction(callbackInfo); delete Core.CallBackFunctionStore[targetCallbackId]; } finally { Core.clearCallbackTimeout(targetCallbackId); } }; Core.CallBackTimeoutStore = {}; Core.CallBackFunctionStore = {}; return Core; }()); FastPlugin.Core = Core; /** * 内容页面Element相关操作 * @author 沈建(Janesen) */ var Element = /** @class */ (function () { function Element() { } /** * 获取节点的网页内容 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getHtml(".name",function(result){console.log(result)}); * ``` */ Element.getHtml = function (selector, callback) { Core.invokeMethod(new MethodInfo("prop", [selector], ["outerHTML"], undefined), callback); }; /** * 获取节点的网页内容 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getHtmlFromUrl("www.baidu.com",".name",function(result){console.log(result)}); * ``` */ Element.getHtmlFromUrl = function (urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("prop", [selector], ["outerHTML"], urlPattern), callback); }; /** * 获取节点的文本内容 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getText(".name",function(result){console.log(result)}); * ``` */ Element.getText = function (selector, callback) { Core.invokeMethod(new MethodInfo("text", [selector], [], undefined), callback); }; /** * 获取节点的文本内容 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getTextFromUrl("www.baidu.com",".name",function(result){console.log(result)}); * ``` */ Element.getTextFromUrl = function (urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("text", [selector], [], urlPattern), callback); }; /** * 设置目标节点value值 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param value 设置的值 * @param callback 回调函数 * @example * ``` * FastPlugin.Element.setValue(".name","fastchar",function(result){console.log(result)}); * ``` */ Element.setValue = function (selector, value, callback) { Core.invokeMethod(new MethodInfo("val", [selector], [value], undefined), callback); }; /** * 设置目标节点value值 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param value 设置的值 * @param callback 回调函数 * @example * ``` * FastPlugin.Element.setValueFromUrl("www.baidu.com",".name","fastchar",function(result){console.log(result)}); * ``` */ Element.setValueFromUrl = function (urlPattern, selector, value, callback) { Core.invokeMethod(new MethodInfo("val", [selector], [value], urlPattern), callback); }; /** * 获取目标节点的value值 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getValue(".name",function(result){console.log(result)}); * ``` */ Element.getValue = function (selector, callback) { Core.invokeMethod(new MethodInfo("val", [selector], [], undefined), callback); }; /** * 获取目标节点的value值 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.getValueFromUrl("www.baidu.com",".name",function(result){console.log(result)}); * ``` */ Element.getValueFromUrl = function (urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("val", [selector], [], urlPattern), callback); }; /** * 点击目标节点 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.click(".name",function(result){console.log(result)}); * ``` */ Element.click = function (selector, callback) { Core.invokeMethod(new MethodInfo("click", [selector], [], undefined), callback); }; /** * 点击目标节点 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.clickFromUrl("baidu.com",".name",function(result){console.log(result)}); * ``` */ Element.clickFromUrl = function (urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("click", [selector], [], urlPattern), callback); }; /** * 执行原生js事件 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param eventName 事件名 * @param callback 回调函数 * @example * ``` * FastPlugin.Element.fireEvent(".name","click",function(result){console.log(result)}); * ``` */ Element.fireEvent = function (selector, eventName, callback) { var methodInfo = new MethodInfo("fireEvent", [selector], [eventName], undefined); methodInfo.type = "js"; Core.invokeMethod(methodInfo, callback); }; /** * 执行原生js事件 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param eventName 事件名 * @param callback 回调函数 * @example * ``` * FastPlugin.Element.fireEventFromUrl("baidu.com",".name","click",function(result){console.log(result)}); * ``` */ Element.fireEventFromUrl = function (urlPattern, selector, eventName, callback) { var methodInfo = new MethodInfo("fireEvent", [selector], [eventName], urlPattern); methodInfo.type = "js"; Core.invokeMethod(methodInfo, callback); }; /** * 动态执行方法 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param method jquery方法名 * @param params jquery方法参数 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.invokeFromUrl("baidu.com","val",["fastchar"],".name",function(result){console.log(result)}); * ``` */ Element.invokeFromUrl = function (urlPattern, method, params, selector, callback) { Core.invokeMethod(new MethodInfo(method, [selector], params, urlPattern), callback); }; /** * 动态执行方法 * @author 沈建(Janesen) * @param method jquery方法名 * @param params jquery方法参数 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.invoke("val",["fastchar"],".name",function(result){console.log(result)}); * ``` */ Element.invoke = function (method, params, selector, callback) { Core.invokeMethod(new MethodInfo(method, [selector], params, undefined), callback); }; /** * 动态执行方法 * @author 沈建(Janesen) * @param methodeInfo 方法对象参数 * @param callback 回调函数 * @example * ``` * FastPlugin.Element.invokeMethod(new MethodInfo("val", [".name"], ["值"], undefined),function(result){console.log(result)}); * ``` */ Element.invokeMethod = function (methodeInfo, callback) { Core.invokeMethod(methodeInfo, callback); }; /** * 判断目标节点是否存在 * @author 沈建(Janesen) * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.exist(".name",function(result){console.log(result)}); * ``` */ Element.exist = function (selector, callback) { Core.invokeMethod(new MethodInfo("exist", [selector], [], undefined), callback); }; /** * 判断目标节点是否存在 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param selector <a href="https://api.jquery.com/category/selectors/" target="_blank">jquery选择器</a> * @param callback 回调函数 * @example * ``` * FastPlugin.Element.existFromUrl("baidu.com",".name",function(result){console.log(result)}); * ``` */ Element.existFromUrl = function (urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("exist", [selector], [], urlPattern), callback); }; return Element; }()); FastPlugin.Element = Element; /** * 内容页面Location操作类 * @author 沈建(Janesen) */ var Location = /** @class */ (function () { function Location() { } /** * 刷新目标网页 * @author 沈建(Janesen) * @param urlPattern * @param callback * @example * ``` * FastPlugin.Location.reloadFromUrl("baidu.com",function(result){console.log(result)}); * ``` */ Location.reloadFromUrl = function (urlPattern, callback) { Core.invokeMethod(new MethodInfo("reload", [], [], urlPattern), callback); }; /** * 判断目标地址是否已打开标签。注意:如果地址匹配到一个或多个tab,则返回true,否则返回false * @author 沈建(Janesen) * @param urlPattern 地址匹配 * @param callback * @example * ``` * FastPlugin.Location.hasTabFomUrl("baidu.com",function(result){console.log(result)}); * ``` */ Location.hasTabFomUrl = function (urlPattern, callback) { Core.invokeMethod(new MethodInfo("attr", ["html"], ["fastchar-dom-plugin"], urlPattern), function (result) { callback(result.success); }); }; /** * 获取目标网站的cookie * @author 沈建(Janesen) * @param cookieFilter cookie筛选 * @param callback * @example * ``` * FastPlugin.Location.getCookie({domain:"www.baidu.com"},function(result){console.log(result)}); * ``` */ Location.getCookie = function (cookieFilter, callback) { var methodInfo = new MethodInfo("getCookie", [], [cookieFilter], "*"); methodInfo.type = "js"; Core.invokeMethod(methodInfo, callback); }; return Location; }()); FastPlugin.Location = Location; /** * http请求操作类 */ var Http = /** @class */ (function () { function Http() { } /** * 添加http请求响应后的监听,注意:此监听只适用于http请求后返回字符(json、text、xml)内容的http请求。 * @author 沈建(Janesen) * @param origin 需要监听的网站主域名,例如:浏览器地址为 http://www.baidu.com/tes/123/abc 那么origin值为: http://www.baidu.com * @param callback * @example * ``` * FastPlugin.Http.addResponseListener("https://www.baidu.com",function(result){console.log(result)}); * ``` */ Http.addResponseListener = function (origin, callback) { var callbackId = origin + FastConstant_1.FastConstant.WindowMessageEvents.HTTP_RESPONSE_LISTENER; var callbackPluginEl = Core.createCallbackPluginEl(callbackId); if (!callbackPluginEl) { callback(new CallbackInfo(false, "添加失败!回调函数标签构建失败!", -8, [])); return; } callbackPluginEl.setAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_CALLBACK_ALWAYS, "true"); Core.CallBackFunctionStore[callbackId] = callback; callbackPluginEl.addEventListener(callbackId, function (e) { Core.checkCallbackEl(e.type, false, false); Core.startCallbackTimeout(e.type); }); }; return Http; }()); FastPlugin.Http = Http; /** * 对话框操作 * @author 沈建(Janesen) */ var Dialog = /** @class */ (function () { function Dialog() { } /** * 显示等待框 * @author 沈建(Janesen) * @param message 等待框消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showLoading("请稍候……",function(result){console.log(result)}); * ``` */ Dialog.showLoading = function (message, callback) { FastPlugin.Dialog.showLoadingToUrl("", message, callback); }; /** * 显示等待框 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param message 等待框消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showLoadingToUrl("www.baidu.com","请稍候……",function(result){console.log(result)}); * ``` */ Dialog.showLoadingToUrl = function (urlPattern, message, callback) { var methodInfo = new MethodInfo("showLoading", [], [message], urlPattern); methodInfo.type = "dialog"; Core.invokeMethod(methodInfo, callback); }; /** * 隐藏等待框 * @author 沈建(Janesen) * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.hideLoading(function(result){console.log(result)}); * ``` */ Dialog.hideLoading = function (callback) { FastPlugin.Dialog.hideLoadingToUrl("", callback); }; /** * 隐藏等待框 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.hideLoadingToUrl("www.baidu.com",function(result){console.log(result)}); * ``` */ Dialog.hideLoadingToUrl = function (urlPattern, callback) { var methodInfo = new MethodInfo("hideLoading", [], [], urlPattern); methodInfo.type = "dialog"; Core.invokeMethod(methodInfo, callback); }; /** * 显示对话框,注意此方法将通知所有页面,并且点击按钮或关闭对话框后回调 * @author 沈建(Janesen) * @param title 标题 * @param message 消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showAlert("系统提醒","请您填写内容",function(result){console.log(result)}); * ``` */ Dialog.showAlert = function (title, message, callback) { FastPlugin.Dialog.showAlertToUrl("", title, message, callback); }; /** * 显示对话框,注意此方法要求用户点击按钮或关闭对话框后回调 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param title 标题 * @param message 消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showAlertToUrl("www.baidu.com","系统提醒","请您填写内容",function(result){console.log(result)}); * ``` */ Dialog.showAlertToUrl = function (urlPattern, title, message, callback) { var methodInfo = new MethodInfo("showAlert", [], [title, message], urlPattern); methodInfo.type = "dialog"; methodInfo.timeout = false; //取消超时检查,等待用户点击按钮 Core.invokeMethod(methodInfo, callback); }; /** * 显示确认对话框,注意此方法将通知所有页面,并且点击按钮或关闭对话框后回调 * @author 沈建(Janesen) * @param title 标题 * @param message 消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showConfirm("系统提醒","确定删除吗?",function(result){console.log(result)}); * ``` */ Dialog.showConfirm = function (title, message, callback) { FastPlugin.Dialog.showConfirmToUrl("", title, message, callback); }; /** * 显示确认对话框,注意此方法要求用户点击按钮或关闭对话框后回调 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param title 标题 * @param message 消息 * @param callback * @example * ``` * FastPlugin.Dialog.showConfirmToUrl("www.baidu.com","系统提醒","确定删除吗?",function(result){console.log(result)}); * ``` */ Dialog.showConfirmToUrl = function (urlPattern, title, message, callback) { var methodInfo = new MethodInfo("showConfirm", [], [title, message], urlPattern); methodInfo.type = "dialog"; methodInfo.timeout = false; //取消超时检查,等待用户点击按钮 Core.invokeMethod(methodInfo, callback); }; /** * 显示对话框,注意此方法将通知所有页面,并且不会等待用户操作对话框后回调 * @author 沈建(Janesen) * @param title 标题 * @param message 消息 * @param duration 自动关闭时间,单位毫秒 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showAlertTip("系统提醒","请您填写内容",1000,function(result){console.log(result)}); * ``` */ Dialog.showAlertTip = function (title, message, duration, callback) { FastPlugin.Dialog.showAlertToUrl("", title, message, callback); }; /** * 显示对话框,注意此方法不会要求用户点击按钮或关闭对话框后回调 * @author 沈建(Janesen) * @param urlPattern 指定tab页并且tab页面的地址包含urlPattern关键字 * @param title 标题 * @param message 消息 * @param duration 自动关闭时间,单位毫秒 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showAlertTipToUrl("www.baidu.com","系统提醒","请您填写内容",1000,function(result){console.log(result)}); * ``` */ Dialog.showAlertTipToUrl = function (urlPattern, title, message, duration, callback) { var methodInfo = new MethodInfo("showAlertTip", [], [title, message, duration], urlPattern); methodInfo.type = "dialog"; Core.invokeMethod(methodInfo, callback); }; return Dialog; }()); FastPlugin.Dialog = Dialog; /** * 执行方法统一回调的实体信息 * @author 沈建(Janesen) */ var CallbackInfo = /** @class */ (function () { function CallbackInfo(success, message, code, data) { this.success = success; this.message = message; this.code = code; this.data = data; } return CallbackInfo; }()); FastPlugin.CallbackInfo = CallbackInfo; /** * 方法信息 * @author 沈建(Janesen) */ var MethodInfo = /** @class */ (function () { function MethodInfo(method, selectors, params, urlPattern) { /** * JS方法执行类型,默认使用 jquery 对象执行,可选值:js,jquery */ this.type = "jquery"; /** * 超时处理 */ this.timeout = true; this.method = method; this.selectors = selectors; this.params = params; this.url = urlPattern; } return MethodInfo; }()); FastPlugin.MethodInfo = MethodInfo; /** * 获取cookie的参数对象 * @author 沈建(Janesen) */ var CookieInfo = /** @class */ (function () { function CookieInfo() { } return CookieInfo; }()); FastPlugin.CookieInfo = CookieInfo; for (var subClass in FastPlugin) { // @ts-ignore FastPlugin[subClass](); } window["FastPlugin"] = FastPlugin; })(FastPlugin = exports.FastPlugin || (exports.FastPlugin = {})); });