"use strict";(()=>{var He=Object.create;var Z=Object.defineProperty;var Ue=Object.getOwnPropertyDescriptor;var Pe=Object.getOwnPropertyNames;var je=Object.getPrototypeOf,We=Object.prototype.hasOwnProperty;var Ke=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ve=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Pe(t))!We.call(e,o)&&o!==n&&Z(e,o,{get:()=>t[o],enumerable:!(r=Ue(t,o))||r.enumerable});return e};var qe=(e,t,n)=>(n=e!=null?He(je(e)):{},Ve(t||!e||!e.__esModule?Z(n,"default",{value:e,enumerable:!0}):n,e));var ue=Ke((Et,j)=>{"use strict";var v=typeof Reflect=="object"?Reflect:null,ee=v&&typeof v.apply=="function"?v.apply:function(t,n,r){return Function.prototype.apply.call(t,n,r)},_;v&&typeof v.ownKeys=="function"?_=v.ownKeys:Object.getOwnPropertySymbols?_=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:_=function(t){return Object.getOwnPropertyNames(t)};function Ge(e){console&&console.warn&&console.warn(e)}var ne=Number.isNaN||function(t){return t!==t};function i(){i.init.call(this)}j.exports=i;j.exports.once=Je;i.EventEmitter=i;i.prototype._events=void 0;i.prototype._eventsCount=0;i.prototype._maxListeners=void 0;var te=10;function A(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return te},set:function(e){if(typeof e!="number"||e<0||ne(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");te=e}});i.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0};i.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||ne(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function re(e){return e._maxListeners===void 0?i.defaultMaxListeners:e._maxListeners}i.prototype.getMaxListeners=function(){return re(this)};i.prototype.emit=function(t){for(var n=[],r=1;r0&&(s=n[0]),s instanceof Error)throw s;var c=new Error("Unhandled error."+(s?" ("+s.message+")":""));throw c.context=s,c}var f=a[t];if(f===void 0)return!1;if(typeof f=="function")ee(f,this,n);else for(var u=f.length,p=ce(f,u),r=0;r0&&s.length>o&&!s.warned){s.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+s.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=s.length,Ge(c)}return e}i.prototype.addListener=function(t,n){return oe(this,t,n,!1)};i.prototype.on=i.prototype.addListener;i.prototype.prependListener=function(t,n){return oe(this,t,n,!0)};function $e(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function ae(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=$e.bind(r);return o.listener=n,r.wrapFn=o,o}i.prototype.once=function(t,n){return A(n),this.on(t,ae(this,t,n)),this};i.prototype.prependOnceListener=function(t,n){return A(n),this.prependListener(t,ae(this,t,n)),this};i.prototype.removeListener=function(t,n){var r,o,a,s,c;if(A(n),o=this._events,o===void 0)return this;if(r=o[t],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete o[t],o.removeListener&&this.emit("removeListener",t,r.listener||n));else if(typeof r!="function"){for(a=-1,s=r.length-1;s>=0;s--)if(r[s]===n||r[s].listener===n){c=r[s].listener,a=s;break}if(a<0)return this;a===0?r.shift():ze(r,a),r.length===1&&(o[t]=r[0]),o.removeListener!==void 0&&this.emit("removeListener",t,c||n)}return this};i.prototype.off=i.prototype.removeListener;i.prototype.removeAllListeners=function(t){var n,r,o;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[t]),this;if(arguments.length===0){var a=Object.keys(r),s;for(o=0;o=0;o--)this.removeListener(t,n[o]);return this};function se(e,t,n){var r=e._events;if(r===void 0)return[];var o=r[t];return o===void 0?[]:typeof o=="function"?n?[o.listener||o]:[o]:n?Qe(o):ce(o,o.length)}i.prototype.listeners=function(t){return se(this,t,!0)};i.prototype.rawListeners=function(t){return se(this,t,!1)};i.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ie.call(e,t)};i.prototype.listenerCount=ie;function ie(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}i.prototype.eventNames=function(){return this._eventsCount>0?_(this._events):[]};function ce(e,t){for(var n=new Array(t),r=0;r{let e=typeof crypto!="undefined"?crypto:typeof window!="undefined"?window.crypto||window.msCrypto:void 0;if(e!==void 0){if(e.randomBytes!==void 0)return e.randomBytes;if(e.getRandomValues!==void 0)return t=>{let n=new Uint8Array(t);return e.getRandomValues(n),n}}return t=>{let n=[];for(let r=t;r>0;r--)n.push(Math.floor(Math.random()*256));return n}})(),fe=4096;function pe(){(W===void 0||O+16>fe)&&(O=0,W=Ye(fe));let e=Array.prototype.slice.call(W,O,O+=16);return e[6]=e[6]&15|64,e[8]=e[8]&63|128,l[e[0]]+l[e[1]]+l[e[2]]+l[e[3]]+"-"+l[e[4]]+l[e[5]]+"-"+l[e[6]]+l[e[7]]+"-"+l[e[8]]+l[e[9]]+"-"+l[e[10]]+l[e[11]]+l[e[12]]+l[e[13]]+l[e[14]]+l[e[15]]}var Ze={undefined:()=>0,boolean:()=>4,number:()=>8,string:e=>2*e.length,object:e=>e?Object.keys(e).reduce((t,n)=>K(n)+K(e[n])+t,0):0},K=e=>Ze[typeof e](e),T=class extends de.EventEmitter{constructor(t){super(),this.setMaxListeners(1/0),this.wall=t,t.listen(n=>{Array.isArray(n)?n.forEach(r=>this._emit(r)):this._emit(n)}),this._sendingQueue=[],this._sending=!1,this._maxMessageSize=32*1024*1024}send(t,n){return this._send([{event:t,payload:n}])}getEvents(){return this._events}on(t,n){return super.on(t,r=>{n({...r,respond:o=>this.send(r.eventResponseKey,o)})})}_emit(t){typeof t=="string"?this.emit(t):this.emit(t.event,t.payload)}_send(t){return this._sendingQueue.push(t),this._nextSend()}_nextSend(){if(!this._sendingQueue.length||this._sending)return Promise.resolve();this._sending=!0;let t=this._sendingQueue.shift(),n=t[0],r=`${n.event}.${pe()}`,o=r+".result";return new Promise((a,s)=>{let c=[],f=u=>{if(u!==void 0&&u._chunkSplit){let p=u._chunkSplit;c=[...c,...u.data],p.lastChunk&&(this.off(o,f),a(c))}else this.off(o,f),a(u)};this.on(o,f);try{let u=t.map(p=>({...p,payload:{data:p.payload,eventResponseKey:o}}));this.wall.send(u)}catch(u){let p="Message length exceeded maximum allowed length.";if(u.message===p&&Array.isArray(n.payload)){let y=K(n);if(y>this._maxMessageSize){let b=Math.ceil(y/this._maxMessageSize),d=Math.ceil(n.payload.length/b),U=n.payload;for(let I=0;Ithis._nextSend(),16)})}};var me=(e,t)=>{window.addEventListener("message",n=>{if(n.source===window&&n.data.from!==void 0&&n.data.from===t){let r=n.data[0],o=e.getEvents();for(let a in o)a===r.event&&o[a](r.payload)}},!1)};var et=chrome.runtime.getURL("assets/config.js"),ge,M=(ge=globalThis.browser)!=null?ge:globalThis.chrome;async function tt(){var J,X;let e=await M.storage.local.get("defaultConfig");if((J=e.defaultConfig)!=null&&J.apiKey)return e.defaultConfig;let t={},n=["DelayTime","RepeatTimes","port"],r=["enabledFor","useCapsolver","manualSolving","useProxy","showSolveButton"],o=/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm,c=(await(await fetch(et)).text()).replace(o,""),f=c.slice(c.indexOf("{")+1,c.lastIndexOf("}")),u=JSON.stringify(f).replaceAll('\\"',"'").replaceAll("\\n","").replaceAll('"',"").replaceAll(" ",""),p=u.indexOf("blackUrlList"),y=u.slice(p),b=y.indexOf("],"),d=y.slice(0,b+1);u.replace(d,"").split(",").forEach(Be=>{let[R,Y]=Be.split(":");if(R&&Y){let x=Y.replaceAll("'","").replaceAll('"',"");for(let h=0;h{let r=new Image;r.src=e,r.setAttribute("crossOrigin","anonymous"),r.onload=()=>{let o=document.createElement("canvas");o.width=r.width,o.height=r.height,o.getContext("2d").drawImage(r,0,0,r.width,r.height);let s=o.toDataURL();t(s)},r.onerror=o=>{n(o)}})}function Ce(e){return new Promise(t=>setTimeout(t,e))}function C(e,t){var n;return"KeyboardEvent"in window?n=new window.KeyboardEvent(t,{bubbles:!0,cancelable:!1}):(n=e.ownerDocument.createEvent("Events"),n.initEvent(t,!0,!1),n.charCode=0,n.keyCode=0,n.which=0,n.srcElement=e,n.target=e),n}function rt(e){return!e||e&&typeof e.click!="function"?!1:(e.click(),!0)}function ot(e,t){if(t){var n=e.value;e.focus(),e.value!==n&&(e.value=n)}else e.focus()}function at(e){var t=e.value;rt(e),ot(e,!1),e.dispatchEvent(C(e,"keydown")),e.dispatchEvent(C(e,"keypress")),e.dispatchEvent(C(e,"keyup")),e.value!==t&&(e.value=t)}function st(e){var t=e.value,n=e.ownerDocument.createEvent("HTMLEvents"),r=e.ownerDocument.createEvent("HTMLEvents");e.dispatchEvent(C(e,"keydown")),e.dispatchEvent(C(e,"keypress")),e.dispatchEvent(C(e,"keyup")),r.initEvent("input",!0,!0),e.dispatchEvent(r),n.initEvent("change",!0,!0),e.dispatchEvent(n),e.blur(),e.value!==t&&(e.value=t)}async function V(e,t){e.value=t,at(e),st(e)}var N="capsolver-image-to-text-source",L="capsolver-image-to-text-result",D=[],ye=0;function F(e){let t="",n="",r=[];return e.style.backgroundImage?n=e.style.backgroundImage:e.style.background&&(n=e.style.background),r=n.split(","),r.find(a=>a.startsWith("url("))?(t=n.slice(5,n.length-2),t.startsWith("blob:")?t.slice(5):t):""}function ct(){let e="["+N+"]",t=document.querySelectorAll(e),n=[];return Array.from(t).forEach(r=>{let o=r.tagName,a="";o==="IMG"?a=r.getAttribute("src"):a=F(r),a&&n.push(r)}),n}function lt(){let e="input["+L+"]";return Array.from(document.querySelectorAll(e))}function ut(e){let t=e.naturalWidth,n=e.naturalHeight,r=document.createElement("canvas");return Object.assign(r,{width:t,height:n}),r.getContext("2d").drawImage(e,0,0,t,n,0,0,t,n),r.toDataURL("image/jpeg")}async function ft(e){if(e.tagName==="IMG")return ut(e);{let n=F(e);return await ve(n)}}function pt(e,t){let n=[];return t.forEach(r=>{let o=r.getAttribute(L),a=e.find(s=>s.getAttribute(N)===o);a&&n.push({image:a,result:r,id:o})}),n}async function dt(e,t){let n=await ft(e.image),r={body:n.slice(n.indexOf(";base64,")+8),id:e.id},o={action:"solver",captchaType:"textCaptcha",params:r};chrome.runtime.sendMessage(o).then(a=>{var s;if(!(a!=null&&a.response)||((s=a==null?void 0:a.response)==null?void 0:s.error)){ye++,ye<=t&&D.splice(D.indexOf(e.id),1);return}vt(a.response)})}var mt=[{value:"mul",label:"\xD7"},{value:"add",label:"+"},{value:"subtract",label:"-"}],ht=new Map([["add","+"],["subtract","-"],["mul","\xD7"]]);function gt(e,t){let r=e.slice(0,e.length-1).split(ht.get(t));if(isNaN(Number(r[0]))||isNaN(Number(r[1])))return NaN;let o;switch(t){case"add":{o=Number(r[0])+Number(r[1]);break}case"subtract":{o=Number(r[0])-Number(r[1]);break}case"mul":{o=Number(r[0])*Number(r[1]);break}}return o}function bt(e){return e[e.length-1]!=="="?!1:mt.find(n=>e.indexOf(n.label)!==-1).value}function vt(e){var a;let t=(a=e.response)==null?void 0:a.solution,n=e.id,r=document.querySelector(`input[${L}="${n}"]`);if(!r)return;let o=bt(t.text);if(!o)V(r,t.text);else{let s=gt(t.text,o);V(r,isNaN(s)?t.text:s)}chrome.runtime.sendMessage({action:"solved"})}function xe(e){N=e.textCaptchaSourceAttribute||N,L=e.textCaptchaResultAttribute||L;let t=ct();if(t.length<=0)return!1;let n=lt();if(n.length<=0)return!1;let r=pt(t,n);return r.length<=0?!1:r}function Te(e,t){let n=e.length;for(let r=0;r{g=null,k=null;let t=e.target,n=t.tagName,r="";n==="IMG"?r=t.getAttribute("src"):r=F(t),r?g=t:k=t})}function z(){let e=window.location;return e.protocol+"//"+e.hostname+e.pathname}function Le(e){let t="",n=e.tagName.toLowerCase(),r=e.id;if(r)t=`${n}#${r}`;else{let o=Array.from(e.attributes),a="";for(let s=0;st?"attr":"id"}async function xt(e){if(!e)return;let t,n=await B("source");ke(e)==="attr"?t=document.querySelector(e):t=document.getElementById(e.slice(e.indexOf("#")+1)),t==null||t.setAttribute(n,String(q))}async function Tt(e){if(!e)return;let t,n=await B("result");ke(e)==="attr"?t=document.querySelector(e):t=document.getElementById(e.slice(e.indexOf("#")+1)),t==null||t.setAttribute(n,String(G))}function wt(e){let t=e.image,n=e.input;xt(t),Tt(n)}function Ee(){return!g}function Ie(){return!!$}async function Se(){let e=await B("source");!g||(g.setAttribute(e,String(q)),$=g,q++,chrome.runtime.sendMessage({action:"updateMenu"}),Ct(g))}async function Re(){let e=await B("result");!k||(k.setAttribute(e,String(G)),$=null,G++,chrome.runtime.sendMessage({action:"updateMenu"}),yt(k))}async function _e(){let e=z(),t=await E.storage.local.get("imageUrls");if(!t)return;let n=t==null?void 0:t.imageUrls;if(!n)return;let r=n[e];!r||wt(r)}async function Ae(e){!e.useCapsolver||!e.enabledForImageToText||!e.apiKey||e.enabledForBlacklistControl&&e.isInBlackList||(await Ce(e.textCaptchaDelayTime),setInterval(async()=>{let t=xe(e);!t||Te(t,e.textCaptchaRepeatTimes)},1e3))}var H=null;H&&window.clearInterval(H);H=window.setInterval(async()=>{let e=await m.getAll();!e.isInit||e.manualSolving||(Ae(e),window.clearInterval(H))},100);window.addEventListener("message",async function(e){if(e.data.type!=="capsolverSolve")return;let t=await m.getAll();!t.manualSolving||Ae(t)});Me();chrome.runtime.onMessage.addListener((e,t,n)=>{let{command:r}=e;switch(r){case"image2Text:canMarkImage":let o=Ee();n(o);break;case"image2Text:canMarkInput":let a=Ie();n(a);break;case"image2Text:markedImage":Se(),n(null);break;case"image2Text:markedResult":Re(),n(null);break}return!1});var Mt=setInterval(function(){document.readyState==="complete"&&(_e(),clearInterval(Mt))},1e3),Oe=e=>{};var Q=chrome.runtime.connect({name:"contentScript"}),Ne=!1;Q.onDisconnect.addListener(()=>{Ne=!0});var De=new T({listen(e){Q.onMessage.addListener(e)},send(e){Ne||(Q.postMessage(e),window.postMessage({...e,from:"bex-content-script"},"*"))}});function Lt(e){let t=document.createElement("script");t.src=e,t.onload=function(){this.remove()},(document.head||document.documentElement).appendChild(t)}document instanceof HTMLDocument&&Lt(chrome.runtime.getURL("dom.js"));me(De,"bex-dom");Oe(De);})();