UNPKG

fastchar-dom-plugin

Version:

Chrome插件,用于操作HTML的DOM

1 lines 15 kB
(()=>{var t={760:(t,e,n)=>{var o;o=function(t,e){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.FastConstant=void 0,function(t){var e=function(){function t(){}return t.buildUDID=function(){var t=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var n=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?n:3&n|8).toString(16)}))},t}();t.FastHelper=e;var n=function(){function t(){}return t.debug=!1,t.PLUGIN_VERSION="2.1.5",t.PLUGIN_DOWNLOAD_URL="https://www.fastchar.com/fastchar-dom-plugin.zip",t.USE_RUNTIME_CONNECT=!0,t.DOM_TAG_NAME="fastchar-dom-plugin",t.DOM_DATA_NAME="fastchar-dom-data",t.DOM_DATA_RECEIVE="fastchar-dom-data-receive",t.DOM_DATA_INVOKE_COUNT="fastchar-dom-data-invoke-count",t.DOM_DATA_CALLBACK_TOTAL="fastchar-dom-data-callback-total",t.DOM_DATA_CALLBACK_ALWAYS="fastchar-dom-data-callback-always",t.DOM_DATA_CALLBACK_TAG_NAME="fastchar-dom-callback",t.DOME_DATA_ERROR="fastchar-dom-error",t.DOM_PLUGIN="fastchar-dom-plugin",t.DOM_PLUGIN_VERSION="fastchar-dom-plugin-version",t.DOM_INVOKE_TIMEOUT=15e3,t.DOM_CONTENT_IDLE_DURATION=100,t.DOM_CONTENT_TIMEOUT=3e3,t.DOM_BACKGROUND_IDLE_DURATION=100,t}();t.FastDOM=n;var o=function(){function t(){}return t.ON_REGISTER_CONNECT="OnRegisterConnect",t.ON_INVOKE_METHOD="OnInvokeMethod",t.ON_RETURN_METHOD="OnReturnMethod",t.ON_WATCH_MESSAGE="OnWatchMessage",t.ON_IDLE="OnIdle",t}();t.FastDOMEvents=o;var a=function(){function t(){}return t.HTTP_RESPONSE_LISTENER="HTTP_RESPONSE_LISTENER",t}();t.WindowMessageEvents=a}(e.FastConstant||(e.FastConstant={}))}.apply(e,[n,e]),void 0===o||(t.exports=o)},196:(t,e,n)=>{var o,a;o=[n,e,n(760),n(333)],a=function(t,e,n,o){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.FastContentScript=void 0,function(t){var e=function(){function e(){e.contentName="FastCharDOM"+$.md5(n.FastConstant.FastHelper.buildUDID()+document.location.href+(new Date).getTime()),n.FastConstant.FastDOM.USE_RUNTIME_CONNECT?e.startConnect():e.startIdle(),e.loadHttpListener()}return e.startIdle=function(){setTimeout((function(){try{chrome.runtime.sendMessage({contentName:e.contentName,timestamp:(new Date).getTime(),title:document.title,url:document.location.href,event:n.FastConstant.FastDOMEvents.ON_WATCH_MESSAGE},(function(e){try{e&&(e instanceof Array?e.forEach((function(e){t.Core.notifyEvent(e)})):t.Core.notifyEvent(e))}finally{t.Core.startIdle()}}))}catch(t){}}),n.FastConstant.FastDOM.DOM_CONTENT_IDLE_DURATION)},e.startConnect=function(){if(this.connectPort=chrome.runtime.connect({name:e.contentName}),this.connectPort){this.connectPort.onMessage.addListener((function(e){e instanceof Array?e.forEach((function(e){t.Core.notifyEvent(e)})):t.Core.notifyEvent(e)})),this.connectPort.onDisconnect.addListener((function(t){n.FastConstant.FastDOM.debug&&console.debug("[ContentScript]当前页面已断开与插件的连接!尝试重连……",t),e.startConnect()}));var o={contentName:e.contentName,timestamp:(new Date).getTime(),title:document.title,url:document.location.href,event:n.FastConstant.FastDOMEvents.ON_REGISTER_CONNECT};this.connectPort.postMessage(o)}chrome.runtime.onConnect.addListener(this.onPopupConnectListener)},e.loadHttpListener=function(){var o=document.createElement("script");o.src=chrome.runtime.getURL("js/http_listener.js"),o.onload=function(){this.remove()},(document.head||document.documentElement).appendChild(o),window.addEventListener("message",(function(o){if(o.data&&o.data.type===n.FastConstant.WindowMessageEvents.HTTP_RESPONSE_LISTENER){var a={success:!0,fromContentName:e.contentName,type:n.FastConstant.WindowMessageEvents.HTTP_RESPONSE_LISTENER,callbackId:o.origin+n.FastConstant.WindowMessageEvents.HTTP_RESPONSE_LISTENER,data:[o.data]};a.event=n.FastConstant.FastDOMEvents.ON_RETURN_METHOD,t.Core.postMessage(a)}}))},e.notifyEvent=function(e){e.event&&e.event===n.FastConstant.FastDOMEvents.ON_INVOKE_METHOD?t.Page.invokeMethod(e):e.event&&e.event===n.FastConstant.FastDOMEvents.ON_RETURN_METHOD&&t.Page.returnMethod(e)},e.postMessage=function(t){try{"self"===t.url?(t.catchCount=1,t.invokeCount=1,this.notifyEvent(t)):n.FastConstant.FastDOM.USE_RUNTIME_CONNECT?this.connectPort?this.connectPort.postMessage(t):console.debug("[ContentScript]消息发送失败!已断开与插件的链接!"):chrome.runtime.sendMessage(t)}catch(t){}},e.invokeMethod=function(e,n){var o=[];try{if(e.method)if("reload"===e.method)o.push({url:document.location.href,title:document.title,selector:[],success:!0}),document.location.reload();else if("showLoading"===e.method)o.push({url:document.location.href,title:document.title,selector:[],success:!0}),t.Dialog.showLoading(e.params[0]);else if("hideLoading"===e.method)o.push({url:document.location.href,title:document.title,selector:[],success:!0}),t.Dialog.hideLoading();else{if("showAlert"===e.method)return void t.Dialog.showAlert(e.params[2]?e.params[2]:"orange",e.params[0],e.params[1],(function(t){o.push({url:document.location.href,title:document.title,selector:[],success:!0,button:t}),n(o)}));if("showAlertTip"===e.method)o.push({url:document.location.href,title:document.title,selector:[],success:!0}),t.Dialog.showAlertTip(e.params[3]?e.params[3]:"purple",e.params[0],e.params[1],e.params[2]);else{if("showConfirm"===e.method)return void t.Dialog.showConfirm(e.params[2]?e.params[2]:"orange",e.params[0],e.params[1],e.params[3]?e.params[3]:["确定","取消"],(function(t){o.push({url:document.location.href,title:document.title,selector:[],success:!0,button:t}),n(o)}));if(e.selectors)for(var a=0;a<e.selectors.length;a++){var s=e.selectors[a],i=$(s);if("exist"!==e.method)if(i&&i.length>0)for(var r=0;r<i.length;r++)try{var c=null,l=!0;if("click"===e.method)i[r].click();else if("js"===e.type||"javascript"===e.type){var u=i[r];"fireEvent"===e.method?(c=u.dispatchEvent(new Event(e.params[0],{bubbles:!0,cancelable:!0})))||(c="执行失败!无法触发事件:"+e.params[0],l=!1):(d=u[e.method])?c=d.apply(u,e.params):(c="执行失败!对象不存在方法:"+e.method,l=!1)}else{var d;(d=(u=$(i[r]))[e.method])?c="prop"===e.method&&"outerHTML"===e.params[0]?this.safeGetOuterHtml(u):d.apply(u,e.params):(c="执行失败!对象不存在方法:"+e.method,l=!1)}o.push({url:document.location.href,title:document.title,selector:s,success:l,content:c})}catch(t){console.debug("[ContentScript]FastChar-DOM-Plugin异常",t),o.push({url:document.location.href,title:document.title,selector:s,success:!1})}else o.push({url:document.location.href,title:document.title,selector:s,success:!1});else o.push({url:document.location.href,title:document.title,selector:s,success:!0,content:i.length>0})}}}else o.push({url:document.location.href,title:document.title,selector:[],success:!0})}catch(t){console.debug("[ContentScript]FastChar-DOM-Plugin异常信息\n",t),console.debug("[ContentScript]FastChar-DOM-Plugin异常参数\n",e),o.push({url:document.location.href,title:document.title,success:!1})}n(o)},e.safeGetOuterHtml=function(t){return t.find("input").each((function(){var t=$(this),e=t.val();null!=e&&t.attr("value",e.toString())})),t.find("textarea").each((function(){var t=$(this),e=t.val();null!=e&&t.attr("value",e.toString())})),t.prop("outerHTML")},e.onPopupConnectListener=function(e){0===e.name.indexOf("FastCharPopup@")&&e.onMessage.addListener((function(o){o.event&&o.event===n.FastConstant.FastDOMEvents.ON_INVOKE_METHOD&&t.Popup.invokeMethod(e,o)}))},e}();t.Core=e;var a=function(){function o(){o.initGlobalEvent()}return o.initGlobalEvent=function(){var o=document.getElementsByTagName("html")[0];o&&(o.setAttribute(n.FastConstant.FastDOM.DOM_PLUGIN,"true"),o.setAttribute(n.FastConstant.FastDOM.DOM_PLUGIN_VERSION,n.FastConstant.FastDOM.PLUGIN_VERSION),o.addEventListener(n.FastConstant.FastDOMEvents.ON_INVOKE_METHOD,(function(o){for(var a=document.getElementsByTagName(n.FastConstant.FastDOM.DOM_TAG_NAME),s=0;s<a.length;s++){var i=a[s];if(!i.getAttribute(n.FastConstant.FastDOM.DOM_DATA_RECEIVE)){var r=i.getAttribute(n.FastConstant.FastDOM.DOM_DATA_NAME);if(r&&0!==r.length)if(n.FastConstant.FastDOM.debug&&console.debug("[ContentScript]执行方法事件",r,new Date),i.setAttribute(n.FastConstant.FastDOM.DOM_DATA_RECEIVE,"true"),!n.FastConstant.FastDOM.USE_RUNTIME_CONNECT||t.Core.connectPort){var c=JSON.parse(r);c.event=n.FastConstant.FastDOMEvents.ON_INVOKE_METHOD,c.contentName=e.contentName,t.Core.postMessage(c)}else t.Page.callbackError(i.getAttribute("id"),"当前页面与插件已断开链接!请刷新页面重新建立链接!")}}})))},o.invokeMethod=function(e){t.Core.invokeMethod(e,(function(o){var a={success:!0,data:o};for(var s in e)a[s]=e[s];a.event=n.FastConstant.FastDOMEvents.ON_RETURN_METHOD,t.Core.postMessage(a)}))},o.returnMethod=function(e){if(e.contentName===t.Core.contentName&&(n.FastConstant.FastDOM.debug&&console.debug("[ContentScript]"+n.FastConstant.FastDOMEvents.ON_RETURN_METHOD,e,new Date),e.callbackId)){var o=document.getElementById(e.callbackId);if(o){o.setAttribute(n.FastConstant.FastDOM.DOM_DATA_CALLBACK_TOTAL,e.catchCount),o.setAttribute(n.FastConstant.FastDOM.DOM_DATA_INVOKE_COUNT,e.invokeCount);var a={data:e.data},s={};for(var i in e)"data"!==i&&"catchCount"!==i&&"invokeCount"!==i&&"success"!==i&&"callbackId"!==i&&"event"!==i&&"contentName"!==i&&"fromContentName"!==i&&"msgId"!==i&&(s[i]=e[i]);o.setAttribute(n.FastConstant.FastDOM.DOM_DATA_NAME,JSON.stringify(s));var r=document.createElement(n.FastConstant.FastDOM.DOM_DATA_CALLBACK_TAG_NAME);r.setAttribute("style","display:none;"),r.innerText=JSON.stringify(a),o.appendChild(r),o.dispatchEvent(new Event(e.callbackId))}}},o.callbackError=function(t,e){var o=document.getElementById(t);o&&(o.setAttribute(n.FastConstant.FastDOM.DOM_DATA_CALLBACK_TOTAL,"0"),o.setAttribute(n.FastConstant.FastDOM.DOM_DATA_INVOKE_COUNT,"0"),o.setAttribute(n.FastConstant.FastDOM.DOME_DATA_ERROR,e),o.dispatchEvent(new Event(t+"Error")))},o}();t.Page=a;var s=function(){function e(){}return e.showLoading=function(e){t.Dialog.loading||(t.Dialog.loading=$.dialog({title:"",content:"<div style='height: 60px;display: flex;align-items: center;justify-content: center;' id='"+n.FastConstant.FastDOM.DOM_PLUGIN+"-loading'><div style='margin-left: 25px;user-select: none;font-size: 18px;color: #000;'>"+e+"</div></div>",type:"blue",useBootstrap:!1,closeIcon:!1,animateFromElement:!0,boxWidth:"280px",onOpenBefore:function(){var t=document.getElementById(n.FastConstant.FastDOM.DOM_PLUGIN+"-loading");t&&new o.Spinner({color:"#000",position:"unset",scale:1,length:0,corners:1,animation:"spinner-line-shrink"}).spin(t)},onClose:function(){t.Dialog.loading=null}}))},e.hideLoading=function(){t.Dialog.loading&&t.Dialog.loading.close()},e.showAlert=function(t,e,n,o){$.confirm({title:e,content:n,type:t,animateFromElement:!0,boxWidth:"280px",useBootstrap:!1,closeIcon:!0,typeAnimated:!0,buttons:{ok:{keys:["enter"],text:"知道了"}},onAction:function(t){o(t)},onClose:function(){o("close")}})},e.showAlertTip=function(t,e,n,o){$.confirm({title:e,content:n,type:t,animateFromElement:!0,boxWidth:"280px",useBootstrap:!1,closeIcon:!0,typeAnimated:!0,backgroundDismiss:!0,autoClose:"ok|"+o,buttons:{ok:{keys:["enter"],text:"知道了"}}})},e.showConfirm=function(t,e,n,o,a){$.confirm({title:e,content:n,type:t,animateFromElement:!0,boxWidth:"280px",useBootstrap:!1,closeIcon:!0,typeAnimated:!0,buttons:{ok:{keys:["enter"],text:o[0]},no:{text:o[1]}},onAction:function(t){a(t)},onClose:function(){a("close")}})},e}();t.Dialog=s;var i=function(){function e(){}return e.invokeMethod=function(e,n){t.Core.invokeMethod(n,(function(t){var o={success:!0,message:"执行成功!",code:0,from:"content_script",data:t};o.popupId=n.popupId,o.callbackId=n.callbackId,o.event="OnReturnMethod",e.postMessage(o)}))},e}();for(var r in t.Popup=i,t)t[r]()}(e.FastContentScript||(e.FastContentScript={}))}.apply(e,o),void 0===a||(t.exports=a)},333:(t,e,n)=>{"use strict";n.r(e),n.d(e,{Spinner:()=>s});var o=function(){return o=Object.assign||function(t){for(var e,n=1,o=arguments.length;n<o;n++)for(var a in e=arguments[n])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t},o.apply(this,arguments)},a={lines:12,length:7,width:5,radius:10,scale:1,corners:1,color:"#000",fadeColor:"transparent",animation:"spinner-line-fade-default",rotate:0,direction:1,speed:1,zIndex:2e9,className:"spinner",top:"50%",left:"50%",shadow:"0 0 1px transparent",position:"absolute"},s=function(){function t(t){void 0===t&&(t={}),this.opts=o(o({},a),t)}return t.prototype.spin=function(t){return this.stop(),this.el=document.createElement("div"),this.el.className=this.opts.className,this.el.setAttribute("role","progressbar"),i(this.el,{position:this.opts.position,width:0,zIndex:this.opts.zIndex,left:this.opts.left,top:this.opts.top,transform:"scale("+this.opts.scale+")"}),t&&t.insertBefore(this.el,t.firstChild||null),function(t,e){var n=Math.round(e.corners*e.width*500)/1e3+"px",o="none";!0===e.shadow?o="0 2px 4px #000":"string"==typeof e.shadow&&(o=e.shadow);for(var a=function(t){for(var e=/^\s*([a-zA-Z]+\s+)?(-?\d+(\.\d+)?)([a-zA-Z]*)\s+(-?\d+(\.\d+)?)([a-zA-Z]*)(.*)$/,n=[],o=0,a=t.split(",");o<a.length;o++){var s=a[o].match(e);if(null!==s){var i=+s[2],r=+s[5],c=s[4],l=s[7];0!==i||c||(c=l),0!==r||l||(l=c),c===l&&n.push({prefix:s[1]||"",x:i,y:r,xUnits:c,yUnits:l,end:s[8]})}}return n}(o),s=0;s<e.lines;s++){var l=~~(360/e.lines*s+e.rotate),u=i(document.createElement("div"),{position:"absolute",top:-e.width/2+"px",width:e.length+e.width+"px",height:e.width+"px",background:r(e.fadeColor,s),borderRadius:n,transformOrigin:"left",transform:"rotate("+l+"deg) translateX("+e.radius+"px)"}),d=s*e.direction/e.lines/e.speed;d-=1/e.speed;var p=i(document.createElement("div"),{width:"100%",height:"100%",background:r(e.color,s),borderRadius:n,boxShadow:c(a,l),animation:1/e.speed+"s linear "+d+"s infinite "+e.animation});u.appendChild(p),t.appendChild(u)}}(this.el,this.opts),this},t.prototype.stop=function(){return this.el&&("undefined"!=typeof requestAnimationFrame?cancelAnimationFrame(this.animateId):clearTimeout(this.animateId),this.el.parentNode&&this.el.parentNode.removeChild(this.el),this.el=void 0),this},t}();function i(t,e){for(var n in e)t.style[n]=e[n];return t}function r(t,e){return"string"==typeof t?t:t[e%t.length]}function c(t,e){for(var n=[],o=0,a=t;o<a.length;o++){var s=a[o],i=l(s.x,s.y,e);n.push(s.prefix+i[0]+s.xUnits+" "+i[1]+s.yUnits+s.end)}return n.join(", ")}function l(t,e,n){var o=n*Math.PI/180,a=Math.sin(o),s=Math.cos(o);return[Math.round(1e3*(t*s+e*a))/1e3,Math.round(1e3*(-t*a+e*s))/1e3]}}},e={};function n(o){var a=e[o];if(void 0!==a)return a.exports;var s=e[o]={exports:{}};return t[o](s,s.exports,n),s.exports}n.d=(t,e)=>{for(var o in e)n.o(e,o)&&!n.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:e[o]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(196)})();