"use strict";(()=>{var Ee=Object.create;var Q=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Se=Object.getOwnPropertyNames;var Re=Object.getPrototypeOf,_e=Object.prototype.hasOwnProperty;var Pe=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var Ie=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Se(t))!_e.call(e,r)&&r!==n&&Q(e,r,{get:()=>t[r],enumerable:!(o=ke(t,r))||o.enumerable});return e};var Oe=(e,t,n)=>(n=e!=null?Ee(Re(e)):{},Ie(t||!e||!e.__esModule?Q(n,"default",{value:e,enumerable:!0}):n,e));var ce=Pe((rt,F)=>{"use strict";var b=typeof Reflect=="object"?Reflect:null,$=b&&typeof b.apply=="function"?b.apply:function(t,n,o){return Function.prototype.apply.call(t,n,o)},R;b&&typeof b.ownKeys=="function"?R=b.ownKeys:Object.getOwnPropertySymbols?R=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:R=function(t){return Object.getOwnPropertyNames(t)};function Be(e){console&&console.warn&&console.warn(e)}var ee=Number.isNaN||function(t){return t!==t};function i(){i.init.call(this)}F.exports=i;F.exports.once=je;i.EventEmitter=i;i.prototype._events=void 0;i.prototype._eventsCount=0;i.prototype._maxListeners=void 0;var Z=10;function _(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 Z},set:function(e){if(typeof e!="number"||e<0||ee(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");Z=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||ee(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 te(e){return e._maxListeners===void 0?i.defaultMaxListeners:e._maxListeners}i.prototype.getMaxListeners=function(){return te(this)};i.prototype.emit=function(t){for(var n=[],o=1;o0&&(a=n[0]),a instanceof Error)throw a;var c=new Error("Unhandled error."+(a?" ("+a.message+")":""));throw c.context=a,c}var l=s[t];if(l===void 0)return!1;if(typeof l=="function")$(l,this,n);else for(var u=l.length,p=se(l,u),o=0;o0&&a.length>r&&!a.warned){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,Be(c)}return e}i.prototype.addListener=function(t,n){return ne(this,t,n,!1)};i.prototype.on=i.prototype.addListener;i.prototype.prependListener=function(t,n){return ne(this,t,n,!0)};function De(){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 oe(e,t,n){var o={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},r=De.bind(o);return r.listener=n,o.wrapFn=r,r}i.prototype.once=function(t,n){return _(n),this.on(t,oe(this,t,n)),this};i.prototype.prependOnceListener=function(t,n){return _(n),this.prependListener(t,oe(this,t,n)),this};i.prototype.removeListener=function(t,n){var o,r,s,a,c;if(_(n),r=this._events,r===void 0)return this;if(o=r[t],o===void 0)return this;if(o===n||o.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete r[t],r.removeListener&&this.emit("removeListener",t,o.listener||n));else if(typeof o!="function"){for(s=-1,a=o.length-1;a>=0;a--)if(o[a]===n||o[a].listener===n){c=o[a].listener,s=a;break}if(s<0)return this;s===0?o.shift():Ae(o,s),o.length===1&&(r[t]=o[0]),r.removeListener!==void 0&&this.emit("removeListener",t,c||n)}return this};i.prototype.off=i.prototype.removeListener;i.prototype.removeAllListeners=function(t){var n,o,r;if(o=this._events,o===void 0)return this;if(o.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):o[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete o[t]),this;if(arguments.length===0){var s=Object.keys(o),a;for(r=0;r=0;r--)this.removeListener(t,n[r]);return this};function re(e,t,n){var o=e._events;if(o===void 0)return[];var r=o[t];return r===void 0?[]:typeof r=="function"?n?[r.listener||r]:[r]:n?Fe(r):se(r,r.length)}i.prototype.listeners=function(t){return re(this,t,!0)};i.prototype.rawListeners=function(t){return re(this,t,!1)};i.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ae.call(e,t)};i.prototype.listenerCount=ae;function ae(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?R(this._events):[]};function se(e,t){for(var n=new Array(t),o=0;o{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 o=t;o>0;o--)n.push(Math.floor(Math.random()*256));return n}})(),le=4096;function ue(){(j===void 0||P+16>le)&&(P=0,j=Ue(le));let e=Array.prototype.slice.call(j,P,P+=16);return e[6]=e[6]&15|64,e[8]=e[8]&63|128,f[e[0]]+f[e[1]]+f[e[2]]+f[e[3]]+"-"+f[e[4]]+f[e[5]]+"-"+f[e[6]]+f[e[7]]+"-"+f[e[8]]+f[e[9]]+"-"+f[e[10]]+f[e[11]]+f[e[12]]+f[e[13]]+f[e[14]]+f[e[15]]}var qe={undefined:()=>0,boolean:()=>4,number:()=>8,string:e=>2*e.length,object:e=>e?Object.keys(e).reduce((t,n)=>N(n)+N(e[n])+t,0):0},N=e=>qe[typeof e](e),w=class extends fe.EventEmitter{constructor(t){super(),this.setMaxListeners(1/0),this.wall=t,t.listen(n=>{Array.isArray(n)?n.forEach(o=>this._emit(o)):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,o=>{n({...o,respond:r=>this.send(o.eventResponseKey,r)})})}_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],o=`${n.event}.${ue()}`,r=o+".result";return new Promise((s,a)=>{let c=[],l=u=>{if(u!==void 0&&u._chunkSplit){let p=u._chunkSplit;c=[...c,...u.data],p.lastChunk&&(this.off(r,l),s(c))}else this.off(r,l),s(u)};this.on(r,l);try{let u=t.map(p=>({...p,payload:{data:p.payload,eventResponseKey:r}}));this.wall.send(u)}catch(u){let p="Message length exceeded maximum allowed length.";if(u.message===p&&Array.isArray(n.payload)){let C=N(n);if(C>this._maxMessageSize){let v=Math.ceil(C/this._maxMessageSize),m=Math.ceil(n.payload.length/v),D=n.payload;for(let E=0;Ethis._nextSend(),16)})}};var pe=(e,t)=>{window.addEventListener("message",n=>{if(n.source===window&&n.data.from!==void 0&&n.data.from===t){let o=n.data[0],r=e.getEvents();for(let s in r)s===o.event&&r[s](o.payload)}},!1)};var He=chrome.runtime.getURL("assets/config.js"),me,L=(me=globalThis.browser)!=null?me:globalThis.chrome;async function Ke(){var J,X;let e=await L.storage.local.get("defaultConfig");if((J=e.defaultConfig)!=null&&J.apiKey)return e.defaultConfig;let t={},n=["DelayTime","RepeatTimes","port"],o=["enabledFor","useCapsolver","manualSolving","useProxy","showSolveButton"],r=/\/\*[\s\S]*?\*\/|([^:]|^)\/\/.*$/gm,c=(await(await fetch(He)).text()).replace(r,""),l=c.slice(c.indexOf("{")+1,c.lastIndexOf("}")),u=JSON.stringify(l).replaceAll('\\"',"'").replaceAll("\\n","").replaceAll('"',"").replaceAll(" ",""),p=u.indexOf("blackUrlList"),C=u.slice(p),v=C.indexOf("],"),m=C.slice(0,v+1);u.replace(m,"").split(",").forEach(Te=>{let[S,Y]=Te.split(":");if(S&&Y){let x=Y.replaceAll("'","").replaceAll('"',"");for(let g=0;gsetTimeout(t,e))}function U(e,t){function n(o,r,s){let a=["mouseover","mousedown","mouseup","click"],c={clientX:r,clientY:s,bubbles:!0};for(let l=0;l{n(t,o.x,o.y)})}var T="",d="",H="",I="",q=0,ge=0;function ye(){let e=document.querySelector("#amzn-btn-verify-internal");if(!e){let t=document.querySelector("awswaf-captcha");if(!t)return null;let n=t.shadowRoot;if(!n)return null;e=n.querySelector("#amzn-btn-verify-internal")}return e.style.display==="none"?null:e}function O(){let e=document.querySelector("canvas");if(!e){let t=document.querySelector("awswaf-captcha");if(!t)return null;let n=t.shadowRoot;if(!n)return null;e=n.querySelector("canvas")}return e}function K(){let e=O();return e?e==null?void 0:e.toDataURL():null}function Ve(){return{image:d==="toycarcity"?T:JSON.parse(T),question:d==="toycarcity"?"aws:toycarcity:carcity":`aws:grid:${H}`}}async function ze(e){var c;let t=(c=e==null?void 0:e.box)!=null?c:[],n=0,o=0,r=[],s=O(),a=s.getBoundingClientRect();for(let l=0;l{var r,s,a;if(!(o!=null&&o.response)||((r=o==null?void 0:o.response)==null?void 0:r.error)){T="",d="",q++,z();return}d==="toycarcity"?ze((s=o.response.response)==null?void 0:s.solution):Je((a=o.response.response)==null?void 0:a.solution)})}function be(){let e=setInterval(async()=>{await Qe()&&(clearInterval(e),await $e())},1e3)}async function W(e){try{let t=JSON.parse(e);if(!(t!=null&&t.problem_type))return;d=t.problem_type,T=t.assets.image||t.assets.images,d!=="toycarcity"&&(H=JSON.parse(t.assets.target)[0]),be()}catch(t){console.error(t)}}function Ze(){let e=document.querySelector("#captcha-container #root form > div:nth-of-type(3)");if(!e)return!1;let n=e.textContent.split(": "),o=n[n.length-1];return Number(o)>1}async function V(e){var t;try{let n=JSON.parse(e);if(n.token)return;if(n.success&&!Ze()){chrome.runtime.sendMessage({action:"solved"});return}if(!((t=n==null?void 0:n.problem)!=null&&t.problem_type))return;d=n.problem.problem_type,T=n.problem.assets.image||n.problem.assets.images,d!=="toycarcity"&&(H=JSON.parse(n.problem.assets.target)[0]),q++,be()}catch(n){console.error(n)}}function z(e){e&&(ge=e.awsRepeatTimes);let t=setInterval(()=>{Xe()&&(Ye(),clearInterval(t))},1e3)}function et(){let e=document.createElement("script");e.src=chrome.runtime.getURL("assets/inject/inject-aws.js");let t=document.head||document.documentElement;if(t.children.length!==0)t.appendChild(e);else{let n=setInterval(()=>{document.querySelector("#amzn-btn-verify-internal")&&(document.head.appendChild(e),clearInterval(n),window.addEventListener("message",function(r){var s,a;if(((s=r==null?void 0:r.data)==null?void 0:s.type)==="xhr"||((a=r==null?void 0:r.data)==null?void 0:a.type)==="fetch"){let c=r.data.url;c.includes("/problem")&&W(r.data.data),c.includes("/verify")&&V(r.data.data)}}),h(1e3).then(()=>{document.querySelector("#amzn-btn-refresh-internal").click()}))},300)}}et();window.addEventListener("message",function(e){var t,n;if(((t=e==null?void 0:e.data)==null?void 0:t.type)==="xhr"||((n=e==null?void 0:e.data)==null?void 0:n.type)==="fetch"){let o=e.data.url;o.includes("/problem")&&W(e.data.data),o.includes("/verify")&&V(e.data.data)}});function Ce(e){z(e)}async function tt(e){!e.useCapsolver||!e.enabledForAwsCaptcha||!e.apiKey||e.enabledForBlacklistControl&&e.isInBlackList||e.awsCaptchaMode!=="click"||(await h(e.awsDelayTime),Ce(e))}var B=null;B&&window.clearInterval(B);B=window.setInterval(async()=>{let e=await y.getAll();!e.isInit||(e.manualSolving?chrome.runtime.onMessage.addListener(t=>{t.command==="execute"&&Ce(e)}):tt(e),window.clearInterval(B))},100);var xe=e=>{};var G=chrome.runtime.connect({name:"contentScript"}),we=!1;G.onDisconnect.addListener(()=>{we=!0});var Me=new w({listen(e){G.onMessage.addListener(e)},send(e){we||(G.postMessage(e),window.postMessage({...e,from:"bex-content-script"},"*"))}});function nt(e){let t=document.createElement("script");t.src=e,t.onload=function(){this.remove()},(document.head||document.documentElement).appendChild(t)}document instanceof HTMLDocument&&nt(chrome.runtime.getURL("dom.js"));pe(Me,"bex-dom");xe(Me);})();