mirror of
https://github.com/altcha-org/altcha.git
synced 2026-01-25 04:16:41 +00:00
2 lines
2.2 KiB
JavaScript
2 lines
2.2 KiB
JavaScript
(function(o,s){typeof exports=="object"&&typeof module<"u"?s(exports):typeof define=="function"&&define.amd?define(["exports"],s):(o=typeof globalThis<"u"?globalThis:o||self,s(o["[name]"]={}))})(this,function(o){"use strict";class s{constructor(t){this.context=t}static pluginName;static register(t){typeof globalThis.altchaPlugins!="object"&&(globalThis.altchaPlugins=[]),globalThis.altchaPlugins.includes(t)||globalThis.altchaPlugins.push(t)}destroy(){}onErrorChange(t){}onStateChange(t){}}var a=(e=>(e.CODE="code",e.ERROR="error",e.VERIFIED="verified",e.VERIFYING="verifying",e.UNVERIFIED="unverified",e.EXPIRED="expired",e))(a||{});class h extends s{static pluginName="obfuscation";elButton;#t=this.#e.bind(this);constructor(t){super(t);const i=t.el;this.elButton=i.parentElement?.querySelector("[data-clarify-button]")||i.parentElement?.querySelector("button, a"),this.elButton&&this.elButton.addEventListener("click",this.#t)}destroy(){this.elButton&&this.elButton.removeEventListener("click",this.#t)}async clarify(){const{el:t,getConfiguration:i,getFloatingAnchor:n,setFloatingAnchor:u,reset:p,solve:m,setState:f}=this.context,{delay:g,floating:E,maxnumber:y,obfuscated:d}=i();if(this.elButton&&!n()&&u(this.elButton),!d){f(a.ERROR);return}p(a.VERIFYING),await new Promise(c=>setTimeout(c,g||0));const[b,R]=d.split("?");let l=new URLSearchParams(R||"").get("key")||void 0;if(l){const c=l.match(/^\(prompt:?(.*)\)$/);c&&(l=prompt(c[1]||"Enter Key:")||void 0)}const{solution:r}=await m({obfuscated:b,key:l,maxnumber:y});r&&"clearText"in r?(this.#i(r.clearText),f(a.VERIFIED),this.context.dispatch("cleartext",r.clearText),E&&t&&(t.style.display="none")):f(a.ERROR,"Unable to decrypt data.")}#e(t){t.preventDefault();const{auto:i}=this.context.getConfiguration();i==="off"||this.clarify()}#i(t){const i=t.match(/^(mailto|tel|sms|https?):/);let n;if(i){const[u]=t.slice(t.indexOf(":")+1).replace(/^\/\//,"").split("?");n=document.createElement("a"),n.href=t,n.innerHTML=u}else n=document.createTextNode(t);this.elButton&&n&&(this.elButton.after(n),this.elButton.parentElement?.removeChild(this.elButton))}}s.register(h),o.PluginObfuscation=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
|