auto-post-marketplace-facebook/releases/auto-post-facebook-extensio.../content/content.js

7 lines
55 KiB
JavaScript

(function(){"use strict";function Se(t,e){return function(){return t.apply(e,arguments)}}const{toString:ct}=Object.prototype,{getPrototypeOf:le}=Object,{iterator:Z,toStringTag:Te}=Symbol,Q=(t=>e=>{const n=ct.call(e);return t[n]||(t[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),x=t=>(t=t.toLowerCase(),e=>Q(e)===t),G=t=>e=>typeof e===t,{isArray:q}=Array,z=G("undefined");function J(t){return t!==null&&!z(t)&&t.constructor!==null&&!z(t.constructor)&&O(t.constructor.isBuffer)&&t.constructor.isBuffer(t)}const Re=x("ArrayBuffer");function lt(t){let e;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?e=ArrayBuffer.isView(t):e=t&&t.buffer&&Re(t.buffer),e}const ut=G("string"),O=G("function"),ke=G("number"),V=t=>t!==null&&typeof t=="object",dt=t=>t===!0||t===!1,Y=t=>{if(Q(t)!=="object")return!1;const e=le(t);return(e===null||e===Object.prototype||Object.getPrototypeOf(e)===null)&&!(Te in t)&&!(Z in t)},ft=t=>{if(!V(t)||J(t))return!1;try{return Object.keys(t).length===0&&Object.getPrototypeOf(t)===Object.prototype}catch{return!1}},ht=x("Date"),pt=x("File"),mt=x("Blob"),wt=x("FileList"),yt=t=>V(t)&&O(t.pipe),gt=t=>{let e;return t&&(typeof FormData=="function"&&t instanceof FormData||O(t.append)&&((e=Q(t))==="formdata"||e==="object"&&O(t.toString)&&t.toString()==="[object FormData]"))},bt=x("URLSearchParams"),[Et,vt,St,Tt]=["ReadableStream","Request","Response","Headers"].map(x),Rt=t=>t.trim?t.trim():t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function K(t,e,{allOwnKeys:n=!1}={}){if(t===null||typeof t>"u")return;let r,s;if(typeof t!="object"&&(t=[t]),q(t))for(r=0,s=t.length;r<s;r++)e.call(null,t[r],r,t);else{if(J(t))return;const i=n?Object.getOwnPropertyNames(t):Object.keys(t),o=i.length;let c;for(r=0;r<o;r++)c=i[r],e.call(null,t[c],c,t)}}function Pe(t,e){if(J(t))return null;e=e.toLowerCase();const n=Object.keys(t);let r=n.length,s;for(;r-- >0;)if(s=n[r],e===s.toLowerCase())return s;return null}const F=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Oe=t=>!z(t)&&t!==F;function ue(){const{caseless:t}=Oe(this)&&this||{},e={},n=(r,s)=>{const i=t&&Pe(e,s)||s;Y(e[i])&&Y(r)?e[i]=ue(e[i],r):Y(r)?e[i]=ue({},r):q(r)?e[i]=r.slice():e[i]=r};for(let r=0,s=arguments.length;r<s;r++)arguments[r]&&K(arguments[r],n);return e}const kt=(t,e,n,{allOwnKeys:r}={})=>(K(e,(s,i)=>{n&&O(s)?t[i]=Se(s,n):t[i]=s},{allOwnKeys:r}),t),Pt=t=>(t.charCodeAt(0)===65279&&(t=t.slice(1)),t),Ot=(t,e,n,r)=>{t.prototype=Object.create(e.prototype,r),t.prototype.constructor=t,Object.defineProperty(t,"super",{value:e.prototype}),n&&Object.assign(t.prototype,n)},At=(t,e,n,r)=>{let s,i,o;const c={};if(e=e||{},t==null)return e;do{for(s=Object.getOwnPropertyNames(t),i=s.length;i-- >0;)o=s[i],(!r||r(o,t,e))&&!c[o]&&(e[o]=t[o],c[o]=!0);t=n!==!1&&le(t)}while(t&&(!n||n(t,e))&&t!==Object.prototype);return e},_t=(t,e,n)=>{t=String(t),(n===void 0||n>t.length)&&(n=t.length),n-=e.length;const r=t.indexOf(e,n);return r!==-1&&r===n},Ct=t=>{if(!t)return null;if(q(t))return t;let e=t.length;if(!ke(e))return null;const n=new Array(e);for(;e-- >0;)n[e]=t[e];return n},xt=(t=>e=>t&&e instanceof t)(typeof Uint8Array<"u"&&le(Uint8Array)),Nt=(t,e)=>{const r=(t&&t[Z]).call(t);let s;for(;(s=r.next())&&!s.done;){const i=s.value;e.call(t,i[0],i[1])}},It=(t,e)=>{let n;const r=[];for(;(n=t.exec(e))!==null;)r.push(n);return r},Lt=x("HTMLFormElement"),Bt=t=>t.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,r,s){return r.toUpperCase()+s}),Ae=(({hasOwnProperty:t})=>(e,n)=>t.call(e,n))(Object.prototype),Ft=x("RegExp"),_e=(t,e)=>{const n=Object.getOwnPropertyDescriptors(t),r={};K(n,(s,i)=>{let o;(o=e(s,i,t))!==!1&&(r[i]=o||s)}),Object.defineProperties(t,r)},Ut=t=>{_e(t,(e,n)=>{if(O(t)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const r=t[n];if(O(r)){if(e.enumerable=!1,"writable"in e){e.writable=!1;return}e.set||(e.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Dt=(t,e)=>{const n={},r=s=>{s.forEach(i=>{n[i]=!0})};return q(t)?r(t):r(String(t).split(e)),n},Mt=()=>{},qt=(t,e)=>t!=null&&Number.isFinite(t=+t)?t:e;function jt(t){return!!(t&&O(t.append)&&t[Te]==="FormData"&&t[Z])}const Ht=t=>{const e=new Array(10),n=(r,s)=>{if(V(r)){if(e.indexOf(r)>=0)return;if(J(r))return r;if(!("toJSON"in r)){e[s]=r;const i=q(r)?[]:{};return K(r,(o,c)=>{const d=n(o,s+1);!z(d)&&(i[c]=d)}),e[s]=void 0,i}}return r};return n(t,0)},$t=x("AsyncFunction"),zt=t=>t&&(V(t)||O(t))&&O(t.then)&&O(t.catch),Ce=((t,e)=>t?setImmediate:e?((n,r)=>(F.addEventListener("message",({source:s,data:i})=>{s===F&&i===n&&r.length&&r.shift()()},!1),s=>{r.push(s),F.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",O(F.postMessage)),Jt=typeof queueMicrotask<"u"?queueMicrotask.bind(F):typeof process<"u"&&process.nextTick||Ce,a={isArray:q,isArrayBuffer:Re,isBuffer:J,isFormData:gt,isArrayBufferView:lt,isString:ut,isNumber:ke,isBoolean:dt,isObject:V,isPlainObject:Y,isEmptyObject:ft,isReadableStream:Et,isRequest:vt,isResponse:St,isHeaders:Tt,isUndefined:z,isDate:ht,isFile:pt,isBlob:mt,isRegExp:Ft,isFunction:O,isStream:yt,isURLSearchParams:bt,isTypedArray:xt,isFileList:wt,forEach:K,merge:ue,extend:kt,trim:Rt,stripBOM:Pt,inherits:Ot,toFlatObject:At,kindOf:Q,kindOfTest:x,endsWith:_t,toArray:Ct,forEachEntry:Nt,matchAll:It,isHTMLForm:Lt,hasOwnProperty:Ae,hasOwnProp:Ae,reduceDescriptors:_e,freezeMethods:Ut,toObjectSet:Dt,toCamelCase:Bt,noop:Mt,toFiniteNumber:qt,findKey:Pe,global:F,isContextDefined:Oe,isSpecCompliantForm:jt,toJSONObject:Ht,isAsyncFn:$t,isThenable:zt,setImmediate:Ce,asap:Jt,isIterable:t=>t!=null&&O(t[Z])};function m(t,e,n,r,s){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=t,this.name="AxiosError",e&&(this.code=e),n&&(this.config=n),r&&(this.request=r),s&&(this.response=s,this.status=s.status?s.status:null)}a.inherits(m,Error,{toJSON:function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:a.toJSONObject(this.config),code:this.code,status:this.status}}});const xe=m.prototype,Ne={};["ERR_BAD_OPTION_VALUE","ERR_BAD_OPTION","ECONNABORTED","ETIMEDOUT","ERR_NETWORK","ERR_FR_TOO_MANY_REDIRECTS","ERR_DEPRECATED","ERR_BAD_RESPONSE","ERR_BAD_REQUEST","ERR_CANCELED","ERR_NOT_SUPPORT","ERR_INVALID_URL"].forEach(t=>{Ne[t]={value:t}}),Object.defineProperties(m,Ne),Object.defineProperty(xe,"isAxiosError",{value:!0}),m.from=(t,e,n,r,s,i)=>{const o=Object.create(xe);return a.toFlatObject(t,o,function(d){return d!==Error.prototype},c=>c!=="isAxiosError"),m.call(o,t.message,e,n,r,s),o.cause=t,o.name=t.name,i&&Object.assign(o,i),o};const Vt=null;function de(t){return a.isPlainObject(t)||a.isArray(t)}function Ie(t){return a.endsWith(t,"[]")?t.slice(0,-2):t}function Le(t,e,n){return t?t.concat(e).map(function(s,i){return s=Ie(s),!n&&i?"["+s+"]":s}).join(n?".":""):e}function Kt(t){return a.isArray(t)&&!t.some(de)}const Xt=a.toFlatObject(a,{},null,function(e){return/^is[A-Z]/.test(e)});function ee(t,e,n){if(!a.isObject(t))throw new TypeError("target must be an object");e=e||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(y,p){return!a.isUndefined(p[y])});const r=n.metaTokens,s=n.visitor||u,i=n.dots,o=n.indexes,d=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(e);if(!a.isFunction(s))throw new TypeError("visitor must be a function");function l(h){if(h===null)return"";if(a.isDate(h))return h.toISOString();if(a.isBoolean(h))return h.toString();if(!d&&a.isBlob(h))throw new m("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(h)||a.isTypedArray(h)?d&&typeof Blob=="function"?new Blob([h]):Buffer.from(h):h}function u(h,y,p){let v=h;if(h&&!p&&typeof h=="object"){if(a.endsWith(y,"{}"))y=r?y:y.slice(0,-2),h=JSON.stringify(h);else if(a.isArray(h)&&Kt(h)||(a.isFileList(h)||a.endsWith(y,"[]"))&&(v=a.toArray(h)))return y=Ie(y),v.forEach(function(k,I){!(a.isUndefined(k)||k===null)&&e.append(o===!0?Le([y],I,i):o===null?y:y+"[]",l(k))}),!1}return de(h)?!0:(e.append(Le(p,y,i),l(h)),!1)}const f=[],b=Object.assign(Xt,{defaultVisitor:u,convertValue:l,isVisitable:de});function S(h,y){if(!a.isUndefined(h)){if(f.indexOf(h)!==-1)throw Error("Circular reference detected in "+y.join("."));f.push(h),a.forEach(h,function(v,T){(!(a.isUndefined(v)||v===null)&&s.call(e,v,a.isString(T)?T.trim():T,y,b))===!0&&S(v,y?y.concat(T):[T])}),f.pop()}}if(!a.isObject(t))throw new TypeError("data must be an object");return S(t),e}function Be(t){const e={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(t).replace(/[!'()~]|%20|%00/g,function(r){return e[r]})}function fe(t,e){this._pairs=[],t&&ee(t,this,e)}const Fe=fe.prototype;Fe.append=function(e,n){this._pairs.push([e,n])},Fe.toString=function(e){const n=e?function(r){return e.call(this,r,Be)}:Be;return this._pairs.map(function(s){return n(s[0])+"="+n(s[1])},"").join("&")};function Wt(t){return encodeURIComponent(t).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function Ue(t,e,n){if(!e)return t;const r=n&&n.encode||Wt;a.isFunction(n)&&(n={serialize:n});const s=n&&n.serialize;let i;if(s?i=s(e,n):i=a.isURLSearchParams(e)?e.toString():new fe(e,n).toString(r),i){const o=t.indexOf("#");o!==-1&&(t=t.slice(0,o)),t+=(t.indexOf("?")===-1?"?":"&")+i}return t}class De{constructor(){this.handlers=[]}use(e,n,r){return this.handlers.push({fulfilled:e,rejected:n,synchronous:r?r.synchronous:!1,runWhen:r?r.runWhen:null}),this.handlers.length-1}eject(e){this.handlers[e]&&(this.handlers[e]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(e){a.forEach(this.handlers,function(r){r!==null&&e(r)})}}const Me={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Zt={isBrowser:!0,classes:{URLSearchParams:typeof URLSearchParams<"u"?URLSearchParams:fe,FormData:typeof FormData<"u"?FormData:null,Blob:typeof Blob<"u"?Blob:null},protocols:["http","https","file","blob","url","data"]},he=typeof window<"u"&&typeof document<"u",pe=typeof navigator=="object"&&navigator||void 0,Qt=he&&(!pe||["ReactNative","NativeScript","NS"].indexOf(pe.product)<0),Gt=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Yt=he&&window.location.href||"http://localhost",P={...Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:he,hasStandardBrowserEnv:Qt,hasStandardBrowserWebWorkerEnv:Gt,navigator:pe,origin:Yt},Symbol.toStringTag,{value:"Module"})),...Zt};function en(t,e){return ee(t,new P.classes.URLSearchParams,{visitor:function(n,r,s,i){return P.isNode&&a.isBuffer(n)?(this.append(r,n.toString("base64")),!1):i.defaultVisitor.apply(this,arguments)},...e})}function tn(t){return a.matchAll(/\w+|\[(\w*)]/g,t).map(e=>e[0]==="[]"?"":e[1]||e[0])}function nn(t){const e={},n=Object.keys(t);let r;const s=n.length;let i;for(r=0;r<s;r++)i=n[r],e[i]=t[i];return e}function qe(t){function e(n,r,s,i){let o=n[i++];if(o==="__proto__")return!0;const c=Number.isFinite(+o),d=i>=n.length;return o=!o&&a.isArray(s)?s.length:o,d?(a.hasOwnProp(s,o)?s[o]=[s[o],r]:s[o]=r,!c):((!s[o]||!a.isObject(s[o]))&&(s[o]=[]),e(n,r,s[o],i)&&a.isArray(s[o])&&(s[o]=nn(s[o])),!c)}if(a.isFormData(t)&&a.isFunction(t.entries)){const n={};return a.forEachEntry(t,(r,s)=>{e(tn(r),s,n,0)}),n}return null}function rn(t,e,n){if(a.isString(t))try{return(e||JSON.parse)(t),a.trim(t)}catch(r){if(r.name!=="SyntaxError")throw r}return(n||JSON.stringify)(t)}const X={transitional:Me,adapter:["xhr","http","fetch"],transformRequest:[function(e,n){const r=n.getContentType()||"",s=r.indexOf("application/json")>-1,i=a.isObject(e);if(i&&a.isHTMLForm(e)&&(e=new FormData(e)),a.isFormData(e))return s?JSON.stringify(qe(e)):e;if(a.isArrayBuffer(e)||a.isBuffer(e)||a.isStream(e)||a.isFile(e)||a.isBlob(e)||a.isReadableStream(e))return e;if(a.isArrayBufferView(e))return e.buffer;if(a.isURLSearchParams(e))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),e.toString();let c;if(i){if(r.indexOf("application/x-www-form-urlencoded")>-1)return en(e,this.formSerializer).toString();if((c=a.isFileList(e))||r.indexOf("multipart/form-data")>-1){const d=this.env&&this.env.FormData;return ee(c?{"files[]":e}:e,d&&new d,this.formSerializer)}}return i||s?(n.setContentType("application/json",!1),rn(e)):e}],transformResponse:[function(e){const n=this.transitional||X.transitional,r=n&&n.forcedJSONParsing,s=this.responseType==="json";if(a.isResponse(e)||a.isReadableStream(e))return e;if(e&&a.isString(e)&&(r&&!this.responseType||s)){const o=!(n&&n.silentJSONParsing)&&s;try{return JSON.parse(e)}catch(c){if(o)throw c.name==="SyntaxError"?m.from(c,m.ERR_BAD_RESPONSE,this,null,this.response):c}}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:P.classes.FormData,Blob:P.classes.Blob},validateStatus:function(e){return e>=200&&e<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],t=>{X.headers[t]={}});const sn=a.toObjectSet(["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"]),on=t=>{const e={};let n,r,s;return t&&t.split(`
`).forEach(function(o){s=o.indexOf(":"),n=o.substring(0,s).trim().toLowerCase(),r=o.substring(s+1).trim(),!(!n||e[n]&&sn[n])&&(n==="set-cookie"?e[n]?e[n].push(r):e[n]=[r]:e[n]=e[n]?e[n]+", "+r:r)}),e},je=Symbol("internals");function W(t){return t&&String(t).trim().toLowerCase()}function te(t){return t===!1||t==null?t:a.isArray(t)?t.map(te):String(t)}function an(t){const e=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let r;for(;r=n.exec(t);)e[r[1]]=r[2];return e}const cn=t=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(t.trim());function me(t,e,n,r,s){if(a.isFunction(r))return r.call(this,e,n);if(s&&(e=n),!!a.isString(e)){if(a.isString(r))return e.indexOf(r)!==-1;if(a.isRegExp(r))return r.test(e)}}function ln(t){return t.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(e,n,r)=>n.toUpperCase()+r)}function un(t,e){const n=a.toCamelCase(" "+e);["get","set","has"].forEach(r=>{Object.defineProperty(t,r+n,{value:function(s,i,o){return this[r].call(this,e,s,i,o)},configurable:!0})})}let A=class{constructor(e){e&&this.set(e)}set(e,n,r){const s=this;function i(c,d,l){const u=W(d);if(!u)throw new Error("header name must be a non-empty string");const f=a.findKey(s,u);(!f||s[f]===void 0||l===!0||l===void 0&&s[f]!==!1)&&(s[f||d]=te(c))}const o=(c,d)=>a.forEach(c,(l,u)=>i(l,u,d));if(a.isPlainObject(e)||e instanceof this.constructor)o(e,n);else if(a.isString(e)&&(e=e.trim())&&!cn(e))o(on(e),n);else if(a.isObject(e)&&a.isIterable(e)){let c={},d,l;for(const u of e){if(!a.isArray(u))throw TypeError("Object iterator must return a key-value pair");c[l=u[0]]=(d=c[l])?a.isArray(d)?[...d,u[1]]:[d,u[1]]:u[1]}o(c,n)}else e!=null&&i(n,e,r);return this}get(e,n){if(e=W(e),e){const r=a.findKey(this,e);if(r){const s=this[r];if(!n)return s;if(n===!0)return an(s);if(a.isFunction(n))return n.call(this,s,r);if(a.isRegExp(n))return n.exec(s);throw new TypeError("parser must be boolean|regexp|function")}}}has(e,n){if(e=W(e),e){const r=a.findKey(this,e);return!!(r&&this[r]!==void 0&&(!n||me(this,this[r],r,n)))}return!1}delete(e,n){const r=this;let s=!1;function i(o){if(o=W(o),o){const c=a.findKey(r,o);c&&(!n||me(r,r[c],c,n))&&(delete r[c],s=!0)}}return a.isArray(e)?e.forEach(i):i(e),s}clear(e){const n=Object.keys(this);let r=n.length,s=!1;for(;r--;){const i=n[r];(!e||me(this,this[i],i,e,!0))&&(delete this[i],s=!0)}return s}normalize(e){const n=this,r={};return a.forEach(this,(s,i)=>{const o=a.findKey(r,i);if(o){n[o]=te(s),delete n[i];return}const c=e?ln(i):String(i).trim();c!==i&&delete n[i],n[c]=te(s),r[c]=!0}),this}concat(...e){return this.constructor.concat(this,...e)}toJSON(e){const n=Object.create(null);return a.forEach(this,(r,s)=>{r!=null&&r!==!1&&(n[s]=e&&a.isArray(r)?r.join(", "):r)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([e,n])=>e+": "+n).join(`
`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(e){return e instanceof this?e:new this(e)}static concat(e,...n){const r=new this(e);return n.forEach(s=>r.set(s)),r}static accessor(e){const r=(this[je]=this[je]={accessors:{}}).accessors,s=this.prototype;function i(o){const c=W(o);r[c]||(un(s,o),r[c]=!0)}return a.isArray(e)?e.forEach(i):i(e),this}};A.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]),a.reduceDescriptors(A.prototype,({value:t},e)=>{let n=e[0].toUpperCase()+e.slice(1);return{get:()=>t,set(r){this[n]=r}}}),a.freezeMethods(A);function we(t,e){const n=this||X,r=e||n,s=A.from(r.headers);let i=r.data;return a.forEach(t,function(c){i=c.call(n,i,s.normalize(),e?e.status:void 0)}),s.normalize(),i}function He(t){return!!(t&&t.__CANCEL__)}function j(t,e,n){m.call(this,t??"canceled",m.ERR_CANCELED,e,n),this.name="CanceledError"}a.inherits(j,m,{__CANCEL__:!0});function $e(t,e,n){const r=n.config.validateStatus;!n.status||!r||r(n.status)?t(n):e(new m("Request failed with status code "+n.status,[m.ERR_BAD_REQUEST,m.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function dn(t){const e=/^([-+\w]{1,25})(:?\/\/|:)/.exec(t);return e&&e[1]||""}function fn(t,e){t=t||10;const n=new Array(t),r=new Array(t);let s=0,i=0,o;return e=e!==void 0?e:1e3,function(d){const l=Date.now(),u=r[i];o||(o=l),n[s]=d,r[s]=l;let f=i,b=0;for(;f!==s;)b+=n[f++],f=f%t;if(s=(s+1)%t,s===i&&(i=(i+1)%t),l-o<e)return;const S=u&&l-u;return S?Math.round(b*1e3/S):void 0}}function hn(t,e){let n=0,r=1e3/e,s,i;const o=(l,u=Date.now())=>{n=u,s=null,i&&(clearTimeout(i),i=null),t(...l)};return[(...l)=>{const u=Date.now(),f=u-n;f>=r?o(l,u):(s=l,i||(i=setTimeout(()=>{i=null,o(s)},r-f)))},()=>s&&o(s)]}const ne=(t,e,n=3)=>{let r=0;const s=fn(50,250);return hn(i=>{const o=i.loaded,c=i.lengthComputable?i.total:void 0,d=o-r,l=s(d),u=o<=c;r=o;const f={loaded:o,total:c,progress:c?o/c:void 0,bytes:d,rate:l||void 0,estimated:l&&c&&u?(c-o)/l:void 0,event:i,lengthComputable:c!=null,[e?"download":"upload"]:!0};t(f)},n)},ze=(t,e)=>{const n=t!=null;return[r=>e[0]({lengthComputable:n,total:t,loaded:r}),e[1]]},Je=t=>(...e)=>a.asap(()=>t(...e)),pn=P.hasStandardBrowserEnv?((t,e)=>n=>(n=new URL(n,P.origin),t.protocol===n.protocol&&t.host===n.host&&(e||t.port===n.port)))(new URL(P.origin),P.navigator&&/(msie|trident)/i.test(P.navigator.userAgent)):()=>!0,mn=P.hasStandardBrowserEnv?{write(t,e,n,r,s,i){const o=[t+"="+encodeURIComponent(e)];a.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),a.isString(r)&&o.push("path="+r),a.isString(s)&&o.push("domain="+s),i===!0&&o.push("secure"),document.cookie=o.join("; ")},read(t){const e=document.cookie.match(new RegExp("(^|;\\s*)("+t+")=([^;]*)"));return e?decodeURIComponent(e[3]):null},remove(t){this.write(t,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function wn(t){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(t)}function yn(t,e){return e?t.replace(/\/?\/$/,"")+"/"+e.replace(/^\/+/,""):t}function Ve(t,e,n){let r=!wn(e);return t&&(r||n==!1)?yn(t,e):e}const Ke=t=>t instanceof A?{...t}:t;function U(t,e){e=e||{};const n={};function r(l,u,f,b){return a.isPlainObject(l)&&a.isPlainObject(u)?a.merge.call({caseless:b},l,u):a.isPlainObject(u)?a.merge({},u):a.isArray(u)?u.slice():u}function s(l,u,f,b){if(a.isUndefined(u)){if(!a.isUndefined(l))return r(void 0,l,f,b)}else return r(l,u,f,b)}function i(l,u){if(!a.isUndefined(u))return r(void 0,u)}function o(l,u){if(a.isUndefined(u)){if(!a.isUndefined(l))return r(void 0,l)}else return r(void 0,u)}function c(l,u,f){if(f in e)return r(l,u);if(f in t)return r(void 0,l)}const d={url:i,method:i,data:i,baseURL:o,transformRequest:o,transformResponse:o,paramsSerializer:o,timeout:o,timeoutMessage:o,withCredentials:o,withXSRFToken:o,adapter:o,responseType:o,xsrfCookieName:o,xsrfHeaderName:o,onUploadProgress:o,onDownloadProgress:o,decompress:o,maxContentLength:o,maxBodyLength:o,beforeRedirect:o,transport:o,httpAgent:o,httpsAgent:o,cancelToken:o,socketPath:o,responseEncoding:o,validateStatus:c,headers:(l,u,f)=>s(Ke(l),Ke(u),f,!0)};return a.forEach(Object.keys({...t,...e}),function(u){const f=d[u]||s,b=f(t[u],e[u],u);a.isUndefined(b)&&f!==c||(n[u]=b)}),n}const Xe=t=>{const e=U({},t);let{data:n,withXSRFToken:r,xsrfHeaderName:s,xsrfCookieName:i,headers:o,auth:c}=e;e.headers=o=A.from(o),e.url=Ue(Ve(e.baseURL,e.url,e.allowAbsoluteUrls),t.params,t.paramsSerializer),c&&o.set("Authorization","Basic "+btoa((c.username||"")+":"+(c.password?unescape(encodeURIComponent(c.password)):"")));let d;if(a.isFormData(n)){if(P.hasStandardBrowserEnv||P.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((d=o.getContentType())!==!1){const[l,...u]=d?d.split(";").map(f=>f.trim()).filter(Boolean):[];o.setContentType([l||"multipart/form-data",...u].join("; "))}}if(P.hasStandardBrowserEnv&&(r&&a.isFunction(r)&&(r=r(e)),r||r!==!1&&pn(e.url))){const l=s&&i&&mn.read(i);l&&o.set(s,l)}return e},gn=typeof XMLHttpRequest<"u"&&function(t){return new Promise(function(n,r){const s=Xe(t);let i=s.data;const o=A.from(s.headers).normalize();let{responseType:c,onUploadProgress:d,onDownloadProgress:l}=s,u,f,b,S,h;function y(){S&&S(),h&&h(),s.cancelToken&&s.cancelToken.unsubscribe(u),s.signal&&s.signal.removeEventListener("abort",u)}let p=new XMLHttpRequest;p.open(s.method.toUpperCase(),s.url,!0),p.timeout=s.timeout;function v(){if(!p)return;const k=A.from("getAllResponseHeaders"in p&&p.getAllResponseHeaders()),_={data:!c||c==="text"||c==="json"?p.responseText:p.response,status:p.status,statusText:p.statusText,headers:k,config:t,request:p};$e(function(M){n(M),y()},function(M){r(M),y()},_),p=null}"onloadend"in p?p.onloadend=v:p.onreadystatechange=function(){!p||p.readyState!==4||p.status===0&&!(p.responseURL&&p.responseURL.indexOf("file:")===0)||setTimeout(v)},p.onabort=function(){p&&(r(new m("Request aborted",m.ECONNABORTED,t,p)),p=null)},p.onerror=function(){r(new m("Network Error",m.ERR_NETWORK,t,p)),p=null},p.ontimeout=function(){let I=s.timeout?"timeout of "+s.timeout+"ms exceeded":"timeout exceeded";const _=s.transitional||Me;s.timeoutErrorMessage&&(I=s.timeoutErrorMessage),r(new m(I,_.clarifyTimeoutError?m.ETIMEDOUT:m.ECONNABORTED,t,p)),p=null},i===void 0&&o.setContentType(null),"setRequestHeader"in p&&a.forEach(o.toJSON(),function(I,_){p.setRequestHeader(_,I)}),a.isUndefined(s.withCredentials)||(p.withCredentials=!!s.withCredentials),c&&c!=="json"&&(p.responseType=s.responseType),l&&([b,h]=ne(l,!0),p.addEventListener("progress",b)),d&&p.upload&&([f,S]=ne(d),p.upload.addEventListener("progress",f),p.upload.addEventListener("loadend",S)),(s.cancelToken||s.signal)&&(u=k=>{p&&(r(!k||k.type?new j(null,t,p):k),p.abort(),p=null)},s.cancelToken&&s.cancelToken.subscribe(u),s.signal&&(s.signal.aborted?u():s.signal.addEventListener("abort",u)));const T=dn(s.url);if(T&&P.protocols.indexOf(T)===-1){r(new m("Unsupported protocol "+T+":",m.ERR_BAD_REQUEST,t));return}p.send(i||null)})},bn=(t,e)=>{const{length:n}=t=t?t.filter(Boolean):[];if(e||n){let r=new AbortController,s;const i=function(l){if(!s){s=!0,c();const u=l instanceof Error?l:this.reason;r.abort(u instanceof m?u:new j(u instanceof Error?u.message:u))}};let o=e&&setTimeout(()=>{o=null,i(new m(`timeout ${e} of ms exceeded`,m.ETIMEDOUT))},e);const c=()=>{t&&(o&&clearTimeout(o),o=null,t.forEach(l=>{l.unsubscribe?l.unsubscribe(i):l.removeEventListener("abort",i)}),t=null)};t.forEach(l=>l.addEventListener("abort",i));const{signal:d}=r;return d.unsubscribe=()=>a.asap(c),d}},En=function*(t,e){let n=t.byteLength;if(n<e){yield t;return}let r=0,s;for(;r<n;)s=r+e,yield t.slice(r,s),r=s},vn=async function*(t,e){for await(const n of Sn(t))yield*En(n,e)},Sn=async function*(t){if(t[Symbol.asyncIterator]){yield*t;return}const e=t.getReader();try{for(;;){const{done:n,value:r}=await e.read();if(n)break;yield r}}finally{await e.cancel()}},We=(t,e,n,r)=>{const s=vn(t,e);let i=0,o,c=d=>{o||(o=!0,r&&r(d))};return new ReadableStream({async pull(d){try{const{done:l,value:u}=await s.next();if(l){c(),d.close();return}let f=u.byteLength;if(n){let b=i+=f;n(b)}d.enqueue(new Uint8Array(u))}catch(l){throw c(l),l}},cancel(d){return c(d),s.return()}},{highWaterMark:2})},re=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Ze=re&&typeof ReadableStream=="function",Tn=re&&(typeof TextEncoder=="function"?(t=>e=>t.encode(e))(new TextEncoder):async t=>new Uint8Array(await new Response(t).arrayBuffer())),Qe=(t,...e)=>{try{return!!t(...e)}catch{return!1}},Rn=Ze&&Qe(()=>{let t=!1;const e=new Request(P.origin,{body:new ReadableStream,method:"POST",get duplex(){return t=!0,"half"}}).headers.has("Content-Type");return t&&!e}),Ge=64*1024,ye=Ze&&Qe(()=>a.isReadableStream(new Response("").body)),se={stream:ye&&(t=>t.body)};re&&(t=>{["text","arrayBuffer","blob","formData","stream"].forEach(e=>{!se[e]&&(se[e]=a.isFunction(t[e])?n=>n[e]():(n,r)=>{throw new m(`Response type '${e}' is not supported`,m.ERR_NOT_SUPPORT,r)})})})(new Response);const kn=async t=>{if(t==null)return 0;if(a.isBlob(t))return t.size;if(a.isSpecCompliantForm(t))return(await new Request(P.origin,{method:"POST",body:t}).arrayBuffer()).byteLength;if(a.isArrayBufferView(t)||a.isArrayBuffer(t))return t.byteLength;if(a.isURLSearchParams(t)&&(t=t+""),a.isString(t))return(await Tn(t)).byteLength},Pn=async(t,e)=>{const n=a.toFiniteNumber(t.getContentLength());return n??kn(e)},ge={http:Vt,xhr:gn,fetch:re&&(async t=>{let{url:e,method:n,data:r,signal:s,cancelToken:i,timeout:o,onDownloadProgress:c,onUploadProgress:d,responseType:l,headers:u,withCredentials:f="same-origin",fetchOptions:b}=Xe(t);l=l?(l+"").toLowerCase():"text";let S=bn([s,i&&i.toAbortSignal()],o),h;const y=S&&S.unsubscribe&&(()=>{S.unsubscribe()});let p;try{if(d&&Rn&&n!=="get"&&n!=="head"&&(p=await Pn(u,r))!==0){let _=new Request(e,{method:"POST",body:r,duplex:"half"}),B;if(a.isFormData(r)&&(B=_.headers.get("content-type"))&&u.setContentType(B),_.body){const[M,ce]=ze(p,ne(Je(d)));r=We(_.body,Ge,M,ce)}}a.isString(f)||(f=f?"include":"omit");const v="credentials"in Request.prototype;h=new Request(e,{...b,signal:S,method:n.toUpperCase(),headers:u.normalize().toJSON(),body:r,duplex:"half",credentials:v?f:void 0});let T=await fetch(h,b);const k=ye&&(l==="stream"||l==="response");if(ye&&(c||k&&y)){const _={};["status","statusText","headers"].forEach(ot=>{_[ot]=T[ot]});const B=a.toFiniteNumber(T.headers.get("content-length")),[M,ce]=c&&ze(B,ne(Je(c),!0))||[];T=new Response(We(T.body,Ge,M,()=>{ce&&ce(),y&&y()}),_)}l=l||"text";let I=await se[a.findKey(se,l)||"text"](T,t);return!k&&y&&y(),await new Promise((_,B)=>{$e(_,B,{data:I,headers:A.from(T.headers),status:T.status,statusText:T.statusText,config:t,request:h})})}catch(v){throw y&&y(),v&&v.name==="TypeError"&&/Load failed|fetch/i.test(v.message)?Object.assign(new m("Network Error",m.ERR_NETWORK,t,h),{cause:v.cause||v}):m.from(v,v&&v.code,t,h)}})};a.forEach(ge,(t,e)=>{if(t){try{Object.defineProperty(t,"name",{value:e})}catch{}Object.defineProperty(t,"adapterName",{value:e})}});const Ye=t=>`- ${t}`,On=t=>a.isFunction(t)||t===null||t===!1,et={getAdapter:t=>{t=a.isArray(t)?t:[t];const{length:e}=t;let n,r;const s={};for(let i=0;i<e;i++){n=t[i];let o;if(r=n,!On(n)&&(r=ge[(o=String(n)).toLowerCase()],r===void 0))throw new m(`Unknown adapter '${o}'`);if(r)break;s[o||"#"+i]=r}if(!r){const i=Object.entries(s).map(([c,d])=>`adapter ${c} `+(d===!1?"is not supported by the environment":"is not available in the build"));let o=e?i.length>1?`since :
`+i.map(Ye).join(`
`):" "+Ye(i[0]):"as no adapter specified";throw new m("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return r},adapters:ge};function be(t){if(t.cancelToken&&t.cancelToken.throwIfRequested(),t.signal&&t.signal.aborted)throw new j(null,t)}function tt(t){return be(t),t.headers=A.from(t.headers),t.data=we.call(t,t.transformRequest),["post","put","patch"].indexOf(t.method)!==-1&&t.headers.setContentType("application/x-www-form-urlencoded",!1),et.getAdapter(t.adapter||X.adapter)(t).then(function(r){return be(t),r.data=we.call(t,t.transformResponse,r),r.headers=A.from(r.headers),r},function(r){return He(r)||(be(t),r&&r.response&&(r.response.data=we.call(t,t.transformResponse,r.response),r.response.headers=A.from(r.response.headers))),Promise.reject(r)})}const nt="1.11.0",ie={};["object","boolean","number","function","string","symbol"].forEach((t,e)=>{ie[t]=function(r){return typeof r===t||"a"+(e<1?"n ":" ")+t}});const rt={};ie.transitional=function(e,n,r){function s(i,o){return"[Axios v"+nt+"] Transitional option '"+i+"'"+o+(r?". "+r:"")}return(i,o,c)=>{if(e===!1)throw new m(s(o," has been removed"+(n?" in "+n:"")),m.ERR_DEPRECATED);return n&&!rt[o]&&(rt[o]=!0,console.warn(s(o," has been deprecated since v"+n+" and will be removed in the near future"))),e?e(i,o,c):!0}},ie.spelling=function(e){return(n,r)=>(console.warn(`${r} is likely a misspelling of ${e}`),!0)};function An(t,e,n){if(typeof t!="object")throw new m("options must be an object",m.ERR_BAD_OPTION_VALUE);const r=Object.keys(t);let s=r.length;for(;s-- >0;){const i=r[s],o=e[i];if(o){const c=t[i],d=c===void 0||o(c,i,t);if(d!==!0)throw new m("option "+i+" must be "+d,m.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new m("Unknown option "+i,m.ERR_BAD_OPTION)}}const oe={assertOptions:An,validators:ie},N=oe.validators;let D=class{constructor(e){this.defaults=e||{},this.interceptors={request:new De,response:new De}}async request(e,n){try{return await this._request(e,n)}catch(r){if(r instanceof Error){let s={};Error.captureStackTrace?Error.captureStackTrace(s):s=new Error;const i=s.stack?s.stack.replace(/^.+\n/,""):"";try{r.stack?i&&!String(r.stack).endsWith(i.replace(/^.+\n.+\n/,""))&&(r.stack+=`
`+i):r.stack=i}catch{}}throw r}}_request(e,n){typeof e=="string"?(n=n||{},n.url=e):n=e||{},n=U(this.defaults,n);const{transitional:r,paramsSerializer:s,headers:i}=n;r!==void 0&&oe.assertOptions(r,{silentJSONParsing:N.transitional(N.boolean),forcedJSONParsing:N.transitional(N.boolean),clarifyTimeoutError:N.transitional(N.boolean)},!1),s!=null&&(a.isFunction(s)?n.paramsSerializer={serialize:s}:oe.assertOptions(s,{encode:N.function,serialize:N.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),oe.assertOptions(n,{baseUrl:N.spelling("baseURL"),withXsrfToken:N.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=i&&a.merge(i.common,i[n.method]);i&&a.forEach(["delete","get","head","post","put","patch","common"],h=>{delete i[h]}),n.headers=A.concat(o,i);const c=[];let d=!0;this.interceptors.request.forEach(function(y){typeof y.runWhen=="function"&&y.runWhen(n)===!1||(d=d&&y.synchronous,c.unshift(y.fulfilled,y.rejected))});const l=[];this.interceptors.response.forEach(function(y){l.push(y.fulfilled,y.rejected)});let u,f=0,b;if(!d){const h=[tt.bind(this),void 0];for(h.unshift(...c),h.push(...l),b=h.length,u=Promise.resolve(n);f<b;)u=u.then(h[f++],h[f++]);return u}b=c.length;let S=n;for(f=0;f<b;){const h=c[f++],y=c[f++];try{S=h(S)}catch(p){y.call(this,p);break}}try{u=tt.call(this,S)}catch(h){return Promise.reject(h)}for(f=0,b=l.length;f<b;)u=u.then(l[f++],l[f++]);return u}getUri(e){e=U(this.defaults,e);const n=Ve(e.baseURL,e.url,e.allowAbsoluteUrls);return Ue(n,e.params,e.paramsSerializer)}};a.forEach(["delete","get","head","options"],function(e){D.prototype[e]=function(n,r){return this.request(U(r||{},{method:e,url:n,data:(r||{}).data}))}}),a.forEach(["post","put","patch"],function(e){function n(r){return function(i,o,c){return this.request(U(c||{},{method:e,headers:r?{"Content-Type":"multipart/form-data"}:{},url:i,data:o}))}}D.prototype[e]=n(),D.prototype[e+"Form"]=n(!0)});let _n=class at{constructor(e){if(typeof e!="function")throw new TypeError("executor must be a function.");let n;this.promise=new Promise(function(i){n=i});const r=this;this.promise.then(s=>{if(!r._listeners)return;let i=r._listeners.length;for(;i-- >0;)r._listeners[i](s);r._listeners=null}),this.promise.then=s=>{let i;const o=new Promise(c=>{r.subscribe(c),i=c}).then(s);return o.cancel=function(){r.unsubscribe(i)},o},e(function(i,o,c){r.reason||(r.reason=new j(i,o,c),n(r.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(e){if(this.reason){e(this.reason);return}this._listeners?this._listeners.push(e):this._listeners=[e]}unsubscribe(e){if(!this._listeners)return;const n=this._listeners.indexOf(e);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const e=new AbortController,n=r=>{e.abort(r)};return this.subscribe(n),e.signal.unsubscribe=()=>this.unsubscribe(n),e.signal}static source(){let e;return{token:new at(function(s){e=s}),cancel:e}}};function Cn(t){return function(n){return t.apply(null,n)}}function xn(t){return a.isObject(t)&&t.isAxiosError===!0}const Ee={Continue:100,SwitchingProtocols:101,Processing:102,EarlyHints:103,Ok:200,Created:201,Accepted:202,NonAuthoritativeInformation:203,NoContent:204,ResetContent:205,PartialContent:206,MultiStatus:207,AlreadyReported:208,ImUsed:226,MultipleChoices:300,MovedPermanently:301,Found:302,SeeOther:303,NotModified:304,UseProxy:305,Unused:306,TemporaryRedirect:307,PermanentRedirect:308,BadRequest:400,Unauthorized:401,PaymentRequired:402,Forbidden:403,NotFound:404,MethodNotAllowed:405,NotAcceptable:406,ProxyAuthenticationRequired:407,RequestTimeout:408,Conflict:409,Gone:410,LengthRequired:411,PreconditionFailed:412,PayloadTooLarge:413,UriTooLong:414,UnsupportedMediaType:415,RangeNotSatisfiable:416,ExpectationFailed:417,ImATeapot:418,MisdirectedRequest:421,UnprocessableEntity:422,Locked:423,FailedDependency:424,TooEarly:425,UpgradeRequired:426,PreconditionRequired:428,TooManyRequests:429,RequestHeaderFieldsTooLarge:431,UnavailableForLegalReasons:451,InternalServerError:500,NotImplemented:501,BadGateway:502,ServiceUnavailable:503,GatewayTimeout:504,HttpVersionNotSupported:505,VariantAlsoNegotiates:506,InsufficientStorage:507,LoopDetected:508,NotExtended:510,NetworkAuthenticationRequired:511};Object.entries(Ee).forEach(([t,e])=>{Ee[e]=t});function st(t){const e=new D(t),n=Se(D.prototype.request,e);return a.extend(n,D.prototype,e,{allOwnKeys:!0}),a.extend(n,e,null,{allOwnKeys:!0}),n.create=function(s){return st(U(t,s))},n}const E=st(X);E.Axios=D,E.CanceledError=j,E.CancelToken=_n,E.isCancel=He,E.VERSION=nt,E.toFormData=ee,E.AxiosError=m,E.Cancel=E.CanceledError,E.all=function(e){return Promise.all(e)},E.spread=Cn,E.isAxiosError=xn,E.mergeConfig=U,E.AxiosHeaders=A,E.formToJSON=t=>qe(a.isHTMLForm(t)?new FormData(t):t),E.getAdapter=et.getAdapter,E.HttpStatusCode=Ee,E.default=E;const{Axios:Jn,AxiosError:Vn,CanceledError:Kn,isCancel:Xn,CancelToken:Wn,VERSION:Zn,all:Qn,Cancel:Gn,isAxiosError:Yn,spread:er,toFormData:tr,AxiosHeaders:nr,HttpStatusCode:rr,formToJSON:sr,getAdapter:ir,mergeConfig:or}=E,ae=E.create({baseURL:"http://localhost:3000/",headers:{"Content-Type":"application/json",Authorization:"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczovL2ludC5pcHN1cHBseS5jb20uYXUvYXBpL2xvZ2luIiwiaWF0IjoxNzIxNjA5MTEzLCJleHAiOjMyMzUzMzcxMTMsIm5iZiI6MTcyMTYwOTExMywianRpIjoiWHpCZkZPc0ZJUlFxaEZvaiIsInN1YiI6MSwicHJ2IjoiYzhlZTFmYzg5ZTc3NWVjNGM3Mzg2NjdlNWJlMTdhNTkwYjZkNDBmYyJ9.kFFEPpdmNUp-kn_G3cIIc26bivO6tbfcvkpG9I8Im7M"}});class Nn{item_per_page=10;async index(e){const n={skip:0,limit:10,order:"updatedAt desc",where:{account:"prology_net",status:"Updated"}};return ae({method:"POST",data:{urlAPI:"/api/ebay-listing/listing-get-list",filter:{...n,...e,where:{...n.where,...e?.where}}}})}async get(e){return ae({method:"POST",data:{filter:{where:{account:"prology_net",condition:e.raw_condition,productModelCode:e.sku}},pageCurrent:"/ebaytools/listing-ebay",urlAPI:"/api/ebay-listing/get-image-listing"}})}async sync(e){return ae({url:"sync",method:"POST",data:e})}async getPublistedProducts(){return ae({url:"data"})}async apiRequest(e,n){return new Promise((r,s)=>{const i="req_"+Date.now()+"_"+Math.random();function o(c){c.data.type==="API_RESPONSE"&&c.data.requestId===i&&(window.removeEventListener("message",o),c.data.error?s(c.data.error):r(c.data.payload))}window.addEventListener("message",o),window.postMessage({type:"API_REQUEST",requestId:i,payload:n,fn:e},"*")})}}const H=new Nn;function L(t){return new Promise(e=>setTimeout(e,t))}function g(t,e){const n=Math.floor(Math.random()*(e-t+1))+t;return L(n)}class In{static ID_EXTENSION="ex-root"}class ve{items=[];storageKey="notiQueue";constructor(e){this.items=e,chrome.storage.onChanged.addListener((n,r)=>{r==="local"&&n[this.storageKey]&&(this.items=n[this.storageKey].newValue?JSON.parse(n[this.storageKey].newValue):[],console.log("Queue updated from another tab:",this.items))})}static async create(){const e="notiQueue",n=await chrome.storage.local.get(e),r=n[e]?JSON.parse(n[e]):[];return new ve(r)}async save(){await chrome.storage.local.set({[this.storageKey]:JSON.stringify(this.items)})}async enqueue(e){this.items.push(e),await this.save()}async dequeue(){const e=this.items.shift();return await this.save(),e}peek(){return this.items[0]}isEmpty(){return this.items.length===0}size(){return this.items.length}}class Ln{base64ToFile(e,n,r){const s=e.includes(",")?e.split(",")[1]:e,i=atob(s),o=new ArrayBuffer(i.length),c=new Uint8Array(o);for(let l=0;l<i.length;l++)c[l]=i.charCodeAt(l);const d=new Blob([o],{type:r});return new File([d],n,{type:r})}clickByPoint(e){const n=e.getBoundingClientRect(),r=n.left+n.width/2,s=n.top+n.height/2,i=document.elementFromPoint(r,s);i&&i.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window}))}async getElementByXPath(e,{retryCount:n=2,delay:r=100,xpathFallback:s}={}){return new Promise(i=>{let o=0,c=!1;const d=()=>{const l=document.evaluate(c&&s?s:e,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;if(l instanceof HTMLElement){i(l);return}o++,o<n?setTimeout(d,r):!c&&s?(c=!0,o=0,setTimeout(d,r)):i(null)};d()})}async imageUrlToBase64(e){const r=await(await fetch(e)).blob();return new Promise((s,i)=>{const o=new FileReader;o.onloadend=()=>{typeof o.result=="string"?s(o.result.split(",")[1]):i("Không thể đọc dữ liệu ảnh")},o.onerror=i,o.readAsDataURL(r)})}getImageExtension(e){try{const r=new URL(e).pathname.match(/\.([a-zA-Z0-9]+)$/);return r?r[1].toLowerCase():null}catch{const s=e.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return s?s[1].toLowerCase():null}}imageLocalToBase64(e){return new Promise((n,r)=>{try{const s=chrome.runtime.getURL(`${e}`);fetch(s).then(i=>i.blob()).then(i=>{const o=new FileReader;o.onloadend=()=>n(o.result),o.onerror=r,o.readAsDataURL(i)}).catch(r)}catch(s){r(s)}})}scrollToElement(e,n="smooth"){e&&e.scrollIntoView({behavior:n,block:"center",inline:"nearest"})}getElementPointCoores(e){if(!e)return null;const n=e.getBoundingClientRect(),r=n.left+n.width/2,s=n.top+n.height/2;return{x:r,y:s}}setInputValue(e,n){e&&(e.value=n,e.dispatchEvent(new Event("input",{bubbles:!0})),e.dispatchEvent(new Event("change",{bubbles:!0})))}writeToInput=async(e,n)=>{let r;if(typeof n=="string"?r=await this.getElementByXPath(n):r=n,!r)throw new Error("Xpath is not found with value: "+e);this.scrollToElement(r),this.clickByPoint(r),this.setInputValue(r,e)};pressEnter(e){if(!e)throw new Error("Textarea not found:",e);e.focus(),["keydown","keypress","keyup"].forEach(n=>{e.dispatchEvent(new KeyboardEvent(n,{key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:!0,cancelable:!0}))})}findNestedElement(e,n,r){const s=document.querySelector(e);if(!s)return null;const i=s.querySelectorAll(n);for(const o of i)if(o.innerText.trim().toLowerCase()===r.toLowerCase())return o;return null}findNestedIcElement(e,n,r){let s=null;if(typeof e=="string"){if(document.querySelector(e),!s)return null}else s=e;const i=s.querySelectorAll(n);for(const o of i)if(o.innerText.trim().toLowerCase().includes(r.toLowerCase()))return o;return null}findElInParent(e,n){return e&&e.parentElement?.querySelector(n)||null}waitForElement(e,n=100){return new Promise(r=>{const s=d=>d.offsetParent!==null&&(d.childElementCount>0||d.innerText.trim().length>0),i=()=>{const d=document.querySelector(e);d&&s(d)&&(o.disconnect(),clearInterval(c),r(d))},o=new MutationObserver(i);o.observe(document.body,{childList:!0,subtree:!0});const c=setInterval(i,n);i()})}}const w=new Ln;class Bn{sellingPath="https://www.facebook.com/marketplace/you/selling";marketPath="https://www.facebook.com/marketplace";createItem="https://www.facebook.com/marketplace/create/item";editItem="https://www.facebook.com/marketplace/edit";selectors={file__image_input:'input[type="file"]',next_btn:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[5]/div/div/div",update_btn:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[4]/div/div/div",publish_btn:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[4]/div[2]/div/div",products:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[2]/div/div/div[2]/div[1]/div/div[2]/div/div/span/div/div",products_fallback:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[2]/div/div/div[2]/div[1]/div/div[3]/div/div/span/div[2]/div",option_btn:"/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div/div/div/div[3]/div/div/div/div/div[1]/div",option_btn_fallback:"/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[3]/div[2]/div/div[2]/div[1]",close_btn_modal_feedback:"/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[2]/div",images_container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[2]/div[1]/div[2]/div/div/div[3]/div[2]/div",description_edit_input:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[3]/div[1]/div[2]/div/div/div[9]/div/div/div[2]/div/div/div/label/div/div/textarea",sku_edit_input:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[3]/div[1]/div[2]/div/div/div[9]/div/div/div[5]/div/div/div[1]/label/div/input",new_item_btn:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[3]/div[1]/div[2]/div/div/div[7]/a/div",item_for_sell:"/html/body/div[1]/div/div[1]/div/div[5]/div/div/div[3]/div[2]/div[2]/div/div/div[2]/div[1]/div/span/div/div/div[1]/div/div",market_container:'[aria-label="Marketplace"]',collection_marketplace:'[aria-label="Collection of your Marketplace items"]'};findInputByTitle(e,n="input"){const r=w.findNestedElement(this.selectors.market_container,"span",e);if(!r)throw new Error("Not found input by title: "+e);return w.findElInParent(r,n)}clearImages=async()=>{document.querySelectorAll('[aria-label="Remove"]').forEach(e=>e?.click())};uploadImages=async e=>{const n=new DataTransfer;for(const s of e.images){const i=await w.imageUrlToBase64(s);console.log("Base64:",s.slice(0,50)+"...");const o=w.base64ToFile(i,e.sku,w.getImageExtension(s)||"jpg");n.items.add(o)}const r=document.querySelector(this.selectors.file__image_input);r?(r.files=n.files,r.dispatchEvent(new Event("change",{bubbles:!0}))):console.error("Không tìm thấy input[type='file']")};chooseSelect=async(e,n,r='[aria-label="Dropdown menu"]')=>{const s=w.findNestedElement(this.selectors.market_container,"span",n);w.scrollToElement(s),await g(500,600),s?.click(),await g(500,600);const i=w.findNestedElement(r,"span",e);if(await g(500,600),!i)throw new Error(`No child found with text "${e}"`);w.scrollToElement(i),await g(500,600),i.click(),await g(500,600)};chooseLocation=async e=>{const n=this.findInputByTitle("location");await w.writeToInput(e,n),await L(600);const r=document.querySelector('[role="listbox"]')?.querySelectorAll("li")||[],s=Array.from(r).find(i=>i.innerHTML.trim().toLowerCase().includes(e.toLowerCase()));if(console.log(s),!s)throw new Error(`No child found with text "${e}"`);w.scrollToElement(s),await L(400),w.clickByPoint(s)};writeTags=async e=>{const n=this.findInputByTitle("product tags","textarea");if(!n)throw new Error("Input is not found");w.scrollToElement(n),await L(500);for(const r of e)await w.writeToInput(r,n),await L(300),w.pressEnter(n)};clickNext=async()=>{const e=await w.getElementByXPath(this.selectors.next_btn);if(!e)throw new Error("Next button is not found");w.clickByPoint(e)};clickUpdate=async()=>{const e=await w.getElementByXPath(this.selectors.update_btn);if(!e)throw new Error("Next button is not found");w.clickByPoint(e)};clickPublist=async()=>{const e=await w.getElementByXPath(this.selectors.publish_btn);if(!e)throw new Error("Publist button is not found");w.clickByPoint(e)};handlePublist=async e=>{console.log({item:e}),await g(600,1e3),await this.uploadImages(e),await g(600,1e3);const n=this.findInputByTitle("title");w.writeToInput(e.title,n),await g(600,1e3);const r=this.findInputByTitle("price");if(w.writeToInput(String(e.price),r),await g(600,1e3),await this.chooseSelect(e.category,"category"),await g(600,1e3),await this.chooseSelect(e.condition,"condition",'[aria-label="Select an option"]'),e.brand){await g(600,1e3);const o=this.findInputByTitle("brand");await w.writeToInput(e.brand,o)}await g(600,1e3);const s=this.findInputByTitle("description","textarea");await w.writeToInput(e.description,s),await g(600,1e3),await this.writeTags(e.tags),await g(600,1e3);const i=this.findInputByTitle("sku");return await w.writeToInput(e.sku,i),e?.location&&(await g(600,1e3),await this.chooseLocation(e.location)),await g(300,500),await this.clickNext(),!0};handleRePublist=async e=>{console.log({item:e}),await w.waitForElement('[aria-label="Collection of your Marketplace items"]');const n=await this.getOptionEls(e);console.log({items:n}),this.clickItemInList(n,"edit"),await L(1e3),await this.waitForPageReady(this.editItem,this.selectors.market_container),await g(1e3,2e3),await this.clearImages(),await g(600,1e3),await this.uploadImages(e),await g(600,1e3);const r=this.findInputByTitle("title");w.writeToInput(e.title,r),await g(600,1e3);const s=this.findInputByTitle("price");w.writeToInput(String(e.price),s),await g(600,1e3),await this.chooseSelect(e.category,"category"),await g(600,1e3),await this.chooseSelect(e.condition,"condition",'[aria-label="Select an option"]'),await g(600,1e3);const i=this.findInputByTitle("description","textarea");return await w.writeToInput(e.description,i),await g(600,1e3),await this.writeTags(e.tags),await g(600,1e3),e?.location&&(await g(600,1e3),await this.chooseLocation(e.location)),!0};async getInfo(){try{const n=Date.now(),r=await new Promise(i=>{chrome.storage.local.get("meCache",o=>{i(o.meCache?JSON.parse(o.meCache):null)})});if(r&&n-r.timestamp<72e5)return r.data;const s=await fetch("/me");if(!s.ok)throw new Error(`HTTP error! status: ${s.status}`);return chrome.storage.local.set({meCache:JSON.stringify({data:{url:s.url},timestamp:n})}),s}catch(n){return console.error("Failed to get /me:",n),null}}getProducts=async()=>{const e=await w.getElementByXPath(this.selectors.products),n=await w.getElementByXPath(this.selectors.products_fallback);if(!e&&!n)throw new Error("List element has changed. Please connect to DEV");const r=[e,n].filter(Boolean);if(r.length===0)return[];const s=await this.getInfo();return console.log({info:s}),r.flatMap(i=>this.extractListings(i,s))};extractListings(e,n){return Array.from(e.children).map(s=>{const o=s.querySelector('span[dir="auto"], div[dir="auto"]')?.textContent?.trim()||"",c=document.querySelectorAll(`[aria-label="${o}"]`),d=Array.from(c).filter(b=>!b.querySelector("img"))[0],u=w.findNestedIcElement(d,"span","AU$")?.textContent?.match(/[\d,]+(?:\.\d+)?/),f=u?parseFloat(u[0].replace(/,/g,"")):0;return{title:o,price:f,el:e,url_info:n?.url}})}closeTab=async e=>{chrome.runtime.sendMessage({type:"close-tab",payload:e})};clickOptionOfProduct(e){const n=document.querySelector(`[aria-label="More options for ${e.title}"]`);if(!n)throw new Error(`Not found option buttin in product ${`[aria-label="More options for ${e.title}"]`}, ID: ${e.id}`);w.scrollToElement(n),n.click?.()}async getOptionEls(e){return this.clickOptionOfProduct(e),await L(2e3),Array.from(document.querySelectorAll('[role="menuitem"]'))}clickItemInList(e,n){const r=e.find(s=>s.textContent.toLocaleLowerCase().includes(n));if(!r)throw new Error(`Not found item ${n} in options list`);r.click?.()}getItemInList(e,n){const r=e.find(s=>s.textContent.toLocaleLowerCase().includes(n));if(!r)throw new Error(`Not found item ${n} in options list`);return r}handleDelete=async e=>{const n=await this.getOptionEls(e);console.log({items:n}),this.clickItemInList(n,"delete"),await L(1e3);const r=await w.getElementByXPath(this.selectors.option_btn,{xpathFallback:this.selectors.option_btn_fallback});console.log({confirmBtn:r}),r?.click(),(await w.getElementByXPath(this.selectors.close_btn_modal_feedback))?.click(),chrome.runtime.sendMessage({type:"delete-done"})};waitForUrlContains(e,n=1e4){return new Promise((r,s)=>{const i=Date.now(),o=()=>{window.location.href.includes(e)?r():Date.now()-i>n?s(new Error("Timeout waiting for URL change")):setTimeout(o,500)};o()})}waitForPageReady(e,n,r=15e3){return new Promise((s,i)=>{const o=Date.now(),c=async()=>{window.location.href.includes(e)&&document.querySelector(n)?s():Date.now()-o>r?i(new Error("Timeout waiting for selling page ready")):setTimeout(c,500)};c()})}syncListing=async()=>{window.location.href.includes(this.sellingPath)||(document.querySelector('a[href="/marketplace/you/selling/"]')?.click?.(),await this.waitForPageReady(this.sellingPath,this.selectors.products)),await R.getProducts()};extractMarketplaceItemId(e){const n=e.match(/\/marketplace\/item\/(\d+)/);return n?n[1]:null}handleGetPublistID=async e=>{const n=await R.getProducts(),r=n.find(c=>c.title==e.title&&c.price==e.price);if(console.log({payload:e,product:r,products:n}),!r)return;r.el;const s=await this.getOptionEls(e),i=this.getItemInList(s,"view listing"),o=this.extractMarketplaceItemId(i.href);return this.clickOptionOfProduct(e),o};async gotoPublist(){(await w.getElementByXPath(this.selectors.new_item_btn))?.click(),await g(400,800),(await w.getElementByXPath(this.selectors.item_for_sell))?.click()}async gotoSell(){document.querySelector('[href="/marketplace/you/selling/"]')?.click()}}const R=new Bn;class Fn{role;listeners;constructor(e){this.role=e,this.listeners=new Map,chrome.runtime.onMessage.addListener((n,r,s)=>{if(n?.type&&this.listeners.has(n.type))return this.listeners.get(n.type)(n.payload,r,s),!0})}on(e,n){this.listeners.set(e,n)}send(e,n,r){const s={from:this.role,to:e,type:n,payload:r};(this.role==="popup"||this.role==="content")&&chrome.runtime.sendMessage(s),this.role==="background"&&(e==="content"?chrome.tabs.query({active:!0,currentWindow:!0},i=>{i[0]?.id&&chrome.tabs.sendMessage(i[0].id,s,()=>{chrome.runtime.lastError&&console.warn("Không gửi được tới content script:",chrome.runtime.lastError.message)})}):e==="popup"&&chrome.runtime.sendMessage(s,()=>{chrome.runtime.lastError&&console.warn("Không gửi được tới popup:",chrome.runtime.lastError.message)}))}sendToTab(e,n,r){if(this.role!=="background")throw new Error("sendToTab chỉ được gọi từ background");const s={from:this.role,to:"content",type:n,payload:r};chrome.tabs.sendMessage(e,s,()=>{chrome.runtime.lastError&&console.warn(`Không gửi được tới content script tab ${e}:`,chrome.runtime.lastError.message)})}waitForMessage(e,n=3e4){return new Promise((r,s)=>{let i;const o=c=>{clearTimeout(i),this.off(e,o),r(c)};i=setTimeout(()=>{this.off(e,o),s(new Error(`Timeout khi chờ message: ${e}`))},n),this.on(e,o)})}off(e,n){this.listeners.get(e)===n&&this.listeners.delete(e)}}const C=new Fn("content"),$=async t=>{await window.QUEUE.enqueue(t)},it=()=>{const t=In.ID_EXTENSION;if(document.getElementById(t))return;const e=document.createElement("div");e.id=t,document.body.appendChild(e);const n=document.createElement("script");n.src=chrome.runtime.getURL("content/inject-ui.js"),n.type="module",document.body.appendChild(n);const r=document.createElement("link");r.rel="stylesheet",r.type="text/css",r.href=chrome.runtime.getURL("assets/style.css"),document.head.appendChild(r)};C.on("background-to-content-publish",async t=>{try{console.log("[publish] Content nhận:",t),await g(800,1e3),await R.handlePublist(t.data),$({title:"Publist Completed !",message:"Please review",type:"success"})}catch(e){console.log({error:e}),$({title:`Publist Error - ${t.data.title||"Unknow"}`,message:e?.message,type:"error"})}finally{C.send("background","content-to-background-publish",{msg:t})}}),C.on("background-to-content-unlist",async t=>{try{console.log("[unlist] Content nhận:",t),await g(800,1e3),await R.gotoSell(),await g(800,1e3),await R.handleDelete(t.data),await g(800,1e3);const e=await R.getProducts();await g(800,1e3),await H.sync(e),$({title:"Unlist Completed !",message:"Please review",type:"success"})}catch(e){console.log({error:e}),$({title:`Unlist Error - ${t.data.title||""}`,message:e?.message,type:"error"})}finally{C.send("background","content-to-background-unlist",{msg:t})}}),C.on("background-to-content-re-publist",async t=>{try{console.log("[re-publist] Content nhận:",t),await g(800,1e3),await R.gotoSell(),await g(800,1e3),await R.handleRePublist(t.data)}catch(e){console.log({error:e}),$({title:"Re-Publist Error",message:e?.message,type:"error"})}finally{C.send("background","content-to-background-re-publist",{msg:t})}}),window.addEventListener("message",async t=>{if(t.source===window&&t.data.type==="API_REQUEST"){const e=t.data.payload,n=t.data.fn,{requestId:r}=t.data;try{let s=null;switch(n){case"index":{const i=await R.getInfo();console.log(i,e),s=(await H.index({info:i,...e})).data;break}case"getPublistedProducts":{s=(await H.getPublistedProducts()).data;break}case"get":{s=(await H.get(e)).data,console.log({data:s,body:e});break}case"createBlobUrl":{C.send("background","content-to-background-create-blod-urls",e),s=await C.waitForMessage("background-to-content-create-blod-urls"),console.log({data:s});break}case"publist":{C.send("background","content-to-background-actions",{type:"publist",data:e}),s=await C.waitForMessage("background-to-content-actions");break}case"unlist":{C.send("background","content-to-background-actions",{type:"unlist",data:e}),s=await C.waitForMessage("background-to-content-actions"),console.log({unlisted:s});break}case"sync":{const i=await w.waitForElement(R.selectors.collection_marketplace);console.log("Element đã xuất hiện:",i),await R.waitForPageReady(R.sellingPath,R.selectors.collection_marketplace),await g(800,1e3);const o=await R.getProducts();console.log({products:o}),await H.sync(o);break}case"dequeue":{s=await window.QUEUE.dequeue();break}}window.postMessage({type:"API_RESPONSE",requestId:r,payload:s},"*")}catch(s){window.postMessage({type:"API_RESPONSE",requestId:r,error:s.message},"*")}}});const Un=()=>{const t=setInterval(async()=>{try{const e=await R.getProducts();await H.sync(e)}catch(e){console.error("Sync error:",e),clearInterval(t),$({title:"Sync Error",message:e.message,type:"error"})}},1e4)};(async()=>{if(window.QUEUE=await ve.create(),await R.getInfo(),await g(800,1e3),window.location.href.includes(R.sellingPath))try{const t=await w.waitForElement(R.selectors.collection_marketplace);console.log("Element đã xuất hiện:",t),await g(800,1e3),Un()}catch(t){console.error(t)}finally{it()}else it()})()})();