UNPKG

fastchar-dom-plugin

Version:

Chrome插件,用于操作HTML的DOM

904 lines (903 loc) 37.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FastPlugin = void 0; /** * 内容页面操作工具类,在内容页面(自己开发的网页)中使用本工具类调用插件的功能方法,进而实现跨域操作其他标签页中的网页DOM结构或iframe中的DOM结构! * @author 沈建(Janesen) */ const FastConstant_1 = require("./FastConstant"); var FastPlugin; (function (FastPlugin) { /** * 内容页面核心操作类 * @author 沈建(Janesen) */ class Core { constructor() { } static CallBackTimeoutStore = {}; static CallBackFunctionStore = {}; /** * 判断目标类型是否为函数 * @author 沈建(Janesen) * @param source */ static isFunction(source) { if (source == null) { return false; } return !!source && typeof source === 'function'; } /** * 检查插件版本,并提示更新 * @author 沈建(Janesen) */ static checkPluginVersion() { if (FastPlugin.Core.newPluginVersion()) { let 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) { let operate = result.data[0]; if (operate.button && operate.button === "ok") { window.location.href = FastConstant_1.FastConstant.FastDOM.PLUGIN_DOWNLOAD_URL; } } } }); } } /** * 判断是否有新版本的插件 * @author 沈建(Janesen) */ static newPluginVersion() { let __fastCharPluginContainer = document.getElementsByTagName("html")[0]; if (__fastCharPluginContainer) { let versionStr = __fastCharPluginContainer.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_PLUGIN_VERSION); let numberVersion = parseFloat(versionStr.replace(".", "")); let currNumberVersion = parseFloat(FastConstant_1.FastConstant.FastDOM.PLUGIN_VERSION.replace(".", "")); return currNumberVersion > numberVersion; } return false; } /** * 设置方法执行超时时间,默认:15000 * @author 沈建(Janesen) * @param duration 超时时间,单位:毫秒 */ static setInvokeTimeout(duration) { FastConstant_1.FastConstant.FastDOM.DOM_INVOKE_TIMEOUT = duration; } /** * 创建插件节点 * @author 沈建(Janesen) * @param id 插件的ID */ static createCallbackPluginEl(id) { let 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 回调函数 */ static invokeMethod(data, callback) { let doMethod = function () { if (!FastPlugin.Core.isFunction(callback)) { console.error(new CallbackInfo(false, "回调函数参数错误!", -8, [])); return; } let __fastCharPluginContainer = document.getElementsByTagName("html")[0]; let 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; } let callbackId = FastConstant_1.FastConstant.FastHelper.buildUDID(); data["callbackId"] = callbackId; let 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 */ static startCallbackTimeout(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 */ static clearCallbackTimeout(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 */ static checkCallbackEl(targetCallbackId, isTimeout, autoRemoveCallbackEl) { try { let targetCallbackEl = document.getElementById(targetCallbackId); if (!targetCallbackEl) { return; } let invokeCount = parseInt(targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_INVOKE_COUNT)); if (isNaN(invokeCount)) { invokeCount = 0; } let callBackCount = parseInt(targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_CALLBACK_TOTAL)); if (isNaN(callBackCount)) { callBackCount = 0; } let callbackFunction = Core.CallBackFunctionStore[targetCallbackId]; if (!callbackFunction) { return; } let callbackInfo = new CallbackInfo(true, "执行成功!", 0, []); callbackInfo.data = []; callbackInfo.invoke = invokeCount; let dataJsonString = targetCallbackEl.getAttribute(FastConstant_1.FastConstant.FastDOM.DOM_DATA_NAME); if (dataJsonString) { try { callbackInfo.method = JSON.parse(dataJsonString); } catch (e) { } } let canCallback = callBackCount === targetCallbackEl.childNodes.length; let 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) { let childNode = targetCallbackEl.childNodes[0]; try { let invokeResult = JSON.parse(childNode.innerText); callbackInfo.data.push.apply(callbackInfo.data, invokeResult.data); } catch (e) { } finally { targetCallbackEl.removeChild(childNode); } } } else { for (let i = 0; i < targetCallbackEl.childNodes.length; i++) { try { let childNode = targetCallbackEl.childNodes[i]; let 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 */ static callbackError(targetCallbackId) { try { let targetCallbackEl = document.getElementById(targetCallbackId); if (!targetCallbackEl) { return; } let callbackFunction = Core.CallBackFunctionStore[targetCallbackId]; if (!callbackFunction) { return; } let 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); } } } FastPlugin.Core = Core; /** * 内容页面Element相关操作 * @author 沈建(Janesen) */ class Element { constructor() { } /** * 获取节点的网页内容 * @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)}); * ``` */ static getHtml(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)}); * ``` */ static getHtmlFromUrl(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)}); * ``` */ static getText(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)}); * ``` */ static getTextFromUrl(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)}); * ``` */ static setValue(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)}); * ``` */ static setValueFromUrl(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)}); * ``` */ static getValue(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)}); * ``` */ static getValueFromUrl(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)}); * ``` */ static click(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)}); * ``` */ static clickFromUrl(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)}); * ``` */ static fireEvent(selector, eventName, callback) { let 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)}); * ``` */ static fireEventFromUrl(urlPattern, selector, eventName, callback) { let 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)}); * ``` */ static invokeFromUrl(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)}); * ``` */ static invoke(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)}); * ``` */ static invokeMethod(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)}); * ``` */ static exist(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)}); * ``` */ static existFromUrl(urlPattern, selector, callback) { Core.invokeMethod(new MethodInfo("exist", [selector], [], urlPattern), callback); } } FastPlugin.Element = Element; /** * 内容页面Location操作类 * @author 沈建(Janesen) */ class Location { constructor() { } /** * 刷新目标网页 * @author 沈建(Janesen) * @param urlPattern * @param callback * @example * ``` * FastPlugin.Location.reloadFromUrl("baidu.com",function(result){console.log(result)}); * ``` */ static reloadFromUrl(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)}); * ``` */ static hasTabFomUrl(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)}); * ``` */ static getCookie(cookieFilter, callback) { let methodInfo = new MethodInfo("getCookie", [], [cookieFilter], "*"); methodInfo.type = "js"; Core.invokeMethod(methodInfo, callback); } } FastPlugin.Location = Location; /** * http请求操作类 */ class 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)}); * ``` */ static addResponseListener(origin, callback) { let callbackId = origin + FastConstant_1.FastConstant.WindowMessageEvents.HTTP_RESPONSE_LISTENER; let 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); }); } } FastPlugin.Http = Http; /** * 对话框操作 * @author 沈建(Janesen) */ class Dialog { constructor() { } /** * 显示等待框 * @author 沈建(Janesen) * @param message 等待框消息 * @param callback 回调函数 * @example * ``` * FastPlugin.Dialog.showLoading("请稍候……",function(result){console.log(result)}); * ``` */ static showLoading(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)}); * ``` */ static showLoadingToUrl(urlPattern, message, callback) { let 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)}); * ``` */ static hideLoading(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)}); * ``` */ static hideLoadingToUrl(urlPattern, callback) { let 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)}); * ``` */ static showAlert(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)}); * ``` */ static showAlertToUrl(urlPattern, title, message, callback) { let 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)}); * ``` */ static showConfirm(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)}); * ``` */ static showConfirmToUrl(urlPattern, title, message, callback) { let 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)}); * ``` */ static showAlertTip(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)}); * ``` */ static showAlertTipToUrl(urlPattern, title, message, duration, callback) { let methodInfo = new MethodInfo("showAlertTip", [], [title, message, duration], urlPattern); methodInfo.type = "dialog"; Core.invokeMethod(methodInfo, callback); } } FastPlugin.Dialog = Dialog; /** * 执行方法统一回调的实体信息 * @author 沈建(Janesen) */ class CallbackInfo { constructor(success, message, code, data) { this.success = success; this.message = message; this.code = code; this.data = data; } /** * 是否执行成功,注意此处成功只能表示页面接受了方法执行,并不代表方法执行成功,方法执行结果查看data属性值 */ success; /** * 执行消息 */ message; /** * 执行结果编号,0:正常执行 -9:插件未安装 -1:未有页面执行 -2 功能执行超时 -8 页面与插件发生错误 */ code; /** * 结果数据 */ data; /** * 执行操作统计 */ invoke; /** * 执行的方法信息 */ method; } FastPlugin.CallbackInfo = CallbackInfo; /** * 方法信息 * @author 沈建(Janesen) */ class MethodInfo { constructor(method, selectors, params, urlPattern) { this.method = method; this.selectors = selectors; this.params = params; this.url = urlPattern; } /** * 方法名称,必须与jquery的方法名一致 */ method; /** * 节点选择器,与jquery规则一致 */ selectors; /** * 方法参数 */ params; /** * 指定匹配的链接地址,当网页地址包含此地址时执行方法 */ url; /** * 回调函数的ID */ callbackId; /** * JS方法执行类型,默认使用 jquery 对象执行,可选值:js,jquery */ type = "jquery"; /** * 超时处理 */ timeout = true; } FastPlugin.MethodInfo = MethodInfo; /** * 获取cookie的参数对象 * @author 沈建(Janesen) */ class CookieInfo { /** * 限定只查找与给定域名或者子域名匹配的cookies。 */ domain; /** * 根据名称过滤cookies。 */ name; /** * 限定只查找与给定URL匹配的cookies。 */ url; /** * cookie的存储id,用于从中检索cookie。默认情况下,当前执行上下文的cookie存储将被使用。 */ storeId; /** * 根据cookie的生命周期是会话的还是持久的进行过滤。 */ session; /** * 限定只查找与给定路径完全一致的cookies。 */ path; /** * 根据cookie的Secure属性进行筛选。 */ secure; } FastPlugin.CookieInfo = CookieInfo; for (let subClass in FastPlugin) { // @ts-ignore FastPlugin[subClass](); } window["FastPlugin"] = FastPlugin; })(FastPlugin = exports.FastPlugin || (exports.FastPlugin = {}));