diff --git a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/app-2S0BUUWF.js b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/app-2S0BUUWF.js deleted file mode 100644 index be96adf..0000000 --- a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/app-2S0BUUWF.js +++ /dev/null @@ -1 +0,0 @@ -function n(e){return new Promise(t=>setTimeout(t,e))}export{n as d}; diff --git a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/index-CCGOrIw_.js b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/index-CCGOrIw_.js new file mode 100644 index 0000000..c896bf0 --- /dev/null +++ b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/assets/index-CCGOrIw_.js @@ -0,0 +1 @@ +function C(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var b={exports:{}},I;function O(){return I||(I=1,function(o){var e=Object.prototype.hasOwnProperty,t="~";function u(){}Object.create&&(u.prototype=Object.create(null),new u().__proto__||(t=!1));function d(h,i,n){this.fn=h,this.context=i,this.once=n||!1}function l(h,i,n,r,v){if(typeof n!="function")throw new TypeError("The listener must be a function");var a=new d(n,r||h,v),f=t?t+i:i;return h._events[f]?h._events[f].fn?h._events[f]=[h._events[f],a]:h._events[f].push(a):(h._events[f]=a,h._eventsCount++),h}function y(h,i){--h._eventsCount===0?h._events=new u:delete h._events[i]}function c(){this._events=new u,this._eventsCount=0}c.prototype.eventNames=function(){var i=[],n,r;if(this._eventsCount===0)return i;for(r in n=this._events)e.call(n,r)&&i.push(t?r.slice(1):r);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(n)):i},c.prototype.listeners=function(i){var n=t?t+i:i,r=this._events[n];if(!r)return[];if(r.fn)return[r.fn];for(var v=0,a=r.length,f=new Array(a);vglobalThis.DOMException===void 0?new q(o):new DOMException(o),x=o=>{const e=o.reason===void 0?_("This operation was aborted."):o.reason;return e instanceof Error?e:_(e)};function z(o,e){const{milliseconds:t,fallback:u,message:d,customTimers:l={setTimeout,clearTimeout}}=e;let y,c;const i=new Promise((n,r)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){const{signal:a}=e;a.aborted&&r(x(a)),c=()=>{r(x(a))},a.addEventListener("abort",c,{once:!0})}if(t===Number.POSITIVE_INFINITY){o.then(n,r);return}const v=new T;y=l.setTimeout.call(void 0,()=>{if(u){try{n(u())}catch(a){r(a)}return}typeof o.cancel=="function"&&o.cancel(),d===!1?n():d instanceof Error?r(d):(v.message=d??`Promise timed out after ${t} milliseconds`,r(v))},t),(async()=>{try{n(await o)}catch(a){r(a)}})()}).finally(()=>{i.clear(),c&&e.signal&&e.signal.removeEventListener("abort",c)});return i.clear=()=>{l.clearTimeout.call(void 0,y),y=void 0},i}function L(o,e,t){let u=0,d=o.length;for(;d>0;){const l=Math.trunc(d/2);let y=u+l;t(o[y],e)<=0?(u=++y,d-=l+1):d=l}return u}class S{#e=[];enqueue(e,t){t={priority:0,...t};const u={priority:t.priority,id:t.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=t.priority){this.#e.push(u);return}const d=L(this.#e,u,(l,y)=>y.priority-l.priority);this.#e.splice(d,0,u)}setPriority(e,t){const u=this.#e.findIndex(l=>l.id===e);if(u===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);const[d]=this.#e.splice(u,1);this.enqueue(d.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}}class $ extends N{#e;#u;#s=0;#d;#o;#m=0;#r;#a;#t;#v;#n=0;#h;#i;#y;#g=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:S,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#u=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#o=e.interval,this.#t=new e.queueClass,this.#v=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#y=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#E(){return this.#u||this.#s{this.#_()},t)),!0}return!1}#l(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){const e=!this.#x;if(this.#E&&this.#b){const t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#p(),!0):!1}}return!1}#p(){this.#u||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#o),this.#m=Date.now()+this.#o)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#c()}#c(){for(;this.#l(););}get concurrency(){return this.#h}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#h=e,this.#c()}async#T(e){return new Promise((t,u)=>{e.addEventListener("abort",()=>{u(e.reason)},{once:!0})})}setPriority(e,t){this.#t.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#g++).toString(),t={timeout:this.timeout,throwOnTimeout:this.#y,...t},new Promise((u,d)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let l=e({signal:t.signal});t.timeout&&(l=z(Promise.resolve(l),{milliseconds:t.timeout})),t.signal&&(l=Promise.race([l,this.#T(t.signal)]));const y=await l;u(y),this.emit("completed",y)}catch(l){if(l instanceof T&&!t.throwOnTimeout){u();return}d(l),this.emit("error",l)}finally{this.#I()}},t),this.emit("add"),this.#l()})}async addAll(e,t){return Promise.all(e.map(async u=>this.add(u,t)))}start(){return this.#i?(this.#i=!1,this.#c(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#v}async onEmpty(){this.#t.size!==0&&await this.#f("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{const d=()=>{t&&!t()||(this.off(e,d),u())};this.on(e,d)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}}export{$ as P}; diff --git a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/background.js b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/background.js index d6752f6..392190a 100644 --- a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/background.js +++ b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/background.js @@ -1 +1 @@ -function O(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var E={exports:{}},T;function L(){return T||(T=1,function(s){var e=Object.prototype.hasOwnProperty,t="~";function a(){}Object.create&&(a.prototype=Object.create(null),new a().__proto__||(t=!1));function c(u,i,r){this.fn=u,this.context=i,this.once=r||!1}function l(u,i,r,n,p){if(typeof r!="function")throw new TypeError("The listener must be a function");var f=new c(r,n||u,p),d=t?t+i:i;return u._events[d]?u._events[d].fn?u._events[d]=[u._events[d],f]:u._events[d].push(f):(u._events[d]=f,u._eventsCount++),u}function v(u,i){--u._eventsCount===0?u._events=new a:delete u._events[i]}function h(){this._events=new a,this._eventsCount=0}h.prototype.eventNames=function(){var i=[],r,n;if(this._eventsCount===0)return i;for(n in r=this._events)e.call(r,n)&&i.push(t?n.slice(1):n);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(r)):i},h.prototype.listeners=function(i){var r=t?t+i:i,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var p=0,f=n.length,d=new Array(f);pglobalThis.DOMException===void 0?new S(s):new DOMException(s),x=s=>{const e=s.reason===void 0?_("This operation was aborted."):s.reason;return e instanceof Error?e:_(e)};function q(s,e){const{milliseconds:t,fallback:a,message:c,customTimers:l={setTimeout,clearTimeout}}=e;let v,h;const i=new Promise((r,n)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){const{signal:f}=e;f.aborted&&n(x(f)),h=()=>{n(x(f))},f.addEventListener("abort",h,{once:!0})}if(t===Number.POSITIVE_INFINITY){s.then(r,n);return}const p=new C;v=l.setTimeout.call(void 0,()=>{if(a){try{r(a())}catch(f){n(f)}return}typeof s.cancel=="function"&&s.cancel(),c===!1?r():c instanceof Error?n(c):(p.message=c??`Promise timed out after ${t} milliseconds`,n(p))},t),(async()=>{try{r(await s)}catch(f){n(f)}})()}).finally(()=>{i.clear(),h&&e.signal&&e.signal.removeEventListener("abort",h)});return i.clear=()=>{l.clearTimeout.call(void 0,v),v=void 0},i}function z(s,e,t){let a=0,c=s.length;for(;c>0;){const l=Math.trunc(c/2);let v=a+l;t(s[v],e)<=0?(a=++v,c-=l+1):c=l}return a}class ${#e=[];enqueue(e,t){t={priority:0,...t};const a={priority:t.priority,id:t.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=t.priority){this.#e.push(a);return}const c=z(this.#e,a,(l,v)=>v.priority-l.priority);this.#e.splice(c,0,a)}setPriority(e,t){const a=this.#e.findIndex(l=>l.id===e);if(a===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);const[c]=this.#e.splice(a,1);this.enqueue(c.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}}class k extends A{#e;#o;#s=0;#d;#a;#m=0;#r;#u;#t;#v;#n=0;#c;#i;#p;#b=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:$,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#v=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#p=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#g(){return this.#o||this.#s{this.#T()},t)),!0}return!1}#l(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){const e=!this.#_;if(this.#g&&this.#E){const t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#m=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#h()}#h(){for(;this.#l(););}get concurrency(){return this.#c}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#c=e,this.#h()}async#x(e){return new Promise((t,a)=>{e.addEventListener("abort",()=>{a(e.reason)},{once:!0})})}setPriority(e,t){this.#t.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#b++).toString(),t={timeout:this.timeout,throwOnTimeout:this.#p,...t},new Promise((a,c)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let l=e({signal:t.signal});t.timeout&&(l=q(Promise.resolve(l),{milliseconds:t.timeout})),t.signal&&(l=Promise.race([l,this.#x(t.signal)]));const v=await l;a(v),this.emit("completed",v)}catch(l){if(l instanceof C&&!t.throwOnTimeout){a();return}c(l),this.emit("error",l)}finally{this.#I()}},t),this.emit("add"),this.#l()})}async addAll(e,t){return Promise.all(e.map(async a=>this.add(a,t)))}start(){return this.#i?(this.#i=!1,this.#h(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#v}async onEmpty(){this.#t.size!==0&&await this.#f("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{const c=()=>{t&&!t()||(this.off(e,c),a())};this.on(e,c)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}}let I=[];const D=new k({concurrency:1});chrome.runtime.onConnect.addListener(s=>{I.push(s),s.onDisconnect.addListener(()=>{I=I.filter(e=>e!==s)})});(()=>{const s=new EventSource("http://localhost:4000/api/v1/products/publist-stream");s.onmessage=e=>{const t=JSON.parse(e.data);console.log("New event:",t),D.add(()=>F(t,3e4))},s.onerror=e=>{console.error("EventSource failed:",e)}})();async function F(s,e=5*60*1e3){return new Promise(t=>{chrome.tabs.create({url:"https://www.facebook.com/marketplace/create/item",active:!0},a=>{if(!a?.id)return t();const c=a.id;let l=!1;const v=()=>{l||(l=!0,chrome.runtime.onConnect.removeListener(h),chrome.tabs.onRemoved.removeListener(u),clearTimeout(i),t())},h=r=>{r.sender?.tab?.id===c&&(r.postMessage({type:"publist-event",payload:s}),chrome.runtime.onConnect.removeListener(h))};chrome.runtime.onConnect.addListener(h);const u=r=>{r===c&&v()};chrome.tabs.onRemoved.addListener(u);const i=setTimeout(()=>{console.warn(`Tab ${c} timeout (${e}ms) - auto resolve`),c&&chrome.tabs.remove(c),v()},e)})})}chrome.runtime.onMessage.addListener((s,e)=>{if(s.type==="close-tab"){const t=e.tab?.id;t&&chrome.tabs.remove(t)}}); +function O(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var E={exports:{}},T;function N(){return T||(T=1,function(r){var e=Object.prototype.hasOwnProperty,t="~";function o(){}Object.create&&(o.prototype=Object.create(null),new o().__proto__||(t=!1));function c(l,s,n){this.fn=l,this.context=s,this.once=n||!1}function u(l,s,n,i,p){if(typeof n!="function")throw new TypeError("The listener must be a function");var f=new c(n,i||l,p),m=t?t+s:s;return l._events[m]?l._events[m].fn?l._events[m]=[l._events[m],f]:l._events[m].push(f):(l._events[m]=f,l._eventsCount++),l}function d(l,s){--l._eventsCount===0?l._events=new o:delete l._events[s]}function h(){this._events=new o,this._eventsCount=0}h.prototype.eventNames=function(){var s=[],n,i;if(this._eventsCount===0)return s;for(i in n=this._events)e.call(n,i)&&s.push(t?i.slice(1):i);return Object.getOwnPropertySymbols?s.concat(Object.getOwnPropertySymbols(n)):s},h.prototype.listeners=function(s){var n=t?t+s:s,i=this._events[n];if(!i)return[];if(i.fn)return[i.fn];for(var p=0,f=i.length,m=new Array(f);pglobalThis.DOMException===void 0?new z(r):new DOMException(r),x=r=>{const e=r.reason===void 0?_("This operation was aborted."):r.reason;return e instanceof Error?e:_(e)};function $(r,e){const{milliseconds:t,fallback:o,message:c,customTimers:u={setTimeout,clearTimeout}}=e;let d,h;const s=new Promise((n,i)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){const{signal:f}=e;f.aborted&&i(x(f)),h=()=>{i(x(f))},f.addEventListener("abort",h,{once:!0})}if(t===Number.POSITIVE_INFINITY){r.then(n,i);return}const p=new C;d=u.setTimeout.call(void 0,()=>{if(o){try{n(o())}catch(f){i(f)}return}typeof r.cancel=="function"&&r.cancel(),c===!1?n():c instanceof Error?i(c):(p.message=c??`Promise timed out after ${t} milliseconds`,i(p))},t),(async()=>{try{n(await r)}catch(f){i(f)}})()}).finally(()=>{s.clear(),h&&e.signal&&e.signal.removeEventListener("abort",h)});return s.clear=()=>{u.clearTimeout.call(void 0,d),d=void 0},s}function k(r,e,t){let o=0,c=r.length;for(;c>0;){const u=Math.trunc(c/2);let d=o+u;t(r[d],e)<=0?(o=++d,c-=u+1):c=u}return o}class D{#e=[];enqueue(e,t){t={priority:0,...t};const o={priority:t.priority,id:t.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=t.priority){this.#e.push(o);return}const c=k(this.#e,o,(u,d)=>d.priority-u.priority);this.#e.splice(c,0,o)}setPriority(e,t){const o=this.#e.findIndex(u=>u.id===e);if(o===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);const[c]=this.#e.splice(o,1);this.enqueue(c.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}}class M extends q{#e;#o;#s=0;#d;#a;#m=0;#r;#u;#t;#v;#n=0;#c;#i;#p;#b=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:D,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#o=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#v=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#p=e.throwOnTimeout===!0,this.#i=e.autoStart===!1}get#g(){return this.#o||this.#s{this.#T()},t)),!0}return!1}#l(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#i){const e=!this.#_;if(this.#g&&this.#E){const t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#o||this.#r!==void 0||(this.#r=setInterval(()=>{this.#w()},this.#a),this.#m=Date.now()+this.#a)}#w(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#h()}#h(){for(;this.#l(););}get concurrency(){return this.#c}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#c=e,this.#h()}async#x(e){return new Promise((t,o)=>{e.addEventListener("abort",()=>{o(e.reason)},{once:!0})})}setPriority(e,t){this.#t.setPriority(e,t)}async add(e,t={}){return t.id??=(this.#b++).toString(),t={timeout:this.timeout,throwOnTimeout:this.#p,...t},new Promise((o,c)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let u=e({signal:t.signal});t.timeout&&(u=$(Promise.resolve(u),{milliseconds:t.timeout})),t.signal&&(u=Promise.race([u,this.#x(t.signal)]));const d=await u;o(d),this.emit("completed",d)}catch(u){if(u instanceof C&&!t.throwOnTimeout){o();return}c(u),this.emit("error",u)}finally{this.#I()}},t),this.emit("add"),this.#l()})}async addAll(e,t){return Promise.all(e.map(async o=>this.add(o,t)))}start(){return this.#i?(this.#i=!1,this.#h(),this):this}pause(){this.#i=!0}clear(){this.#t=new this.#v}async onEmpty(){this.#t.size!==0&&await this.#f("empty")}async onSizeLessThan(e){this.#t.sizethis.#t.size{const c=()=>{t&&!t()||(this.off(e,c),o())};this.on(e,c)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#i}}let I=[];const P=new M({concurrency:1});chrome.runtime.onConnect.addListener(r=>{I.push(r),r.onDisconnect.addListener(()=>{I=I.filter(e=>e!==r)})});async function R(r,e=5*60*1e3){return new Promise(t=>{chrome.tabs.create({url:"https://www.facebook.com/marketplace/create/item",active:!0},o=>{if(!o?.id)return t();const c=o.id;let u=!1;const d=()=>{u||(u=!0,chrome.runtime.onConnect.removeListener(h),chrome.tabs.onRemoved.removeListener(l),clearTimeout(s),t(),S())},h=n=>{n.sender?.tab?.id===c&&(n.postMessage({type:"publist-event",payload:r}),chrome.runtime.onConnect.removeListener(h))};chrome.runtime.onConnect.addListener(h);const l=n=>{n===c&&d()};chrome.tabs.onRemoved.addListener(l);const s=setTimeout(()=>{console.warn(`Tab ${c} timeout (${e}ms) - auto resolve`),c&&chrome.tabs.remove(c),d()},e)})})}const F=()=>{const r=new EventSource("http://localhost:4000/api/v1/products/publist-stream");r.onmessage=e=>{const t=JSON.parse(e.data);console.log("New event:",t),P.add(()=>R(t,3e4))},r.onerror=e=>{console.error("EventSource failed:",e)}},Q=()=>{const r=new EventSource("http://localhost:4000/api/v1/products/delete-stream");r.onmessage=e=>{try{const t=JSON.parse(e.data);console.log("[SSE] New event:",t),P.add(()=>new Promise(o=>{const c=u=>{u?.type==="delete-done"&&(console.log("[QUEUE] Delete done signal received."),chrome.runtime.onMessage.removeListener(c),o())};chrome.runtime.onMessage.addListener(c),chrome.tabs.query({url:"https://www.facebook.com/marketplace/you/selling"},u=>{for(const d of u)d.id&&chrome.tabs.sendMessage(d.id,{type:"DELETE_STREAM_DATA",payload:t})})}))}catch(t){console.error("[SSE] Parse error:",t)}},r.onerror=e=>{console.error("[SSE] Connection failed:",e)},console.log("[SSE] Listening for delete-stream events...")};function S(){const r="https://www.facebook.com/marketplace/you/selling";console.log({targetUrl:r}),chrome.tabs.query({},e=>{const t=e.find(o=>o.url&&o.url.startsWith(r));t?chrome.tabs.reload(t.id):chrome.tabs.create({url:r})})}const V=async()=>{F(),Q(),S()};chrome.runtime.onMessage.addListener((r,e)=>{if(r.type==="close-tab"){const t=e.tab?.id;t&&chrome.tabs.remove(t)}});V(); diff --git a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/content.js b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/content.js index b5da055..bb0f198 100644 --- a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/content.js +++ b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/content.js @@ -1,6 +1,6 @@ -function g(e){return new Promise(t=>setTimeout(t,e))}function ke(e,t){return function(){return e.apply(t,arguments)}}const{toString:rt}=Object.prototype,{getPrototypeOf:fe}=Object,{iterator:G,toStringTag:Ne}=Symbol,Z=(e=>t=>{const n=rt.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),P=e=>(e=e.toLowerCase(),t=>Z(t)===e),Q=e=>t=>typeof t===e,{isArray:j}=Array,M=Q("undefined");function st(e){return e!==null&&!M(e)&&e.constructor!==null&&!M(e.constructor)&&x(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Be=P("ArrayBuffer");function ot(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Be(e.buffer),t}const at=Q("string"),x=Q("function"),Le=Q("number"),Y=e=>e!==null&&typeof e=="object",dt=e=>e===!0||e===!1,J=e=>{if(Z(e)!=="object")return!1;const t=fe(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Ne in e)&&!(G in e)},ct=P("Date"),lt=P("File"),ut=P("Blob"),ft=P("FileList"),pt=e=>Y(e)&&x(e.pipe),ht=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||x(e.append)&&((t=Z(e))==="formdata"||t==="object"&&x(e.toString)&&e.toString()==="[object FormData]"))},vt=P("URLSearchParams"),[mt,wt,bt,yt]=["ReadableStream","Request","Response","Headers"].map(P),Et=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function H(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let i,r;if(typeof e!="object"&&(e=[e]),j(e))for(i=0,r=e.length;i0;)if(r=n[i],t===r.toLowerCase())return r;return null}const F=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,Ue=e=>!M(e)&&e!==F;function oe(){const{caseless:e}=Ue(this)&&this||{},t={},n=(i,r)=>{const s=e&&Fe(t,r)||r;J(t[s])&&J(i)?t[s]=oe(t[s],i):J(i)?t[s]=oe({},i):j(i)?t[s]=i.slice():t[s]=i};for(let i=0,r=arguments.length;i(H(t,(r,s)=>{n&&x(r)?e[s]=ke(r,n):e[s]=r},{allOwnKeys:i}),e),Rt=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),St=(e,t,n,i)=>{e.prototype=Object.create(t.prototype,i),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Tt=(e,t,n,i)=>{let r,s,o;const d={};if(t=t||{},e==null)return t;do{for(r=Object.getOwnPropertyNames(e),s=r.length;s-- >0;)o=r[s],(!i||i(o,e,t))&&!d[o]&&(t[o]=e[o],d[o]=!0);e=n!==!1&&fe(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},Ot=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const i=e.indexOf(t,n);return i!==-1&&i===n},At=e=>{if(!e)return null;if(j(e))return e;let t=e.length;if(!Le(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},_t=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&fe(Uint8Array)),xt=(e,t)=>{const i=(e&&e[G]).call(e);let r;for(;(r=i.next())&&!r.done;){const s=r.value;t.call(e,s[0],s[1])}},Ct=(e,t)=>{let n;const i=[];for(;(n=e.exec(t))!==null;)i.push(n);return i},Pt=P("HTMLFormElement"),kt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,i,r){return i.toUpperCase()+r}),me=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Nt=P("RegExp"),De=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),i={};H(n,(r,s)=>{let o;(o=t(r,s,e))!==!1&&(i[s]=o||r)}),Object.defineProperties(e,i)},Bt=e=>{De(e,(t,n)=>{if(x(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const i=e[n];if(x(i)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Lt=(e,t)=>{const n={},i=r=>{r.forEach(s=>{n[s]=!0})};return j(e)?i(e):i(String(e).split(t)),n},Ft=()=>{},Ut=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Dt(e){return!!(e&&x(e.append)&&e[Ne]==="FormData"&&e[G])}const jt=e=>{const t=new Array(10),n=(i,r)=>{if(Y(i)){if(t.indexOf(i)>=0)return;if(!("toJSON"in i)){t[r]=i;const s=j(i)?[]:{};return H(i,(o,d)=>{const u=n(o,r+1);!M(u)&&(s[d]=u)}),t[r]=void 0,s}}return i};return n(e,0)},It=P("AsyncFunction"),qt=e=>e&&(Y(e)||x(e))&&x(e.then)&&x(e.catch),je=((e,t)=>e?setImmediate:t?((n,i)=>(F.addEventListener("message",({source:r,data:s})=>{r===F&&s===n&&i.length&&i.shift()()},!1),r=>{i.push(r),F.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",x(F.postMessage)),Mt=typeof queueMicrotask<"u"?queueMicrotask.bind(F):typeof process<"u"&&process.nextTick||je,Ht=e=>e!=null&&x(e[G]),a={isArray:j,isArrayBuffer:Be,isBuffer:st,isFormData:ht,isArrayBufferView:ot,isString:at,isNumber:Le,isBoolean:dt,isObject:Y,isPlainObject:J,isReadableStream:mt,isRequest:wt,isResponse:bt,isHeaders:yt,isUndefined:M,isDate:ct,isFile:lt,isBlob:ut,isRegExp:Nt,isFunction:x,isStream:pt,isURLSearchParams:vt,isTypedArray:_t,isFileList:ft,forEach:H,merge:oe,extend:gt,trim:Et,stripBOM:Rt,inherits:St,toFlatObject:Tt,kindOf:Z,kindOfTest:P,endsWith:Ot,toArray:At,forEachEntry:xt,matchAll:Ct,isHTMLForm:Pt,hasOwnProperty:me,hasOwnProp:me,reduceDescriptors:De,freezeMethods:Bt,toObjectSet:Lt,toCamelCase:kt,noop:Ft,toFiniteNumber:Ut,findKey:Fe,global:F,isContextDefined:Ue,isSpecCompliantForm:Dt,toJSONObject:jt,isAsyncFn:It,isThenable:qt,setImmediate:je,asap:Mt,isIterable:Ht};function v(e,t,n,i,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),i&&(this.request=i),r&&(this.response=r,this.status=r.status?r.status:null)}a.inherits(v,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 Ie=v.prototype,qe={};["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(e=>{qe[e]={value:e}});Object.defineProperties(v,qe);Object.defineProperty(Ie,"isAxiosError",{value:!0});v.from=(e,t,n,i,r,s)=>{const o=Object.create(Ie);return a.toFlatObject(e,o,function(u){return u!==Error.prototype},d=>d!=="isAxiosError"),v.call(o,e.message,t,n,i,r),o.cause=e,o.name=e.name,s&&Object.assign(o,s),o};const $t=null;function ae(e){return a.isPlainObject(e)||a.isArray(e)}function Me(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function we(e,t,n){return e?e.concat(t).map(function(r,s){return r=Me(r),!n&&s?"["+r+"]":r}).join(n?".":""):t}function zt(e){return a.isArray(e)&&!e.some(ae)}const Jt=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function ee(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,h){return!a.isUndefined(h[m])});const i=n.metaTokens,r=n.visitor||l,s=n.dots,o=n.indexes,u=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(r))throw new TypeError("visitor must be a function");function c(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(a.isBoolean(f))return f.toString();if(!u&&a.isBlob(f))throw new v("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?u&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,m,h){let y=f;if(f&&!h&&typeof f=="object"){if(a.endsWith(m,"{}"))m=i?m:m.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&zt(f)||(a.isFileList(f)||a.endsWith(m,"[]"))&&(y=a.toArray(f)))return m=Me(m),y.forEach(function(T,N){!(a.isUndefined(T)||T===null)&&t.append(o===!0?we([m],N,s):o===null?m:m+"[]",c(T))}),!1}return ae(f)?!0:(t.append(we(h,m,s),c(f)),!1)}const p=[],w=Object.assign(Jt,{defaultVisitor:l,convertValue:c,isVisitable:ae});function R(f,m){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));p.push(f),a.forEach(f,function(y,S){(!(a.isUndefined(y)||y===null)&&r.call(t,y,a.isString(S)?S.trim():S,m,w))===!0&&R(y,m?m.concat(S):[S])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return R(e),t}function be(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(i){return t[i]})}function pe(e,t){this._pairs=[],e&&ee(e,this,t)}const He=pe.prototype;He.append=function(t,n){this._pairs.push([t,n])};He.toString=function(t){const n=t?function(i){return t.call(this,i,be)}:be;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function Vt(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function $e(e,t,n){if(!t)return e;const i=n&&n.encode||Vt;a.isFunction(n)&&(n={serialize:n});const r=n&&n.serialize;let s;if(r?s=r(t,n):s=a.isURLSearchParams(t)?t.toString():new pe(t,n).toString(i),s){const o=e.indexOf("#");o!==-1&&(e=e.slice(0,o)),e+=(e.indexOf("?")===-1?"?":"&")+s}return e}class ye{constructor(){this.handlers=[]}use(t,n,i){return this.handlers.push({fulfilled:t,rejected:n,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(i){i!==null&&t(i)})}}const ze={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Kt=typeof URLSearchParams<"u"?URLSearchParams:pe,Wt=typeof FormData<"u"?FormData:null,Xt=typeof Blob<"u"?Blob:null,Gt={isBrowser:!0,classes:{URLSearchParams:Kt,FormData:Wt,Blob:Xt},protocols:["http","https","file","blob","url","data"]},he=typeof window<"u"&&typeof document<"u",de=typeof navigator=="object"&&navigator||void 0,Zt=he&&(!de||["ReactNative","NativeScript","NS"].indexOf(de.product)<0),Qt=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Yt=he&&window.location.href||"http://localhost",en=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:he,hasStandardBrowserEnv:Zt,hasStandardBrowserWebWorkerEnv:Qt,navigator:de,origin:Yt},Symbol.toStringTag,{value:"Module"})),O={...en,...Gt};function tn(e,t){return ee(e,new O.classes.URLSearchParams,Object.assign({visitor:function(n,i,r,s){return O.isNode&&a.isBuffer(n)?(this.append(i,n.toString("base64")),!1):s.defaultVisitor.apply(this,arguments)}},t))}function nn(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function rn(e){const t={},n=Object.keys(e);let i;const r=n.length;let s;for(i=0;i=n.length;return o=!o&&a.isArray(r)?r.length:o,u?(a.hasOwnProp(r,o)?r[o]=[r[o],i]:r[o]=i,!d):((!r[o]||!a.isObject(r[o]))&&(r[o]=[]),t(n,i,r[o],s)&&a.isArray(r[o])&&(r[o]=rn(r[o])),!d)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(i,r)=>{t(nn(i),r,n,0)}),n}return null}function sn(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(i){if(i.name!=="SyntaxError")throw i}return(n||JSON.stringify)(e)}const $={transitional:ze,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const i=n.getContentType()||"",r=i.indexOf("application/json")>-1,s=a.isObject(t);if(s&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return r?JSON.stringify(Je(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t)||a.isReadableStream(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let d;if(s){if(i.indexOf("application/x-www-form-urlencoded")>-1)return tn(t,this.formSerializer).toString();if((d=a.isFileList(t))||i.indexOf("multipart/form-data")>-1){const u=this.env&&this.env.FormData;return ee(d?{"files[]":t}:t,u&&new u,this.formSerializer)}}return s||r?(n.setContentType("application/json",!1),sn(t)):t}],transformResponse:[function(t){const n=this.transitional||$.transitional,i=n&&n.forcedJSONParsing,r=this.responseType==="json";if(a.isResponse(t)||a.isReadableStream(t))return t;if(t&&a.isString(t)&&(i&&!this.responseType||r)){const o=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(t)}catch(d){if(o)throw d.name==="SyntaxError"?v.from(d,v.ERR_BAD_RESPONSE,this,null,this.response):d}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:O.classes.FormData,Blob:O.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],e=>{$.headers[e]={}});const on=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"]),an=e=>{const t={};let n,i,r;return e&&e.split(` -`).forEach(function(o){r=o.indexOf(":"),n=o.substring(0,r).trim().toLowerCase(),i=o.substring(r+1).trim(),!(!n||t[n]&&on[n])&&(n==="set-cookie"?t[n]?t[n].push(i):t[n]=[i]:t[n]=t[n]?t[n]+", "+i:i)}),t},Ee=Symbol("internals");function q(e){return e&&String(e).trim().toLowerCase()}function V(e){return e===!1||e==null?e:a.isArray(e)?e.map(V):String(e)}function dn(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let i;for(;i=n.exec(e);)t[i[1]]=i[2];return t}const cn=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ie(e,t,n,i,r){if(a.isFunction(i))return i.call(this,t,n);if(r&&(t=n),!!a.isString(t)){if(a.isString(i))return t.indexOf(i)!==-1;if(a.isRegExp(i))return i.test(t)}}function ln(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,i)=>n.toUpperCase()+i)}function un(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(i=>{Object.defineProperty(e,i+n,{value:function(r,s,o){return this[i].call(this,t,r,s,o)},configurable:!0})})}let C=class{constructor(t){t&&this.set(t)}set(t,n,i){const r=this;function s(d,u,c){const l=q(u);if(!l)throw new Error("header name must be a non-empty string");const p=a.findKey(r,l);(!p||r[p]===void 0||c===!0||c===void 0&&r[p]!==!1)&&(r[p||u]=V(d))}const o=(d,u)=>a.forEach(d,(c,l)=>s(c,l,u));if(a.isPlainObject(t)||t instanceof this.constructor)o(t,n);else if(a.isString(t)&&(t=t.trim())&&!cn(t))o(an(t),n);else if(a.isObject(t)&&a.isIterable(t)){let d={},u,c;for(const l of t){if(!a.isArray(l))throw TypeError("Object iterator must return a key-value pair");d[c=l[0]]=(u=d[c])?a.isArray(u)?[...u,l[1]]:[u,l[1]]:l[1]}o(d,n)}else t!=null&&s(n,t,i);return this}get(t,n){if(t=q(t),t){const i=a.findKey(this,t);if(i){const r=this[i];if(!n)return r;if(n===!0)return dn(r);if(a.isFunction(n))return n.call(this,r,i);if(a.isRegExp(n))return n.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=q(t),t){const i=a.findKey(this,t);return!!(i&&this[i]!==void 0&&(!n||ie(this,this[i],i,n)))}return!1}delete(t,n){const i=this;let r=!1;function s(o){if(o=q(o),o){const d=a.findKey(i,o);d&&(!n||ie(i,i[d],d,n))&&(delete i[d],r=!0)}}return a.isArray(t)?t.forEach(s):s(t),r}clear(t){const n=Object.keys(this);let i=n.length,r=!1;for(;i--;){const s=n[i];(!t||ie(this,this[s],s,t,!0))&&(delete this[s],r=!0)}return r}normalize(t){const n=this,i={};return a.forEach(this,(r,s)=>{const o=a.findKey(i,s);if(o){n[o]=V(r),delete n[s];return}const d=t?ln(s):String(s).trim();d!==s&&delete n[s],n[d]=V(r),i[d]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(i,r)=>{i!=null&&i!==!1&&(n[r]=t&&a.isArray(i)?i.join(", "):i)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(` -`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const i=new this(t);return n.forEach(r=>i.set(r)),i}static accessor(t){const i=(this[Ee]=this[Ee]={accessors:{}}).accessors,r=this.prototype;function s(o){const d=q(o);i[d]||(un(r,o),i[d]=!0)}return a.isArray(t)?t.forEach(s):s(t),this}};C.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);a.reduceDescriptors(C.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(i){this[n]=i}}});a.freezeMethods(C);function re(e,t){const n=this||$,i=t||n,r=C.from(i.headers);let s=i.data;return a.forEach(e,function(d){s=d.call(n,s,r.normalize(),t?t.status:void 0)}),r.normalize(),s}function Ve(e){return!!(e&&e.__CANCEL__)}function I(e,t,n){v.call(this,e??"canceled",v.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(I,v,{__CANCEL__:!0});function Ke(e,t,n){const i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):t(new v("Request failed with status code "+n.status,[v.ERR_BAD_REQUEST,v.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function fn(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function pn(e,t){e=e||10;const n=new Array(e),i=new Array(e);let r=0,s=0,o;return t=t!==void 0?t:1e3,function(u){const c=Date.now(),l=i[s];o||(o=c),n[r]=u,i[r]=c;let p=s,w=0;for(;p!==r;)w+=n[p++],p=p%e;if(r=(r+1)%e,r===s&&(s=(s+1)%e),c-o{n=l,r=null,s&&(clearTimeout(s),s=null),e.apply(null,c)};return[(...c)=>{const l=Date.now(),p=l-n;p>=i?o(c,l):(r=c,s||(s=setTimeout(()=>{s=null,o(r)},i-p)))},()=>r&&o(r)]}const W=(e,t,n=3)=>{let i=0;const r=pn(50,250);return hn(s=>{const o=s.loaded,d=s.lengthComputable?s.total:void 0,u=o-i,c=r(u),l=o<=d;i=o;const p={loaded:o,total:d,progress:d?o/d:void 0,bytes:u,rate:c||void 0,estimated:c&&d&&l?(d-o)/c:void 0,event:s,lengthComputable:d!=null,[t?"download":"upload"]:!0};e(p)},n)},ge=(e,t)=>{const n=e!=null;return[i=>t[0]({lengthComputable:n,total:e,loaded:i}),t[1]]},Re=e=>(...t)=>a.asap(()=>e(...t)),vn=O.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,O.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(O.origin),O.navigator&&/(msie|trident)/i.test(O.navigator.userAgent)):()=>!0,mn=O.hasStandardBrowserEnv?{write(e,t,n,i,r,s){const o=[e+"="+encodeURIComponent(t)];a.isNumber(n)&&o.push("expires="+new Date(n).toGMTString()),a.isString(i)&&o.push("path="+i),a.isString(r)&&o.push("domain="+r),s===!0&&o.push("secure"),document.cookie=o.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function wn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function bn(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function We(e,t,n){let i=!wn(t);return e&&(i||n==!1)?bn(e,t):t}const Se=e=>e instanceof C?{...e}:e;function D(e,t){t=t||{};const n={};function i(c,l,p,w){return a.isPlainObject(c)&&a.isPlainObject(l)?a.merge.call({caseless:w},c,l):a.isPlainObject(l)?a.merge({},l):a.isArray(l)?l.slice():l}function r(c,l,p,w){if(a.isUndefined(l)){if(!a.isUndefined(c))return i(void 0,c,p,w)}else return i(c,l,p,w)}function s(c,l){if(!a.isUndefined(l))return i(void 0,l)}function o(c,l){if(a.isUndefined(l)){if(!a.isUndefined(c))return i(void 0,c)}else return i(void 0,l)}function d(c,l,p){if(p in t)return i(c,l);if(p in e)return i(void 0,c)}const u={url:s,method:s,data:s,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:d,headers:(c,l,p)=>r(Se(c),Se(l),p,!0)};return a.forEach(Object.keys(Object.assign({},e,t)),function(l){const p=u[l]||r,w=p(e[l],t[l],l);a.isUndefined(w)&&p!==d||(n[l]=w)}),n}const Xe=e=>{const t=D({},e);let{data:n,withXSRFToken:i,xsrfHeaderName:r,xsrfCookieName:s,headers:o,auth:d}=t;t.headers=o=C.from(o),t.url=$e(We(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),d&&o.set("Authorization","Basic "+btoa((d.username||"")+":"+(d.password?unescape(encodeURIComponent(d.password)):"")));let u;if(a.isFormData(n)){if(O.hasStandardBrowserEnv||O.hasStandardBrowserWebWorkerEnv)o.setContentType(void 0);else if((u=o.getContentType())!==!1){const[c,...l]=u?u.split(";").map(p=>p.trim()).filter(Boolean):[];o.setContentType([c||"multipart/form-data",...l].join("; "))}}if(O.hasStandardBrowserEnv&&(i&&a.isFunction(i)&&(i=i(t)),i||i!==!1&&vn(t.url))){const c=r&&s&&mn.read(s);c&&o.set(r,c)}return t},yn=typeof XMLHttpRequest<"u",En=yn&&function(e){return new Promise(function(n,i){const r=Xe(e);let s=r.data;const o=C.from(r.headers).normalize();let{responseType:d,onUploadProgress:u,onDownloadProgress:c}=r,l,p,w,R,f;function m(){R&&R(),f&&f(),r.cancelToken&&r.cancelToken.unsubscribe(l),r.signal&&r.signal.removeEventListener("abort",l)}let h=new XMLHttpRequest;h.open(r.method.toUpperCase(),r.url,!0),h.timeout=r.timeout;function y(){if(!h)return;const T=C.from("getAllResponseHeaders"in h&&h.getAllResponseHeaders()),_={data:!d||d==="text"||d==="json"?h.responseText:h.response,status:h.status,statusText:h.statusText,headers:T,config:e,request:h};Ke(function(L){n(L),m()},function(L){i(L),m()},_),h=null}"onloadend"in h?h.onloadend=y:h.onreadystatechange=function(){!h||h.readyState!==4||h.status===0&&!(h.responseURL&&h.responseURL.indexOf("file:")===0)||setTimeout(y)},h.onabort=function(){h&&(i(new v("Request aborted",v.ECONNABORTED,e,h)),h=null)},h.onerror=function(){i(new v("Network Error",v.ERR_NETWORK,e,h)),h=null},h.ontimeout=function(){let N=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const _=r.transitional||ze;r.timeoutErrorMessage&&(N=r.timeoutErrorMessage),i(new v(N,_.clarifyTimeoutError?v.ETIMEDOUT:v.ECONNABORTED,e,h)),h=null},s===void 0&&o.setContentType(null),"setRequestHeader"in h&&a.forEach(o.toJSON(),function(N,_){h.setRequestHeader(_,N)}),a.isUndefined(r.withCredentials)||(h.withCredentials=!!r.withCredentials),d&&d!=="json"&&(h.responseType=r.responseType),c&&([w,f]=W(c,!0),h.addEventListener("progress",w)),u&&h.upload&&([p,R]=W(u),h.upload.addEventListener("progress",p),h.upload.addEventListener("loadend",R)),(r.cancelToken||r.signal)&&(l=T=>{h&&(i(!T||T.type?new I(null,e,h):T),h.abort(),h=null)},r.cancelToken&&r.cancelToken.subscribe(l),r.signal&&(r.signal.aborted?l():r.signal.addEventListener("abort",l)));const S=fn(r.url);if(S&&O.protocols.indexOf(S)===-1){i(new v("Unsupported protocol "+S+":",v.ERR_BAD_REQUEST,e));return}h.send(s||null)})},gn=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let i=new AbortController,r;const s=function(c){if(!r){r=!0,d();const l=c instanceof Error?c:this.reason;i.abort(l instanceof v?l:new I(l instanceof Error?l.message:l))}};let o=t&&setTimeout(()=>{o=null,s(new v(`timeout ${t} of ms exceeded`,v.ETIMEDOUT))},t);const d=()=>{e&&(o&&clearTimeout(o),o=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(s):c.removeEventListener("abort",s)}),e=null)};e.forEach(c=>c.addEventListener("abort",s));const{signal:u}=i;return u.unsubscribe=()=>a.asap(d),u}},Rn=function*(e,t){let n=e.byteLength;if(n{const r=Sn(e,t);let s=0,o,d=u=>{o||(o=!0,i&&i(u))};return new ReadableStream({async pull(u){try{const{done:c,value:l}=await r.next();if(c){d(),u.close();return}let p=l.byteLength;if(n){let w=s+=p;n(w)}u.enqueue(new Uint8Array(l))}catch(c){throw d(c),c}},cancel(u){return d(u),r.return()}},{highWaterMark:2})},te=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Ge=te&&typeof ReadableStream=="function",On=te&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),Ze=(e,...t)=>{try{return!!e(...t)}catch{return!1}},An=Ge&&Ze(()=>{let e=!1;const t=new Request(O.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Oe=64*1024,ce=Ge&&Ze(()=>a.isReadableStream(new Response("").body)),X={stream:ce&&(e=>e.body)};te&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!X[t]&&(X[t]=a.isFunction(e[t])?n=>n[t]():(n,i)=>{throw new v(`Response type '${t}' is not supported`,v.ERR_NOT_SUPPORT,i)})})})(new Response);const _n=async e=>{if(e==null)return 0;if(a.isBlob(e))return e.size;if(a.isSpecCompliantForm(e))return(await new Request(O.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(a.isArrayBufferView(e)||a.isArrayBuffer(e))return e.byteLength;if(a.isURLSearchParams(e)&&(e=e+""),a.isString(e))return(await On(e)).byteLength},xn=async(e,t)=>{const n=a.toFiniteNumber(e.getContentLength());return n??_n(t)},Cn=te&&(async e=>{let{url:t,method:n,data:i,signal:r,cancelToken:s,timeout:o,onDownloadProgress:d,onUploadProgress:u,responseType:c,headers:l,withCredentials:p="same-origin",fetchOptions:w}=Xe(e);c=c?(c+"").toLowerCase():"text";let R=gn([r,s&&s.toAbortSignal()],o),f;const m=R&&R.unsubscribe&&(()=>{R.unsubscribe()});let h;try{if(u&&An&&n!=="get"&&n!=="head"&&(h=await xn(l,i))!==0){let _=new Request(t,{method:"POST",body:i,duplex:"half"}),B;if(a.isFormData(i)&&(B=_.headers.get("content-type"))&&l.setContentType(B),_.body){const[L,z]=ge(h,W(Re(u)));i=Te(_.body,Oe,L,z)}}a.isString(p)||(p=p?"include":"omit");const y="credentials"in Request.prototype;f=new Request(t,{...w,signal:R,method:n.toUpperCase(),headers:l.normalize().toJSON(),body:i,duplex:"half",credentials:y?p:void 0});let S=await fetch(f,w);const T=ce&&(c==="stream"||c==="response");if(ce&&(d||T&&m)){const _={};["status","statusText","headers"].forEach(ve=>{_[ve]=S[ve]});const B=a.toFiniteNumber(S.headers.get("content-length")),[L,z]=d&&ge(B,W(Re(d),!0))||[];S=new Response(Te(S.body,Oe,L,()=>{z&&z(),m&&m()}),_)}c=c||"text";let N=await X[a.findKey(X,c)||"text"](S,e);return!T&&m&&m(),await new Promise((_,B)=>{Ke(_,B,{data:N,headers:C.from(S.headers),status:S.status,statusText:S.statusText,config:e,request:f})})}catch(y){throw m&&m(),y&&y.name==="TypeError"&&/Load failed|fetch/i.test(y.message)?Object.assign(new v("Network Error",v.ERR_NETWORK,e,f),{cause:y.cause||y}):v.from(y,y&&y.code,e,f)}}),le={http:$t,xhr:En,fetch:Cn};a.forEach(le,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const Ae=e=>`- ${e}`,Pn=e=>a.isFunction(e)||e===null||e===!1,Qe={getAdapter:e=>{e=a.isArray(e)?e:[e];const{length:t}=e;let n,i;const r={};for(let s=0;s`adapter ${d} `+(u===!1?"is not supported by the environment":"is not available in the build"));let o=t?s.length>1?`since : -`+s.map(Ae).join(` -`):" "+Ae(s[0]):"as no adapter specified";throw new v("There is no suitable adapter to dispatch the request "+o,"ERR_NOT_SUPPORT")}return i},adapters:le};function se(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new I(null,e)}function _e(e){return se(e),e.headers=C.from(e.headers),e.data=re.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Qe.getAdapter(e.adapter||$.adapter)(e).then(function(i){return se(e),i.data=re.call(e,e.transformResponse,i),i.headers=C.from(i.headers),i},function(i){return Ve(i)||(se(e),i&&i.response&&(i.response.data=re.call(e,e.transformResponse,i.response),i.response.headers=C.from(i.response.headers))),Promise.reject(i)})}const Ye="1.10.0",ne={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ne[e]=function(i){return typeof i===e||"a"+(t<1?"n ":" ")+e}});const xe={};ne.transitional=function(t,n,i){function r(s,o){return"[Axios v"+Ye+"] Transitional option '"+s+"'"+o+(i?". "+i:"")}return(s,o,d)=>{if(t===!1)throw new v(r(o," has been removed"+(n?" in "+n:"")),v.ERR_DEPRECATED);return n&&!xe[o]&&(xe[o]=!0,console.warn(r(o," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(s,o,d):!0}};ne.spelling=function(t){return(n,i)=>(console.warn(`${i} is likely a misspelling of ${t}`),!0)};function kn(e,t,n){if(typeof e!="object")throw new v("options must be an object",v.ERR_BAD_OPTION_VALUE);const i=Object.keys(e);let r=i.length;for(;r-- >0;){const s=i[r],o=t[s];if(o){const d=e[s],u=d===void 0||o(d,s,e);if(u!==!0)throw new v("option "+s+" must be "+u,v.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new v("Unknown option "+s,v.ERR_BAD_OPTION)}}const K={assertOptions:kn,validators:ne},k=K.validators;let U=class{constructor(t){this.defaults=t||{},this.interceptors={request:new ye,response:new ye}}async request(t,n){try{return await this._request(t,n)}catch(i){if(i instanceof Error){let r={};Error.captureStackTrace?Error.captureStackTrace(r):r=new Error;const s=r.stack?r.stack.replace(/^.+\n/,""):"";try{i.stack?s&&!String(i.stack).endsWith(s.replace(/^.+\n.+\n/,""))&&(i.stack+=` -`+s):i.stack=s}catch{}}throw i}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=D(this.defaults,n);const{transitional:i,paramsSerializer:r,headers:s}=n;i!==void 0&&K.assertOptions(i,{silentJSONParsing:k.transitional(k.boolean),forcedJSONParsing:k.transitional(k.boolean),clarifyTimeoutError:k.transitional(k.boolean)},!1),r!=null&&(a.isFunction(r)?n.paramsSerializer={serialize:r}:K.assertOptions(r,{encode:k.function,serialize:k.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),K.assertOptions(n,{baseUrl:k.spelling("baseURL"),withXsrfToken:k.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let o=s&&a.merge(s.common,s[n.method]);s&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete s[f]}),n.headers=C.concat(o,s);const d=[];let u=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(u=u&&m.synchronous,d.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let l,p=0,w;if(!u){const f=[_e.bind(this),void 0];for(f.unshift.apply(f,d),f.push.apply(f,c),w=f.length,l=Promise.resolve(n);p{if(!i._listeners)return;let s=i._listeners.length;for(;s-- >0;)i._listeners[s](r);i._listeners=null}),this.promise.then=r=>{let s;const o=new Promise(d=>{i.subscribe(d),s=d}).then(r);return o.cancel=function(){i.unsubscribe(s)},o},t(function(s,o,d){i.reason||(i.reason=new I(s,o,d),n(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=i=>{t.abort(i)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new et(function(r){t=r}),cancel:t}}};function Bn(e){return function(n){return e.apply(null,n)}}function Ln(e){return a.isObject(e)&&e.isAxiosError===!0}const ue={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(ue).forEach(([e,t])=>{ue[t]=e});function tt(e){const t=new U(e),n=ke(U.prototype.request,t);return a.extend(n,U.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return tt(D(e,r))},n}const E=tt($);E.Axios=U;E.CanceledError=I;E.CancelToken=Nn;E.isCancel=Ve;E.VERSION=Ye;E.toFormData=ee;E.AxiosError=v;E.Cancel=E.CanceledError;E.all=function(t){return Promise.all(t)};E.spread=Bn;E.isAxiosError=Ln;E.mergeConfig=D;E.AxiosHeaders=C;E.formToJSON=e=>Je(a.isHTMLForm(e)?new FormData(e):e);E.getAdapter=Qe.getAdapter;E.HttpStatusCode=ue;E.default=E;const{Axios:Vn,AxiosError:Kn,CanceledError:Wn,isCancel:Xn,CancelToken:Gn,VERSION:Zn,all:Qn,Cancel:Yn,isAxiosError:ei,spread:ti,toFormData:ni,AxiosHeaders:ii,HttpStatusCode:ri,formToJSON:si,getAdapter:oi,mergeConfig:ai}=E,nt=E.create({baseURL:"http://localhost:4000/api/v1",headers:{"Content-Type":"application/json"}});class Fn{base64ToFile(t,n,i){const r=t.includes(",")?t.split(",")[1]:t,s=atob(r),o=new ArrayBuffer(s.length),d=new Uint8Array(o);for(let c=0;c{let o=0,d=!1;const u=()=>{const c=document.evaluate(d&&r?r:t,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;if(c instanceof HTMLElement){s(c);return}o++,o{const o=new FileReader;o.onloadend=()=>{typeof o.result=="string"?r(o.result.split(",")[1]):s("Không thể đọc dữ liệu ảnh")},o.onerror=s,o.readAsDataURL(i)})}getImageExtension(t){try{const i=new URL(t).pathname.match(/\.([a-zA-Z0-9]+)$/);return i?i[1].toLowerCase():null}catch{const r=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return r?r[1].toLowerCase():null}}imageLocalToBase64(t){return new Promise((n,i)=>{try{const r=chrome.runtime.getURL(`${t}`);fetch(r).then(s=>s.blob()).then(s=>{const o=new FileReader;o.onloadend=()=>n(o.result),o.onerror=i,o.readAsDataURL(s)}).catch(i)}catch(r){i(r)}})}scrollToElement(t,n="smooth"){t&&t.scrollIntoView({behavior:n,block:"center",inline:"nearest"})}getElementPointCoores(t){if(!t)return null;const n=t.getBoundingClientRect(),i=n.left+n.width/2,r=n.top+n.height/2;return{x:i,y:r}}setInputValue(t,n){t&&(t.value=n,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})))}writeToInput=async(t,n,i)=>{const r=await this.getElementByXPath(n,{xpathFallback:i});if(!r)throw new Error("Xpath is not found with value: "+t);this.scrollToElement(r),this.clickByPoint(r),this.setInputValue(r,t)};pressEnter(t){if(!t)throw new Error("Textarea not found:",t);t.focus(),["keydown","keypress","keyup"].forEach(n=>{t.dispatchEvent(new KeyboardEvent(n,{key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:!0,cancelable:!0}))})}}const b=new Fn,A={file__image_input:'input[type="file"]',title_input:"/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[5]/div/div/div/label/div/input",price_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[6]/div/div/div/label/div/input",brand_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/input",brand_input_fallback:"/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[10]/div/div/div[2]/div/div/div/label/div/input",description_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[3]/div/div/div/label/div/div/textarea",description_input_falback:"/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[10]/div/div/div[3]/div/div/div/label/div/div/textarea",sku_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[6]/div/div/div[1]/label/div/input",sku_input_fallback:"/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[10]/div/div/div[6]/div/div/div[1]/label/div/input",category_select:{wraper:"/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]/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div/div/span/div"},condition_select:{wraper:"/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[8]/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div/div[1]/div"},tags_input:{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/div[1]/label/div/div/div[2]/div/textarea",input_falback:"/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[10]/div/div/div[5]/div/div/div/div[1]/label/div/div/div[2]/div/textarea"},location_select:{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[7]/div/div/div/div/div/div/div/div/label/div[2]/input",input_fallback:"/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[10]/div/div/div[7]/div/div/div/div/div/div/div/div/label/div[2]/input",wraper:"/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[7]/div/div/div/div/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/ul",container_fallback:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/ul"},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",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"},Un=async e=>{const t=new DataTransfer;for(const i of e.images){const r=await b.imageUrlToBase64(i);console.log("Base64:",i.slice(0,50)+"...");const s=b.base64ToFile(r,e.sku,b.getImageExtension(i)||"jpg");t.items.add(s)}const n=document.querySelector(A.file__image_input);n?(n.files=t.files,n.dispatchEvent(new Event("change",{bubbles:!0}))):console.error("Không tìm thấy input[type='file']")},Ce=async(e,t)=>{const n=await b.getElementByXPath(t.wraper);if(!n)throw new Error("Wrapper xpath not found");b.scrollToElement(n),b.clickByPoint(n),await g(200);const i=await b.getElementByXPath(t.container);if(!i)throw new Error("Container xpath not found");const r=Array.from(i.children).find(s=>s.textContent?.trim().toLocaleLowerCase().replace(/–/g,"-").includes(e.toLocaleLowerCase()));if(!r)throw new Error(`No child found with text "${e}"`);b.scrollToElement(r),await g(200),b.clickByPoint(r)},Dn=async(e,{input:t,...n})=>{await b.writeToInput(e,t,n.input_fallback),await g(200);const i=await b.getElementByXPath(n.container,{xpathFallback:n.container_fallback});if(!i)throw new Error("Container xpath not found");b.scrollToElement(i);const r=Array.from(i.children).find(s=>s.textContent?.trim().toLocaleLowerCase().includes(e.toLocaleLowerCase()));if(!r)throw new Error(`No child found with text "${e}"`);b.scrollToElement(r),await g(200),b.clickByPoint(r)},jn=async(e,t)=>{const n=await b.getElementByXPath(t.input,{xpathFallback:t?.input_falback});if(!n)throw new Error("Input is not found");b.scrollToElement(n),await g(200);for(const i of e)await b.writeToInput(i,t.input,t?.input_falback),await g(200),b.pressEnter(n)},Pe=async(e,t)=>{const{data:n}=await nt({url:"products/publist-finish/"+e.id,method:"POST",data:t});return n},In=async()=>{const e=await b.getElementByXPath(A.next_btn);if(!e)throw new Error("Next button is not found");b.clickByPoint(e)},qn=async()=>{const e=await b.getElementByXPath(A.publish_btn);if(!e)throw new Error("Publist button is not found");b.clickByPoint(e)},it=async e=>(console.log({item:e}),await g(1e3),await Un(e),await g(200),b.writeToInput(e.title,A.title_input),await g(200),b.writeToInput(String(e.price),A.price_input),await g(200),await Ce(e.category,A.category_select),await g(200),await Ce(e.condition,A.condition_select),e.brand&&(await g(200),await b.writeToInput(e.brand,A.brand_input,A.brand_input_fallback)),await g(200),await b.writeToInput(e.description,A.description_input,A.description_input_falback),await g(200),await jn(e.tags,A.tags_input),await g(200),await b.writeToInput(e.sku,A.sku_input,A.sku_input_fallback),e?.location&&(await g(200),await Dn(e.location,A.location_select)),await g(200),await In(),await g(200),await qn(),!0),Mn=async e=>{chrome.runtime.sendMessage({type:"close-tab",payload:e})},Hn=chrome.runtime.connect();Hn.onMessage.addListener(async e=>{if(e.type==="publist-event"){const t=e.payload;if(!t)return;console.log("Received new product event:",t);try{await g(500),await it(t)}catch(n){await Pe(t,{error:n.message,published:!1})}finally{await Pe(t,{published:!0}),await g(5e3),await Mn(t)}}});async function $n(){const{data:e}=await nt.get("products/27");if(!e.data)return;const t=e.data;await it(t)}$n(); +function Ne(e,t){return function(){return e.apply(t,arguments)}}const{toString:rt}=Object.prototype,{getPrototypeOf:fe}=Object,{iterator:G,toStringTag:Le}=Symbol,Z=(e=>t=>{const n=rt.call(t);return e[n]||(e[n]=n.slice(8,-1).toLowerCase())})(Object.create(null)),P=e=>(e=e.toLowerCase(),t=>Z(t)===e),Q=e=>t=>typeof t===e,{isArray:j}=Array,M=Q("undefined");function ot(e){return e!==null&&!M(e)&&e.constructor!==null&&!M(e.constructor)&&x(e.constructor.isBuffer)&&e.constructor.isBuffer(e)}const Be=P("ArrayBuffer");function st(e){let t;return typeof ArrayBuffer<"u"&&ArrayBuffer.isView?t=ArrayBuffer.isView(e):t=e&&e.buffer&&Be(e.buffer),t}const at=Q("string"),x=Q("function"),Fe=Q("number"),Y=e=>e!==null&&typeof e=="object",dt=e=>e===!0||e===!1,J=e=>{if(Z(e)!=="object")return!1;const t=fe(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Le in e)&&!(G in e)},ct=P("Date"),lt=P("File"),ut=P("Blob"),ft=P("FileList"),pt=e=>Y(e)&&x(e.pipe),vt=e=>{let t;return e&&(typeof FormData=="function"&&e instanceof FormData||x(e.append)&&((t=Z(e))==="formdata"||t==="object"&&x(e.toString)&&e.toString()==="[object FormData]"))},ht=P("URLSearchParams"),[mt,wt,yt,bt]=["ReadableStream","Request","Response","Headers"].map(P),Et=e=>e.trim?e.trim():e.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"");function H(e,t,{allOwnKeys:n=!1}={}){if(e===null||typeof e>"u")return;let i,r;if(typeof e!="object"&&(e=[e]),j(e))for(i=0,r=e.length;i0;)if(r=n[i],t===r.toLowerCase())return r;return null}const F=typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:global,De=e=>!M(e)&&e!==F;function se(){const{caseless:e}=De(this)&&this||{},t={},n=(i,r)=>{const o=e&&Ue(t,r)||r;J(t[o])&&J(i)?t[o]=se(t[o],i):J(i)?t[o]=se({},i):j(i)?t[o]=i.slice():t[o]=i};for(let i=0,r=arguments.length;i(H(t,(r,o)=>{n&&x(r)?e[o]=Ne(r,n):e[o]=r},{allOwnKeys:i}),e),Rt=e=>(e.charCodeAt(0)===65279&&(e=e.slice(1)),e),St=(e,t,n,i)=>{e.prototype=Object.create(t.prototype,i),e.prototype.constructor=e,Object.defineProperty(e,"super",{value:t.prototype}),n&&Object.assign(e.prototype,n)},Tt=(e,t,n,i)=>{let r,o,s;const d={};if(t=t||{},e==null)return t;do{for(r=Object.getOwnPropertyNames(e),o=r.length;o-- >0;)s=r[o],(!i||i(s,e,t))&&!d[s]&&(t[s]=e[s],d[s]=!0);e=n!==!1&&fe(e)}while(e&&(!n||n(e,t))&&e!==Object.prototype);return t},At=(e,t,n)=>{e=String(e),(n===void 0||n>e.length)&&(n=e.length),n-=t.length;const i=e.indexOf(t,n);return i!==-1&&i===n},Ot=e=>{if(!e)return null;if(j(e))return e;let t=e.length;if(!Fe(t))return null;const n=new Array(t);for(;t-- >0;)n[t]=e[t];return n},_t=(e=>t=>e&&t instanceof e)(typeof Uint8Array<"u"&&fe(Uint8Array)),xt=(e,t)=>{const i=(e&&e[G]).call(e);let r;for(;(r=i.next())&&!r.done;){const o=r.value;t.call(e,o[0],o[1])}},Ct=(e,t)=>{let n;const i=[];for(;(n=e.exec(t))!==null;)i.push(n);return i},Pt=P("HTMLFormElement"),kt=e=>e.toLowerCase().replace(/[-_\s]([a-z\d])(\w*)/g,function(n,i,r){return i.toUpperCase()+r}),we=(({hasOwnProperty:e})=>(t,n)=>e.call(t,n))(Object.prototype),Nt=P("RegExp"),je=(e,t)=>{const n=Object.getOwnPropertyDescriptors(e),i={};H(n,(r,o)=>{let s;(s=t(r,o,e))!==!1&&(i[o]=s||r)}),Object.defineProperties(e,i)},Lt=e=>{je(e,(t,n)=>{if(x(e)&&["arguments","caller","callee"].indexOf(n)!==-1)return!1;const i=e[n];if(x(i)){if(t.enumerable=!1,"writable"in t){t.writable=!1;return}t.set||(t.set=()=>{throw Error("Can not rewrite read-only method '"+n+"'")})}})},Bt=(e,t)=>{const n={},i=r=>{r.forEach(o=>{n[o]=!0})};return j(e)?i(e):i(String(e).split(t)),n},Ft=()=>{},Ut=(e,t)=>e!=null&&Number.isFinite(e=+e)?e:t;function Dt(e){return!!(e&&x(e.append)&&e[Le]==="FormData"&&e[G])}const jt=e=>{const t=new Array(10),n=(i,r)=>{if(Y(i)){if(t.indexOf(i)>=0)return;if(!("toJSON"in i)){t[r]=i;const o=j(i)?[]:{};return H(i,(s,d)=>{const u=n(s,r+1);!M(u)&&(o[d]=u)}),t[r]=void 0,o}}return i};return n(e,0)},qt=P("AsyncFunction"),It=e=>e&&(Y(e)||x(e))&&x(e.then)&&x(e.catch),qe=((e,t)=>e?setImmediate:t?((n,i)=>(F.addEventListener("message",({source:r,data:o})=>{r===F&&o===n&&i.length&&i.shift()()},!1),r=>{i.push(r),F.postMessage(n,"*")}))(`axios@${Math.random()}`,[]):n=>setTimeout(n))(typeof setImmediate=="function",x(F.postMessage)),Mt=typeof queueMicrotask<"u"?queueMicrotask.bind(F):typeof process<"u"&&process.nextTick||qe,Ht=e=>e!=null&&x(e[G]),a={isArray:j,isArrayBuffer:Be,isBuffer:ot,isFormData:vt,isArrayBufferView:st,isString:at,isNumber:Fe,isBoolean:dt,isObject:Y,isPlainObject:J,isReadableStream:mt,isRequest:wt,isResponse:yt,isHeaders:bt,isUndefined:M,isDate:ct,isFile:lt,isBlob:ut,isRegExp:Nt,isFunction:x,isStream:pt,isURLSearchParams:ht,isTypedArray:_t,isFileList:ft,forEach:H,merge:se,extend:gt,trim:Et,stripBOM:Rt,inherits:St,toFlatObject:Tt,kindOf:Z,kindOfTest:P,endsWith:At,toArray:Ot,forEachEntry:xt,matchAll:Ct,isHTMLForm:Pt,hasOwnProperty:we,hasOwnProp:we,reduceDescriptors:je,freezeMethods:Lt,toObjectSet:Bt,toCamelCase:kt,noop:Ft,toFiniteNumber:Ut,findKey:Ue,global:F,isContextDefined:De,isSpecCompliantForm:Dt,toJSONObject:jt,isAsyncFn:qt,isThenable:It,setImmediate:qe,asap:Mt,isIterable:Ht};function h(e,t,n,i,r){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=e,this.name="AxiosError",t&&(this.code=t),n&&(this.config=n),i&&(this.request=i),r&&(this.response=r,this.status=r.status?r.status:null)}a.inherits(h,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 Ie=h.prototype,Me={};["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(e=>{Me[e]={value:e}});Object.defineProperties(h,Me);Object.defineProperty(Ie,"isAxiosError",{value:!0});h.from=(e,t,n,i,r,o)=>{const s=Object.create(Ie);return a.toFlatObject(e,s,function(u){return u!==Error.prototype},d=>d!=="isAxiosError"),h.call(s,e.message,t,n,i,r),s.cause=e,s.name=e.name,o&&Object.assign(s,o),s};const $t=null;function ae(e){return a.isPlainObject(e)||a.isArray(e)}function He(e){return a.endsWith(e,"[]")?e.slice(0,-2):e}function ye(e,t,n){return e?e.concat(t).map(function(r,o){return r=He(r),!n&&o?"["+r+"]":r}).join(n?".":""):t}function zt(e){return a.isArray(e)&&!e.some(ae)}const Jt=a.toFlatObject(a,{},null,function(t){return/^is[A-Z]/.test(t)});function ee(e,t,n){if(!a.isObject(e))throw new TypeError("target must be an object");t=t||new FormData,n=a.toFlatObject(n,{metaTokens:!0,dots:!1,indexes:!1},!1,function(m,v){return!a.isUndefined(v[m])});const i=n.metaTokens,r=n.visitor||l,o=n.dots,s=n.indexes,u=(n.Blob||typeof Blob<"u"&&Blob)&&a.isSpecCompliantForm(t);if(!a.isFunction(r))throw new TypeError("visitor must be a function");function c(f){if(f===null)return"";if(a.isDate(f))return f.toISOString();if(a.isBoolean(f))return f.toString();if(!u&&a.isBlob(f))throw new h("Blob is not supported. Use a Buffer instead.");return a.isArrayBuffer(f)||a.isTypedArray(f)?u&&typeof Blob=="function"?new Blob([f]):Buffer.from(f):f}function l(f,m,v){let E=f;if(f&&!v&&typeof f=="object"){if(a.endsWith(m,"{}"))m=i?m:m.slice(0,-2),f=JSON.stringify(f);else if(a.isArray(f)&&zt(f)||(a.isFileList(f)||a.endsWith(m,"[]"))&&(E=a.toArray(f)))return m=He(m),E.forEach(function(T,N){!(a.isUndefined(T)||T===null)&&t.append(s===!0?ye([m],N,o):s===null?m:m+"[]",c(T))}),!1}return ae(f)?!0:(t.append(ye(v,m,o),c(f)),!1)}const p=[],y=Object.assign(Jt,{defaultVisitor:l,convertValue:c,isVisitable:ae});function R(f,m){if(!a.isUndefined(f)){if(p.indexOf(f)!==-1)throw Error("Circular reference detected in "+m.join("."));p.push(f),a.forEach(f,function(E,S){(!(a.isUndefined(E)||E===null)&&r.call(t,E,a.isString(S)?S.trim():S,m,y))===!0&&R(E,m?m.concat(S):[S])}),p.pop()}}if(!a.isObject(e))throw new TypeError("data must be an object");return R(e),t}function be(e){const t={"!":"%21","'":"%27","(":"%28",")":"%29","~":"%7E","%20":"+","%00":"\0"};return encodeURIComponent(e).replace(/[!'()~]|%20|%00/g,function(i){return t[i]})}function pe(e,t){this._pairs=[],e&&ee(e,this,t)}const $e=pe.prototype;$e.append=function(t,n){this._pairs.push([t,n])};$e.toString=function(t){const n=t?function(i){return t.call(this,i,be)}:be;return this._pairs.map(function(r){return n(r[0])+"="+n(r[1])},"").join("&")};function Vt(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}function ze(e,t,n){if(!t)return e;const i=n&&n.encode||Vt;a.isFunction(n)&&(n={serialize:n});const r=n&&n.serialize;let o;if(r?o=r(t,n):o=a.isURLSearchParams(t)?t.toString():new pe(t,n).toString(i),o){const s=e.indexOf("#");s!==-1&&(e=e.slice(0,s)),e+=(e.indexOf("?")===-1?"?":"&")+o}return e}class Ee{constructor(){this.handlers=[]}use(t,n,i){return this.handlers.push({fulfilled:t,rejected:n,synchronous:i?i.synchronous:!1,runWhen:i?i.runWhen:null}),this.handlers.length-1}eject(t){this.handlers[t]&&(this.handlers[t]=null)}clear(){this.handlers&&(this.handlers=[])}forEach(t){a.forEach(this.handlers,function(i){i!==null&&t(i)})}}const Je={silentJSONParsing:!0,forcedJSONParsing:!0,clarifyTimeoutError:!1},Xt=typeof URLSearchParams<"u"?URLSearchParams:pe,Kt=typeof FormData<"u"?FormData:null,Wt=typeof Blob<"u"?Blob:null,Gt={isBrowser:!0,classes:{URLSearchParams:Xt,FormData:Kt,Blob:Wt},protocols:["http","https","file","blob","url","data"]},ve=typeof window<"u"&&typeof document<"u",de=typeof navigator=="object"&&navigator||void 0,Zt=ve&&(!de||["ReactNative","NativeScript","NS"].indexOf(de.product)<0),Qt=typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope&&typeof self.importScripts=="function",Yt=ve&&window.location.href||"http://localhost",en=Object.freeze(Object.defineProperty({__proto__:null,hasBrowserEnv:ve,hasStandardBrowserEnv:Zt,hasStandardBrowserWebWorkerEnv:Qt,navigator:de,origin:Yt},Symbol.toStringTag,{value:"Module"})),O={...en,...Gt};function tn(e,t){return ee(e,new O.classes.URLSearchParams,Object.assign({visitor:function(n,i,r,o){return O.isNode&&a.isBuffer(n)?(this.append(i,n.toString("base64")),!1):o.defaultVisitor.apply(this,arguments)}},t))}function nn(e){return a.matchAll(/\w+|\[(\w*)]/g,e).map(t=>t[0]==="[]"?"":t[1]||t[0])}function rn(e){const t={},n=Object.keys(e);let i;const r=n.length;let o;for(i=0;i=n.length;return s=!s&&a.isArray(r)?r.length:s,u?(a.hasOwnProp(r,s)?r[s]=[r[s],i]:r[s]=i,!d):((!r[s]||!a.isObject(r[s]))&&(r[s]=[]),t(n,i,r[s],o)&&a.isArray(r[s])&&(r[s]=rn(r[s])),!d)}if(a.isFormData(e)&&a.isFunction(e.entries)){const n={};return a.forEachEntry(e,(i,r)=>{t(nn(i),r,n,0)}),n}return null}function on(e,t,n){if(a.isString(e))try{return(t||JSON.parse)(e),a.trim(e)}catch(i){if(i.name!=="SyntaxError")throw i}return(n||JSON.stringify)(e)}const $={transitional:Je,adapter:["xhr","http","fetch"],transformRequest:[function(t,n){const i=n.getContentType()||"",r=i.indexOf("application/json")>-1,o=a.isObject(t);if(o&&a.isHTMLForm(t)&&(t=new FormData(t)),a.isFormData(t))return r?JSON.stringify(Ve(t)):t;if(a.isArrayBuffer(t)||a.isBuffer(t)||a.isStream(t)||a.isFile(t)||a.isBlob(t)||a.isReadableStream(t))return t;if(a.isArrayBufferView(t))return t.buffer;if(a.isURLSearchParams(t))return n.setContentType("application/x-www-form-urlencoded;charset=utf-8",!1),t.toString();let d;if(o){if(i.indexOf("application/x-www-form-urlencoded")>-1)return tn(t,this.formSerializer).toString();if((d=a.isFileList(t))||i.indexOf("multipart/form-data")>-1){const u=this.env&&this.env.FormData;return ee(d?{"files[]":t}:t,u&&new u,this.formSerializer)}}return o||r?(n.setContentType("application/json",!1),on(t)):t}],transformResponse:[function(t){const n=this.transitional||$.transitional,i=n&&n.forcedJSONParsing,r=this.responseType==="json";if(a.isResponse(t)||a.isReadableStream(t))return t;if(t&&a.isString(t)&&(i&&!this.responseType||r)){const s=!(n&&n.silentJSONParsing)&&r;try{return JSON.parse(t)}catch(d){if(s)throw d.name==="SyntaxError"?h.from(d,h.ERR_BAD_RESPONSE,this,null,this.response):d}}return t}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,env:{FormData:O.classes.FormData,Blob:O.classes.Blob},validateStatus:function(t){return t>=200&&t<300},headers:{common:{Accept:"application/json, text/plain, */*","Content-Type":void 0}}};a.forEach(["delete","get","head","post","put","patch"],e=>{$.headers[e]={}});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"]),an=e=>{const t={};let n,i,r;return e&&e.split(` +`).forEach(function(s){r=s.indexOf(":"),n=s.substring(0,r).trim().toLowerCase(),i=s.substring(r+1).trim(),!(!n||t[n]&&sn[n])&&(n==="set-cookie"?t[n]?t[n].push(i):t[n]=[i]:t[n]=t[n]?t[n]+", "+i:i)}),t},ge=Symbol("internals");function I(e){return e&&String(e).trim().toLowerCase()}function V(e){return e===!1||e==null?e:a.isArray(e)?e.map(V):String(e)}function dn(e){const t=Object.create(null),n=/([^\s,;=]+)\s*(?:=\s*([^,;]+))?/g;let i;for(;i=n.exec(e);)t[i[1]]=i[2];return t}const cn=e=>/^[-_a-zA-Z0-9^`|~,!#$%&'*+.]+$/.test(e.trim());function ie(e,t,n,i,r){if(a.isFunction(i))return i.call(this,t,n);if(r&&(t=n),!!a.isString(t)){if(a.isString(i))return t.indexOf(i)!==-1;if(a.isRegExp(i))return i.test(t)}}function ln(e){return e.trim().toLowerCase().replace(/([a-z\d])(\w*)/g,(t,n,i)=>n.toUpperCase()+i)}function un(e,t){const n=a.toCamelCase(" "+t);["get","set","has"].forEach(i=>{Object.defineProperty(e,i+n,{value:function(r,o,s){return this[i].call(this,t,r,o,s)},configurable:!0})})}let C=class{constructor(t){t&&this.set(t)}set(t,n,i){const r=this;function o(d,u,c){const l=I(u);if(!l)throw new Error("header name must be a non-empty string");const p=a.findKey(r,l);(!p||r[p]===void 0||c===!0||c===void 0&&r[p]!==!1)&&(r[p||u]=V(d))}const s=(d,u)=>a.forEach(d,(c,l)=>o(c,l,u));if(a.isPlainObject(t)||t instanceof this.constructor)s(t,n);else if(a.isString(t)&&(t=t.trim())&&!cn(t))s(an(t),n);else if(a.isObject(t)&&a.isIterable(t)){let d={},u,c;for(const l of t){if(!a.isArray(l))throw TypeError("Object iterator must return a key-value pair");d[c=l[0]]=(u=d[c])?a.isArray(u)?[...u,l[1]]:[u,l[1]]:l[1]}s(d,n)}else t!=null&&o(n,t,i);return this}get(t,n){if(t=I(t),t){const i=a.findKey(this,t);if(i){const r=this[i];if(!n)return r;if(n===!0)return dn(r);if(a.isFunction(n))return n.call(this,r,i);if(a.isRegExp(n))return n.exec(r);throw new TypeError("parser must be boolean|regexp|function")}}}has(t,n){if(t=I(t),t){const i=a.findKey(this,t);return!!(i&&this[i]!==void 0&&(!n||ie(this,this[i],i,n)))}return!1}delete(t,n){const i=this;let r=!1;function o(s){if(s=I(s),s){const d=a.findKey(i,s);d&&(!n||ie(i,i[d],d,n))&&(delete i[d],r=!0)}}return a.isArray(t)?t.forEach(o):o(t),r}clear(t){const n=Object.keys(this);let i=n.length,r=!1;for(;i--;){const o=n[i];(!t||ie(this,this[o],o,t,!0))&&(delete this[o],r=!0)}return r}normalize(t){const n=this,i={};return a.forEach(this,(r,o)=>{const s=a.findKey(i,o);if(s){n[s]=V(r),delete n[o];return}const d=t?ln(o):String(o).trim();d!==o&&delete n[o],n[d]=V(r),i[d]=!0}),this}concat(...t){return this.constructor.concat(this,...t)}toJSON(t){const n=Object.create(null);return a.forEach(this,(i,r)=>{i!=null&&i!==!1&&(n[r]=t&&a.isArray(i)?i.join(", "):i)}),n}[Symbol.iterator](){return Object.entries(this.toJSON())[Symbol.iterator]()}toString(){return Object.entries(this.toJSON()).map(([t,n])=>t+": "+n).join(` +`)}getSetCookie(){return this.get("set-cookie")||[]}get[Symbol.toStringTag](){return"AxiosHeaders"}static from(t){return t instanceof this?t:new this(t)}static concat(t,...n){const i=new this(t);return n.forEach(r=>i.set(r)),i}static accessor(t){const i=(this[ge]=this[ge]={accessors:{}}).accessors,r=this.prototype;function o(s){const d=I(s);i[d]||(un(r,s),i[d]=!0)}return a.isArray(t)?t.forEach(o):o(t),this}};C.accessor(["Content-Type","Content-Length","Accept","Accept-Encoding","User-Agent","Authorization"]);a.reduceDescriptors(C.prototype,({value:e},t)=>{let n=t[0].toUpperCase()+t.slice(1);return{get:()=>e,set(i){this[n]=i}}});a.freezeMethods(C);function re(e,t){const n=this||$,i=t||n,r=C.from(i.headers);let o=i.data;return a.forEach(e,function(d){o=d.call(n,o,r.normalize(),t?t.status:void 0)}),r.normalize(),o}function Xe(e){return!!(e&&e.__CANCEL__)}function q(e,t,n){h.call(this,e??"canceled",h.ERR_CANCELED,t,n),this.name="CanceledError"}a.inherits(q,h,{__CANCEL__:!0});function Ke(e,t,n){const i=n.config.validateStatus;!n.status||!i||i(n.status)?e(n):t(new h("Request failed with status code "+n.status,[h.ERR_BAD_REQUEST,h.ERR_BAD_RESPONSE][Math.floor(n.status/100)-4],n.config,n.request,n))}function fn(e){const t=/^([-+\w]{1,25})(:?\/\/|:)/.exec(e);return t&&t[1]||""}function pn(e,t){e=e||10;const n=new Array(e),i=new Array(e);let r=0,o=0,s;return t=t!==void 0?t:1e3,function(u){const c=Date.now(),l=i[o];s||(s=c),n[r]=u,i[r]=c;let p=o,y=0;for(;p!==r;)y+=n[p++],p=p%e;if(r=(r+1)%e,r===o&&(o=(o+1)%e),c-s{n=l,r=null,o&&(clearTimeout(o),o=null),e.apply(null,c)};return[(...c)=>{const l=Date.now(),p=l-n;p>=i?s(c,l):(r=c,o||(o=setTimeout(()=>{o=null,s(r)},i-p)))},()=>r&&s(r)]}const K=(e,t,n=3)=>{let i=0;const r=pn(50,250);return vn(o=>{const s=o.loaded,d=o.lengthComputable?o.total:void 0,u=s-i,c=r(u),l=s<=d;i=s;const p={loaded:s,total:d,progress:d?s/d:void 0,bytes:u,rate:c||void 0,estimated:c&&d&&l?(d-s)/c:void 0,event:o,lengthComputable:d!=null,[t?"download":"upload"]:!0};e(p)},n)},Re=(e,t)=>{const n=e!=null;return[i=>t[0]({lengthComputable:n,total:e,loaded:i}),t[1]]},Se=e=>(...t)=>a.asap(()=>e(...t)),hn=O.hasStandardBrowserEnv?((e,t)=>n=>(n=new URL(n,O.origin),e.protocol===n.protocol&&e.host===n.host&&(t||e.port===n.port)))(new URL(O.origin),O.navigator&&/(msie|trident)/i.test(O.navigator.userAgent)):()=>!0,mn=O.hasStandardBrowserEnv?{write(e,t,n,i,r,o){const s=[e+"="+encodeURIComponent(t)];a.isNumber(n)&&s.push("expires="+new Date(n).toGMTString()),a.isString(i)&&s.push("path="+i),a.isString(r)&&s.push("domain="+r),o===!0&&s.push("secure"),document.cookie=s.join("; ")},read(e){const t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove(e){this.write(e,"",Date.now()-864e5)}}:{write(){},read(){return null},remove(){}};function wn(e){return/^([a-z][a-z\d+\-.]*:)?\/\//i.test(e)}function yn(e,t){return t?e.replace(/\/?\/$/,"")+"/"+t.replace(/^\/+/,""):e}function We(e,t,n){let i=!wn(t);return e&&(i||n==!1)?yn(e,t):t}const Te=e=>e instanceof C?{...e}:e;function D(e,t){t=t||{};const n={};function i(c,l,p,y){return a.isPlainObject(c)&&a.isPlainObject(l)?a.merge.call({caseless:y},c,l):a.isPlainObject(l)?a.merge({},l):a.isArray(l)?l.slice():l}function r(c,l,p,y){if(a.isUndefined(l)){if(!a.isUndefined(c))return i(void 0,c,p,y)}else return i(c,l,p,y)}function o(c,l){if(!a.isUndefined(l))return i(void 0,l)}function s(c,l){if(a.isUndefined(l)){if(!a.isUndefined(c))return i(void 0,c)}else return i(void 0,l)}function d(c,l,p){if(p in t)return i(c,l);if(p in e)return i(void 0,c)}const u={url:o,method:o,data:o,baseURL:s,transformRequest:s,transformResponse:s,paramsSerializer:s,timeout:s,timeoutMessage:s,withCredentials:s,withXSRFToken:s,adapter:s,responseType:s,xsrfCookieName:s,xsrfHeaderName:s,onUploadProgress:s,onDownloadProgress:s,decompress:s,maxContentLength:s,maxBodyLength:s,beforeRedirect:s,transport:s,httpAgent:s,httpsAgent:s,cancelToken:s,socketPath:s,responseEncoding:s,validateStatus:d,headers:(c,l,p)=>r(Te(c),Te(l),p,!0)};return a.forEach(Object.keys(Object.assign({},e,t)),function(l){const p=u[l]||r,y=p(e[l],t[l],l);a.isUndefined(y)&&p!==d||(n[l]=y)}),n}const Ge=e=>{const t=D({},e);let{data:n,withXSRFToken:i,xsrfHeaderName:r,xsrfCookieName:o,headers:s,auth:d}=t;t.headers=s=C.from(s),t.url=ze(We(t.baseURL,t.url,t.allowAbsoluteUrls),e.params,e.paramsSerializer),d&&s.set("Authorization","Basic "+btoa((d.username||"")+":"+(d.password?unescape(encodeURIComponent(d.password)):"")));let u;if(a.isFormData(n)){if(O.hasStandardBrowserEnv||O.hasStandardBrowserWebWorkerEnv)s.setContentType(void 0);else if((u=s.getContentType())!==!1){const[c,...l]=u?u.split(";").map(p=>p.trim()).filter(Boolean):[];s.setContentType([c||"multipart/form-data",...l].join("; "))}}if(O.hasStandardBrowserEnv&&(i&&a.isFunction(i)&&(i=i(t)),i||i!==!1&&hn(t.url))){const c=r&&o&&mn.read(o);c&&s.set(r,c)}return t},bn=typeof XMLHttpRequest<"u",En=bn&&function(e){return new Promise(function(n,i){const r=Ge(e);let o=r.data;const s=C.from(r.headers).normalize();let{responseType:d,onUploadProgress:u,onDownloadProgress:c}=r,l,p,y,R,f;function m(){R&&R(),f&&f(),r.cancelToken&&r.cancelToken.unsubscribe(l),r.signal&&r.signal.removeEventListener("abort",l)}let v=new XMLHttpRequest;v.open(r.method.toUpperCase(),r.url,!0),v.timeout=r.timeout;function E(){if(!v)return;const T=C.from("getAllResponseHeaders"in v&&v.getAllResponseHeaders()),_={data:!d||d==="text"||d==="json"?v.responseText:v.response,status:v.status,statusText:v.statusText,headers:T,config:e,request:v};Ke(function(B){n(B),m()},function(B){i(B),m()},_),v=null}"onloadend"in v?v.onloadend=E:v.onreadystatechange=function(){!v||v.readyState!==4||v.status===0&&!(v.responseURL&&v.responseURL.indexOf("file:")===0)||setTimeout(E)},v.onabort=function(){v&&(i(new h("Request aborted",h.ECONNABORTED,e,v)),v=null)},v.onerror=function(){i(new h("Network Error",h.ERR_NETWORK,e,v)),v=null},v.ontimeout=function(){let N=r.timeout?"timeout of "+r.timeout+"ms exceeded":"timeout exceeded";const _=r.transitional||Je;r.timeoutErrorMessage&&(N=r.timeoutErrorMessage),i(new h(N,_.clarifyTimeoutError?h.ETIMEDOUT:h.ECONNABORTED,e,v)),v=null},o===void 0&&s.setContentType(null),"setRequestHeader"in v&&a.forEach(s.toJSON(),function(N,_){v.setRequestHeader(_,N)}),a.isUndefined(r.withCredentials)||(v.withCredentials=!!r.withCredentials),d&&d!=="json"&&(v.responseType=r.responseType),c&&([y,f]=K(c,!0),v.addEventListener("progress",y)),u&&v.upload&&([p,R]=K(u),v.upload.addEventListener("progress",p),v.upload.addEventListener("loadend",R)),(r.cancelToken||r.signal)&&(l=T=>{v&&(i(!T||T.type?new q(null,e,v):T),v.abort(),v=null)},r.cancelToken&&r.cancelToken.subscribe(l),r.signal&&(r.signal.aborted?l():r.signal.addEventListener("abort",l)));const S=fn(r.url);if(S&&O.protocols.indexOf(S)===-1){i(new h("Unsupported protocol "+S+":",h.ERR_BAD_REQUEST,e));return}v.send(o||null)})},gn=(e,t)=>{const{length:n}=e=e?e.filter(Boolean):[];if(t||n){let i=new AbortController,r;const o=function(c){if(!r){r=!0,d();const l=c instanceof Error?c:this.reason;i.abort(l instanceof h?l:new q(l instanceof Error?l.message:l))}};let s=t&&setTimeout(()=>{s=null,o(new h(`timeout ${t} of ms exceeded`,h.ETIMEDOUT))},t);const d=()=>{e&&(s&&clearTimeout(s),s=null,e.forEach(c=>{c.unsubscribe?c.unsubscribe(o):c.removeEventListener("abort",o)}),e=null)};e.forEach(c=>c.addEventListener("abort",o));const{signal:u}=i;return u.unsubscribe=()=>a.asap(d),u}},Rn=function*(e,t){let n=e.byteLength;if(n{const r=Sn(e,t);let o=0,s,d=u=>{s||(s=!0,i&&i(u))};return new ReadableStream({async pull(u){try{const{done:c,value:l}=await r.next();if(c){d(),u.close();return}let p=l.byteLength;if(n){let y=o+=p;n(y)}u.enqueue(new Uint8Array(l))}catch(c){throw d(c),c}},cancel(u){return d(u),r.return()}},{highWaterMark:2})},te=typeof fetch=="function"&&typeof Request=="function"&&typeof Response=="function",Ze=te&&typeof ReadableStream=="function",An=te&&(typeof TextEncoder=="function"?(e=>t=>e.encode(t))(new TextEncoder):async e=>new Uint8Array(await new Response(e).arrayBuffer())),Qe=(e,...t)=>{try{return!!e(...t)}catch{return!1}},On=Ze&&Qe(()=>{let e=!1;const t=new Request(O.origin,{body:new ReadableStream,method:"POST",get duplex(){return e=!0,"half"}}).headers.has("Content-Type");return e&&!t}),Oe=64*1024,ce=Ze&&Qe(()=>a.isReadableStream(new Response("").body)),W={stream:ce&&(e=>e.body)};te&&(e=>{["text","arrayBuffer","blob","formData","stream"].forEach(t=>{!W[t]&&(W[t]=a.isFunction(e[t])?n=>n[t]():(n,i)=>{throw new h(`Response type '${t}' is not supported`,h.ERR_NOT_SUPPORT,i)})})})(new Response);const _n=async e=>{if(e==null)return 0;if(a.isBlob(e))return e.size;if(a.isSpecCompliantForm(e))return(await new Request(O.origin,{method:"POST",body:e}).arrayBuffer()).byteLength;if(a.isArrayBufferView(e)||a.isArrayBuffer(e))return e.byteLength;if(a.isURLSearchParams(e)&&(e=e+""),a.isString(e))return(await An(e)).byteLength},xn=async(e,t)=>{const n=a.toFiniteNumber(e.getContentLength());return n??_n(t)},Cn=te&&(async e=>{let{url:t,method:n,data:i,signal:r,cancelToken:o,timeout:s,onDownloadProgress:d,onUploadProgress:u,responseType:c,headers:l,withCredentials:p="same-origin",fetchOptions:y}=Ge(e);c=c?(c+"").toLowerCase():"text";let R=gn([r,o&&o.toAbortSignal()],s),f;const m=R&&R.unsubscribe&&(()=>{R.unsubscribe()});let v;try{if(u&&On&&n!=="get"&&n!=="head"&&(v=await xn(l,i))!==0){let _=new Request(t,{method:"POST",body:i,duplex:"half"}),L;if(a.isFormData(i)&&(L=_.headers.get("content-type"))&&l.setContentType(L),_.body){const[B,z]=Re(v,K(Se(u)));i=Ae(_.body,Oe,B,z)}}a.isString(p)||(p=p?"include":"omit");const E="credentials"in Request.prototype;f=new Request(t,{...y,signal:R,method:n.toUpperCase(),headers:l.normalize().toJSON(),body:i,duplex:"half",credentials:E?p:void 0});let S=await fetch(f,y);const T=ce&&(c==="stream"||c==="response");if(ce&&(d||T&&m)){const _={};["status","statusText","headers"].forEach(me=>{_[me]=S[me]});const L=a.toFiniteNumber(S.headers.get("content-length")),[B,z]=d&&Re(L,K(Se(d),!0))||[];S=new Response(Ae(S.body,Oe,B,()=>{z&&z(),m&&m()}),_)}c=c||"text";let N=await W[a.findKey(W,c)||"text"](S,e);return!T&&m&&m(),await new Promise((_,L)=>{Ke(_,L,{data:N,headers:C.from(S.headers),status:S.status,statusText:S.statusText,config:e,request:f})})}catch(E){throw m&&m(),E&&E.name==="TypeError"&&/Load failed|fetch/i.test(E.message)?Object.assign(new h("Network Error",h.ERR_NETWORK,e,f),{cause:E.cause||E}):h.from(E,E&&E.code,e,f)}}),le={http:$t,xhr:En,fetch:Cn};a.forEach(le,(e,t)=>{if(e){try{Object.defineProperty(e,"name",{value:t})}catch{}Object.defineProperty(e,"adapterName",{value:t})}});const _e=e=>`- ${e}`,Pn=e=>a.isFunction(e)||e===null||e===!1,Ye={getAdapter:e=>{e=a.isArray(e)?e:[e];const{length:t}=e;let n,i;const r={};for(let o=0;o`adapter ${d} `+(u===!1?"is not supported by the environment":"is not available in the build"));let s=t?o.length>1?`since : +`+o.map(_e).join(` +`):" "+_e(o[0]):"as no adapter specified";throw new h("There is no suitable adapter to dispatch the request "+s,"ERR_NOT_SUPPORT")}return i},adapters:le};function oe(e){if(e.cancelToken&&e.cancelToken.throwIfRequested(),e.signal&&e.signal.aborted)throw new q(null,e)}function xe(e){return oe(e),e.headers=C.from(e.headers),e.data=re.call(e,e.transformRequest),["post","put","patch"].indexOf(e.method)!==-1&&e.headers.setContentType("application/x-www-form-urlencoded",!1),Ye.getAdapter(e.adapter||$.adapter)(e).then(function(i){return oe(e),i.data=re.call(e,e.transformResponse,i),i.headers=C.from(i.headers),i},function(i){return Xe(i)||(oe(e),i&&i.response&&(i.response.data=re.call(e,e.transformResponse,i.response),i.response.headers=C.from(i.response.headers))),Promise.reject(i)})}const et="1.10.0",ne={};["object","boolean","number","function","string","symbol"].forEach((e,t)=>{ne[e]=function(i){return typeof i===e||"a"+(t<1?"n ":" ")+e}});const Ce={};ne.transitional=function(t,n,i){function r(o,s){return"[Axios v"+et+"] Transitional option '"+o+"'"+s+(i?". "+i:"")}return(o,s,d)=>{if(t===!1)throw new h(r(s," has been removed"+(n?" in "+n:"")),h.ERR_DEPRECATED);return n&&!Ce[s]&&(Ce[s]=!0,console.warn(r(s," has been deprecated since v"+n+" and will be removed in the near future"))),t?t(o,s,d):!0}};ne.spelling=function(t){return(n,i)=>(console.warn(`${i} is likely a misspelling of ${t}`),!0)};function kn(e,t,n){if(typeof e!="object")throw new h("options must be an object",h.ERR_BAD_OPTION_VALUE);const i=Object.keys(e);let r=i.length;for(;r-- >0;){const o=i[r],s=t[o];if(s){const d=e[o],u=d===void 0||s(d,o,e);if(u!==!0)throw new h("option "+o+" must be "+u,h.ERR_BAD_OPTION_VALUE);continue}if(n!==!0)throw new h("Unknown option "+o,h.ERR_BAD_OPTION)}}const X={assertOptions:kn,validators:ne},k=X.validators;let U=class{constructor(t){this.defaults=t||{},this.interceptors={request:new Ee,response:new Ee}}async request(t,n){try{return await this._request(t,n)}catch(i){if(i instanceof Error){let r={};Error.captureStackTrace?Error.captureStackTrace(r):r=new Error;const o=r.stack?r.stack.replace(/^.+\n/,""):"";try{i.stack?o&&!String(i.stack).endsWith(o.replace(/^.+\n.+\n/,""))&&(i.stack+=` +`+o):i.stack=o}catch{}}throw i}}_request(t,n){typeof t=="string"?(n=n||{},n.url=t):n=t||{},n=D(this.defaults,n);const{transitional:i,paramsSerializer:r,headers:o}=n;i!==void 0&&X.assertOptions(i,{silentJSONParsing:k.transitional(k.boolean),forcedJSONParsing:k.transitional(k.boolean),clarifyTimeoutError:k.transitional(k.boolean)},!1),r!=null&&(a.isFunction(r)?n.paramsSerializer={serialize:r}:X.assertOptions(r,{encode:k.function,serialize:k.function},!0)),n.allowAbsoluteUrls!==void 0||(this.defaults.allowAbsoluteUrls!==void 0?n.allowAbsoluteUrls=this.defaults.allowAbsoluteUrls:n.allowAbsoluteUrls=!0),X.assertOptions(n,{baseUrl:k.spelling("baseURL"),withXsrfToken:k.spelling("withXSRFToken")},!0),n.method=(n.method||this.defaults.method||"get").toLowerCase();let s=o&&a.merge(o.common,o[n.method]);o&&a.forEach(["delete","get","head","post","put","patch","common"],f=>{delete o[f]}),n.headers=C.concat(s,o);const d=[];let u=!0;this.interceptors.request.forEach(function(m){typeof m.runWhen=="function"&&m.runWhen(n)===!1||(u=u&&m.synchronous,d.unshift(m.fulfilled,m.rejected))});const c=[];this.interceptors.response.forEach(function(m){c.push(m.fulfilled,m.rejected)});let l,p=0,y;if(!u){const f=[xe.bind(this),void 0];for(f.unshift.apply(f,d),f.push.apply(f,c),y=f.length,l=Promise.resolve(n);p{if(!i._listeners)return;let o=i._listeners.length;for(;o-- >0;)i._listeners[o](r);i._listeners=null}),this.promise.then=r=>{let o;const s=new Promise(d=>{i.subscribe(d),o=d}).then(r);return s.cancel=function(){i.unsubscribe(o)},s},t(function(o,s,d){i.reason||(i.reason=new q(o,s,d),n(i.reason))})}throwIfRequested(){if(this.reason)throw this.reason}subscribe(t){if(this.reason){t(this.reason);return}this._listeners?this._listeners.push(t):this._listeners=[t]}unsubscribe(t){if(!this._listeners)return;const n=this._listeners.indexOf(t);n!==-1&&this._listeners.splice(n,1)}toAbortSignal(){const t=new AbortController,n=i=>{t.abort(i)};return this.subscribe(n),t.signal.unsubscribe=()=>this.unsubscribe(n),t.signal}static source(){let t;return{token:new tt(function(r){t=r}),cancel:t}}};function Ln(e){return function(n){return e.apply(null,n)}}function Bn(e){return a.isObject(e)&&e.isAxiosError===!0}const ue={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(ue).forEach(([e,t])=>{ue[t]=e});function nt(e){const t=new U(e),n=Ne(U.prototype.request,t);return a.extend(n,U.prototype,t,{allOwnKeys:!0}),a.extend(n,t,null,{allOwnKeys:!0}),n.create=function(r){return nt(D(e,r))},n}const g=nt($);g.Axios=U;g.CanceledError=q;g.CancelToken=Nn;g.isCancel=Xe;g.VERSION=et;g.toFormData=ee;g.AxiosError=h;g.Cancel=g.CanceledError;g.all=function(t){return Promise.all(t)};g.spread=Ln;g.isAxiosError=Bn;g.mergeConfig=D;g.AxiosHeaders=C;g.formToJSON=e=>Ve(a.isHTMLForm(e)?new FormData(e):e);g.getAdapter=Ye.getAdapter;g.HttpStatusCode=ue;g.default=g;const{Axios:Yn,AxiosError:ei,CanceledError:ti,isCancel:ni,CancelToken:ii,VERSION:ri,all:oi,Cancel:si,isAxiosError:ai,spread:di,toFormData:ci,AxiosHeaders:li,HttpStatusCode:ui,formToJSON:fi,getAdapter:pi,mergeConfig:vi}=g,he=g.create({baseURL:"http://localhost:4000/api/v1",headers:{"Content-Type":"application/json"}});class Fn{async sync(t){try{const{data:n}=await he.post("/products/sync",{items:t});return console.log("[NestJS] Response (bulk):",n),n}catch(n){throw console.error("[NestJS] Error (bulk):",n),n}}}const Un=new Fn;function b(e){return new Promise(t=>setTimeout(t,e))}class Dn{base64ToFile(t,n,i){const r=t.includes(",")?t.split(",")[1]:t,o=atob(r),s=new ArrayBuffer(o.length),d=new Uint8Array(s);for(let c=0;c{let s=0,d=!1;const u=()=>{const c=document.evaluate(d&&r?r:t,document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;if(c instanceof HTMLElement){o(c);return}s++,s{const s=new FileReader;s.onloadend=()=>{typeof s.result=="string"?r(s.result.split(",")[1]):o("Không thể đọc dữ liệu ảnh")},s.onerror=o,s.readAsDataURL(i)})}getImageExtension(t){try{const i=new URL(t).pathname.match(/\.([a-zA-Z0-9]+)$/);return i?i[1].toLowerCase():null}catch{const r=t.split("?")[0].match(/\.([a-zA-Z0-9]+)$/);return r?r[1].toLowerCase():null}}imageLocalToBase64(t){return new Promise((n,i)=>{try{const r=chrome.runtime.getURL(`${t}`);fetch(r).then(o=>o.blob()).then(o=>{const s=new FileReader;s.onloadend=()=>n(s.result),s.onerror=i,s.readAsDataURL(o)}).catch(i)}catch(r){i(r)}})}scrollToElement(t,n="smooth"){t&&t.scrollIntoView({behavior:n,block:"center",inline:"nearest"})}getElementPointCoores(t){if(!t)return null;const n=t.getBoundingClientRect(),i=n.left+n.width/2,r=n.top+n.height/2;return{x:i,y:r}}setInputValue(t,n){t&&(t.value=n,t.dispatchEvent(new Event("input",{bubbles:!0})),t.dispatchEvent(new Event("change",{bubbles:!0})))}writeToInput=async(t,n,i)=>{const r=await this.getElementByXPath(n,{xpathFallback:i});if(!r)throw new Error("Xpath is not found with value: "+t);this.scrollToElement(r),this.clickByPoint(r),this.setInputValue(r,t)};pressEnter(t){if(!t)throw new Error("Textarea not found:",t);t.focus(),["keydown","keypress","keyup"].forEach(n=>{t.dispatchEvent(new KeyboardEvent(n,{key:"Enter",code:"Enter",keyCode:13,which:13,bubbles:!0,cancelable:!0}))})}}const w=new Dn,A={file__image_input:'input[type="file"]',title_input:"/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[5]/div/div/div/label/div/input",price_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[6]/div/div/div/label/div/input",brand_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/input",brand_input_fallback:"/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[10]/div/div/div[2]/div/div/div/label/div/input",description_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[3]/div/div/div/label/div/div/textarea",description_input_falback:"/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[10]/div/div/div[3]/div/div/div/label/div/div/textarea",sku_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[6]/div/div/div[1]/label/div/input",sku_input_fallback:"/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[10]/div/div/div[6]/div/div/div[1]/label/div/input",category_select:{wraper:"/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]/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div/div/span/div"},condition_select:{wraper:"/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[8]/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/div/div/div/div[1]/div"},tags_input:{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/div[1]/label/div/div/div[2]/div/textarea",input_falback:"/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[10]/div/div/div[5]/div/div/div/div[1]/label/div/div/div[2]/div/textarea"},location_select:{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[7]/div/div/div/div/div/div/div/div/label/div[2]/input",input_fallback:"/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[10]/div/div/div[7]/div/div/div/div/div/div/div/div/label/div[2]/input",wraper:"/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[7]/div/div/div/div/div/div/div/div",container:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/ul",container_fallback:"/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[2]/div/div/div[1]/div[1]/div/ul"},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",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"},jn=async e=>{const t=new DataTransfer;for(const i of e.images){const r=await w.imageUrlToBase64(i);console.log("Base64:",i.slice(0,50)+"...");const o=w.base64ToFile(r,e.sku,w.getImageExtension(i)||"jpg");t.items.add(o)}const n=document.querySelector(A.file__image_input);n?(n.files=t.files,n.dispatchEvent(new Event("change",{bubbles:!0}))):console.error("Không tìm thấy input[type='file']")},Pe=async(e,t)=>{const n=await w.getElementByXPath(t.wraper);if(!n)throw new Error("Wrapper xpath not found");w.scrollToElement(n),w.clickByPoint(n),await b(200);const i=await w.getElementByXPath(t.container);if(!i)throw new Error("Container xpath not found");const r=Array.from(i.children).find(o=>o.textContent?.trim().toLocaleLowerCase().replace(/–/g,"-").includes(e.toLocaleLowerCase()));if(!r)throw new Error(`No child found with text "${e}"`);w.scrollToElement(r),await b(200),w.clickByPoint(r)},qn=async(e,{input:t,...n})=>{await w.writeToInput(e,t,n.input_fallback),await b(200);const i=await w.getElementByXPath(n.container,{xpathFallback:n.container_fallback});if(!i)throw new Error("Container xpath not found");w.scrollToElement(i);const r=Array.from(i.children).find(o=>o.textContent?.trim().toLocaleLowerCase().includes(e.toLocaleLowerCase()));if(!r)throw new Error(`No child found with text "${e}"`);w.scrollToElement(r),await b(200),w.clickByPoint(r)},In=async(e,t)=>{const n=await w.getElementByXPath(t.input,{xpathFallback:t?.input_falback});if(!n)throw new Error("Input is not found");w.scrollToElement(n),await b(200);for(const i of e)await w.writeToInput(i,t.input,t?.input_falback),await b(200),w.pressEnter(n)},ke=async(e,t)=>{const{data:n}=await he({url:"products/publist-finish/"+e.id,method:"POST",data:t});return n},Mn=async(e,t)=>{const{data:n}=await he({url:"products/delete-finish/"+e.id,method:"POST",data:t});return n},Hn=async()=>{const e=await w.getElementByXPath(A.next_btn);if(!e)throw new Error("Next button is not found");w.clickByPoint(e)},$n=async()=>{const e=await w.getElementByXPath(A.publish_btn);if(!e)throw new Error("Publist button is not found");w.clickByPoint(e)};function zn(e){return Array.from(e.children).map(n=>{const r=n.querySelector('span[dir="auto"], div[dir="auto"]')?.textContent?.trim()||"",s=Array.from(n.querySelectorAll('span[dir="auto"]')).find(u=>/\d/.test(u.textContent||"")&&/[AU$]/.test(u.textContent||""))?.textContent?.match(/\d+(?:\.\d+)?/),d=s?parseFloat(s[0]):0;return{title:r,price:d,el:e}})}const Jn=async e=>(console.log({item:e}),await b(1e3),await jn(e),await b(200),w.writeToInput(e.title,A.title_input),await b(200),w.writeToInput(String(e.price),A.price_input),await b(200),await Pe(e.category,A.category_select),await b(200),await Pe(e.condition,A.condition_select),e.brand&&(await b(200),await w.writeToInput(e.brand,A.brand_input,A.brand_input_fallback)),await b(200),await w.writeToInput(e.description,A.description_input,A.description_input_falback),await b(200),await In(e.tags,A.tags_input),await b(200),await w.writeToInput(e.sku,A.sku_input,A.sku_input_fallback),e?.location&&(await b(200),await qn(e.location,A.location_select)),await b(200),await Hn(),await b(200),await $n(),!0),it=async()=>{const e=await w.getElementByXPath(A.products);return e?zn(e):[]},Vn=async()=>{if(!window.location.href.includes("https://www.facebook.com/marketplace/you/selling"))return;const t=await it();if(!t.length)return;const n=await Un.sync(t.map(i=>({title:i.title,price:i.price})));console.log({response:n})},Xn=async e=>{chrome.runtime.sendMessage({type:"close-tab",payload:e})},Kn=async e=>{const t=await it(),n=t.find(c=>c.title==e.title&&c.price==e.price);if(console.log({payload:e,product:n,products:t}),!n)return;const r=n.el.querySelector(`[aria-label="More options for ${n.title}"]`);if(console.log({optionEl:r}),!r)return;r.click?.(),await b(2e3);const o=Array.from(document.querySelectorAll('[role="menuitem"]'));console.log({items:o}),o.find(c=>c.textContent.toLocaleLowerCase().includes("delete")).click?.(),await b(1e3);const d=await w.getElementByXPath("/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",{xpathFallback:"/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]"});console.log({btnDelete:d}),d?.click(),(await w.getElementByXPath("/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[2]/div"))?.click(),await Mn(e,{published:!1}),chrome.runtime.sendMessage({type:"delete-done"})},Wn=chrome.runtime.connect();Wn.onMessage.addListener(async e=>{if(e.type==="publist-event"){const t=e.payload;if(!t)return;console.log("Received new product event:",t);try{await b(500),await Jn(t)}catch(n){await ke(t,{error:n.message,published:!1})}finally{await ke(t,{published:!0}),await b(5e3),await Xn(t)}}});chrome.runtime.onMessage.addListener(e=>{e.type==="DELETE_STREAM_DATA"&&(console.log("Nhận dữ liệu từ background:",e.payload),Kn(e.payload))});async function Gn(){await Vn()}Gn(); diff --git a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/manifest.json b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/manifest.json index 796ccae..4849141 100644 --- a/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/manifest.json +++ b/auto-listing-facebook-marketplace/auto-listing-facebook-marketplace/manifest.json @@ -6,11 +6,17 @@ "permissions": ["storage", "tabs", "alarms"], - "host_permissions": ["https://www.facebook.com/marketplace/*"], + "host_permissions": [ + "https://www.facebook.com/marketplace/*", + "https://web.facebook.com/*" + ], "content_scripts": [ { - "matches": ["https://www.facebook.com/marketplace/*"], + "matches": [ + "https://www.facebook.com/marketplace/*", + "https://web.facebook.com/marketplace/*" + ], "js": ["content.js"], "run_at": "document_idle", "type": "module" diff --git a/auto-listing-facebook-marketplace/public/manifest.json b/auto-listing-facebook-marketplace/public/manifest.json index 796ccae..4849141 100644 --- a/auto-listing-facebook-marketplace/public/manifest.json +++ b/auto-listing-facebook-marketplace/public/manifest.json @@ -6,11 +6,17 @@ "permissions": ["storage", "tabs", "alarms"], - "host_permissions": ["https://www.facebook.com/marketplace/*"], + "host_permissions": [ + "https://www.facebook.com/marketplace/*", + "https://web.facebook.com/*" + ], "content_scripts": [ { - "matches": ["https://www.facebook.com/marketplace/*"], + "matches": [ + "https://www.facebook.com/marketplace/*", + "https://web.facebook.com/marketplace/*" + ], "js": ["content.js"], "run_at": "document_idle", "type": "module" diff --git a/auto-listing-facebook-marketplace/src/api/message-api.service.ts b/auto-listing-facebook-marketplace/src/api/message-api.service.ts deleted file mode 100644 index 90e7f4e..0000000 --- a/auto-listing-facebook-marketplace/src/api/message-api.service.ts +++ /dev/null @@ -1,27 +0,0 @@ -import axios from "@/lib/axios"; - -class MessageApiService { - async sendSingleMessage(message: IMessage) { - try { - const { data } = await axios.post("/messages", message); - console.log("[NestJS] Response (single):", data); - return data; - } catch (err) { - console.error("[NestJS] Error (single):", err); - throw err; - } - } - - async sendBulkMessages(messages: IMessage[]) { - try { - const { data } = await axios.post("/messages/bulk", { data: messages }); - console.log("[NestJS] Response (bulk):", data); - return data; - } catch (err) { - console.error("[NestJS] Error (bulk):", err); - throw err; - } - } -} - -export const messageApi = new MessageApiService(); diff --git a/auto-listing-facebook-marketplace/src/api/product-api.service.ts b/auto-listing-facebook-marketplace/src/api/product-api.service.ts new file mode 100644 index 0000000..8a65e1f --- /dev/null +++ b/auto-listing-facebook-marketplace/src/api/product-api.service.ts @@ -0,0 +1,18 @@ +import axios from "@/lib/axios"; + +class ProductApiService { + async sync(items: ISyncItem[]) { + try { + const { data } = await axios.post("/products/sync", { + items, + }); + console.log("[NestJS] Response (bulk):", data); + return data; + } catch (err) { + console.error("[NestJS] Error (bulk):", err); + throw err; + } + } +} + +export const productApi = new ProductApiService(); diff --git a/auto-listing-facebook-marketplace/src/background.ts b/auto-listing-facebook-marketplace/src/background.ts index 202336e..3506886 100644 --- a/auto-listing-facebook-marketplace/src/background.ts +++ b/auto-listing-facebook-marketplace/src/background.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ import PQueue from "p-queue"; let ports: chrome.runtime.Port[] = []; @@ -10,22 +11,6 @@ chrome.runtime.onConnect.addListener((port) => { }); }); -(() => { - const evtSource = new EventSource( - `${import.meta.env.VITE_API_URL}/products/publist-stream` - ); - - evtSource.onmessage = (event) => { - const data = JSON.parse(event.data); - console.log("New event:", data); - queue.add(() => handlePublish(data, 30000)); - }; - - evtSource.onerror = (err) => { - console.error("EventSource failed:", err); - }; -})(); - // eslint-disable-next-line @typescript-eslint/no-explicit-any async function handlePublish(data: any, timeoutMs = 5 * 60 * 1000) { return new Promise((resolve) => { @@ -43,6 +28,7 @@ async function handlePublish(data: any, timeoutMs = 5 * 60 * 1000) { chrome.tabs.onRemoved.removeListener(onTabClosed); clearTimeout(timeoutId); resolve(); + ensureMarketplaceSellingTab(); }; const onConnectListener = (port: chrome.runtime.Port) => { @@ -71,9 +57,101 @@ async function handlePublish(data: any, timeoutMs = 5 * 60 * 1000) { }); } +const handleListenPublists = () => { + const evtSource = new EventSource( + `${import.meta.env.VITE_API_URL}/products/publist-stream` + ); + + evtSource.onmessage = (event) => { + const data = JSON.parse(event.data); + console.log("New event:", data); + queue.add(() => handlePublish(data, 30000)); + }; + + evtSource.onerror = (err) => { + console.error("EventSource failed:", err); + }; +}; + +const handleListenDeletes = () => { + const evtSource = new EventSource( + `${import.meta.env.VITE_API_URL}/products/delete-stream` + ); + + evtSource.onmessage = (event) => { + try { + const data = JSON.parse(event.data); + console.log("[SSE] New event:", data); + + queue.add(() => { + return new Promise((resolve) => { + const listener = (msg: any) => { + if (msg?.type === "delete-done") { + console.log("[QUEUE] Delete done signal received."); + chrome.runtime.onMessage.removeListener(listener); + resolve(); + } + }; + chrome.runtime.onMessage.addListener(listener); + + // Gửi tới tab có URL khớp + chrome.tabs.query( + { url: "https://www.facebook.com/marketplace/you/selling" }, + (tabs) => { + for (const tab of tabs) { + if (tab.id) { + chrome.tabs.sendMessage(tab.id, { + type: "DELETE_STREAM_DATA", + payload: data, + }); + } + } + } + ); + }); + }); + } catch (err) { + console.error("[SSE] Parse error:", err); + } + }; + + evtSource.onerror = (err) => { + console.error("[SSE] Connection failed:", err); + }; + + console.log("[SSE] Listening for delete-stream events..."); +}; + +function ensureMarketplaceSellingTab() { + const targetUrl = "https://www.facebook.com/marketplace/you/selling"; + + console.log({ targetUrl }); + chrome.tabs.query({}, (tabs) => { + const existingTab = tabs.find( + (tab) => tab.url && tab.url.startsWith(targetUrl) + ); + + if (existingTab) { + // Nếu đã có thì refresh lại + chrome.tabs.reload((existingTab as any).id); + } else { + // Nếu chưa có thì mở mới + chrome.tabs.create({ url: targetUrl }); + } + }); +} + +const init = async () => { + handleListenPublists(); + handleListenDeletes(); + ensureMarketplaceSellingTab(); +}; + chrome.runtime.onMessage.addListener((message, sender) => { if (message.type === "close-tab") { const tabId = sender.tab?.id; if (tabId) chrome.tabs.remove(tabId); } }); + +init(); diff --git a/auto-listing-facebook-marketplace/src/content.ts b/auto-listing-facebook-marketplace/src/content.ts index 12d0c18..3e5f15f 100644 --- a/auto-listing-facebook-marketplace/src/content.ts +++ b/auto-listing-facebook-marketplace/src/content.ts @@ -1,8 +1,9 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ // content.ts +import { productApi } from "./api/product-api.service"; import { delay } from "./features/app"; import axios from "./lib/axios"; import { thiefService } from "./services/thief.service"; - const selectors = { file__image_input: 'input[type="file"]', title_input: @@ -58,23 +59,10 @@ const selectors = { "/html/body/div[1]/div/div[1]/div/div[3]/div/div/div[1]/div[1]/div[1]/div/div[5]/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", }; -// const getData = async () => { -// return new Promise((rev, rej) => { -// const url = chrome.runtime.getURL("data.json"); - -// fetch(url) -// .then((res) => res.json()) -// .then((data) => { -// rev(data as IItem[]); -// }) -// .catch((err) => { -// rej(err); -// }); -// }); -// }; - const uploadImages = async (item: IItem) => { // Tạo DataTransfer để giả lập FileList const dt: DataTransfer = new DataTransfer(); @@ -214,6 +202,19 @@ const finistPublist = async ( return data; }; +const finistDelete = async ( + item: IItem, + values: { error?: string; published: boolean } +) => { + const { data } = await axios({ + url: "products/delete-finish/" + item.id, + method: "POST", + data: values, + }); + + return data; +}; + const clickNext = async () => { const btn = await thiefService.getElementByXPath(selectors.next_btn); @@ -230,6 +231,28 @@ const clickPublist = async () => { thiefService.clickByPoint(btn); }; +function extractListings(productsEl: HTMLElement) { + const children = Array.from(productsEl.children); + + return children.map((child) => { + // Lấy title (thường là span hoặc div có dir="auto") + const titleEl = child.querySelector('span[dir="auto"], div[dir="auto"]'); + const title = titleEl?.textContent?.trim() || ""; + + // Lấy giá (span có attribute dir="auto") + const priceEl = Array.from(child.querySelectorAll('span[dir="auto"]')).find( + (el) => + /\d/.test(el.textContent || "") && /[AU$]/.test(el.textContent || "") + ); + + // Tách lấy số, ví dụ: "AU$20" -> "20" + const priceMatch = priceEl?.textContent?.match(/\d+(?:\.\d+)?/); + const price = priceMatch ? parseFloat(priceMatch[0]) : 0; + + return { title, price, el: productsEl }; + }); +} + /** * B1. Upload images * B2. Write title @@ -308,6 +331,31 @@ const handle = async (item: IItem) => { return true; }; +const getProducts = async () => { + const products = await thiefService.getElementByXPath(selectors.products); + if (!products) return []; + + return extractListings(products) as ISyncItem[]; +}; + +const syncListing = async () => { + const url = window.location.href; + if (!url.includes("https://www.facebook.com/marketplace/you/selling")) return; + + const products = await getProducts(); + + if (!products.length) return; + + const response = await productApi.sync( + products.map((item) => ({ + title: item.title, + price: item.price, + })) as ISyncItem[] + ); + + console.log({ response }); +}; + const closeTab = async (data: IItem) => { chrome.runtime.sendMessage({ type: "close-tab", @@ -315,6 +363,64 @@ const closeTab = async (data: IItem) => { }); }; +const handleDelete = async (payload: IItem) => { + const products = await getProducts(); + + const product = products.find((product) => { + return product.title == payload.title && product.price == payload.price; + }); + + console.log({ payload, product, products }); + + if (!product) return; + + const el = product.el; + + const optionEl = el.querySelector( + `[aria-label="More options for ${product.title}"]` + ); + + console.log({ optionEl }); + if (!optionEl) return; + + (optionEl as any).click?.(); + + await delay(2000); + + const items = Array.from(document.querySelectorAll('[role="menuitem"]')); + + console.log({ items }); + const deleteItem = items.find((item) => + item.textContent.toLocaleLowerCase().includes("delete") + ); + + (deleteItem as any).click?.(); + + await delay(1000); + + const btnDelete = await thiefService.getElementByXPath( + "/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", + { + xpathFallback: + "/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]", + } + ); + + console.log({ btnDelete }); + + btnDelete?.click(); + + const closeModal = await thiefService.getElementByXPath( + "/html/body/div[1]/div/div[1]/div/div[4]/div/div/div[1]/div/div[2]/div/div/div/div[2]/div" + ); + + closeModal?.click(); + + await finistDelete(payload, { published: false }); + + chrome.runtime.sendMessage({ type: "delete-done" }); +}; + const port = chrome.runtime.connect(); port.onMessage.addListener(async (message) => { @@ -345,14 +451,25 @@ port.onMessage.addListener(async (message) => { } }); +// content.js +chrome.runtime.onMessage.addListener((message) => { + if (message.type === "DELETE_STREAM_DATA") { + console.log("Nhận dữ liệu từ background:", message.payload); + + handleDelete(message.payload); + } +}); + async function init() { - const { data } = await axios.get("products/27"); + // const { data } = await axios.get("products/33"); - if (!data.data) return; + // if (!data.data) return; - const item = data.data as IItem; + // const item = data.data as IItem; - await handle(item); + // await handle(item); + + await syncListing(); } init(); diff --git a/auto-listing-facebook-marketplace/src/features/app.ts b/auto-listing-facebook-marketplace/src/features/app.ts index 99965d7..3f75b45 100644 --- a/auto-listing-facebook-marketplace/src/features/app.ts +++ b/auto-listing-facebook-marketplace/src/features/app.ts @@ -15,3 +15,8 @@ export function removeFalsyValues>( export function delay(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } + +export function randomDelay(minMs: number, maxMs: number): Promise { + const time = Math.floor(Math.random() * (maxMs - minMs + 1)) + minMs; + return delay(time); +} diff --git a/auto-listing-facebook-marketplace/src/interfate.d.ts b/auto-listing-facebook-marketplace/src/interfate.d.ts index 1fdf9a3..cf0b88f 100644 --- a/auto-listing-facebook-marketplace/src/interfate.d.ts +++ b/auto-listing-facebook-marketplace/src/interfate.d.ts @@ -1,3 +1,4 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ interface IItem { images: string[]; title: string; @@ -11,3 +12,9 @@ interface IItem { location?: string; id: number; } + +interface ISyncItem { + title: string; + price: number; + el: HTMLElement; +} diff --git a/client/app/routes/products/components/modals/history-modal.tsx b/client/app/routes/products/components/modals/history-modal.tsx index 7fc9940..f94e172 100644 --- a/client/app/routes/products/components/modals/history-modal.tsx +++ b/client/app/routes/products/components/modals/history-modal.tsx @@ -80,6 +80,18 @@ export function HistoryModal({ data, open, setOpen }: HistoryModalProps) { )} + {item.message && ( +
+
+ +
+

Message:

+

{item.message}

+
+
+
+ )} +
diff --git a/client/app/routes/products/list.tsx b/client/app/routes/products/list.tsx index 5347a77..516ede3 100644 --- a/client/app/routes/products/list.tsx +++ b/client/app/routes/products/list.tsx @@ -150,12 +150,12 @@ export default function List() { }, { key: "histories", - label: "Published", + label: "Status", displayType: "custom", render(value, row) { return (
- {row.histories.some((item) => item.published) ? ( + {row.status ? ( @@ -267,6 +267,7 @@ export default function List() { }, onSuccess: (data) => { console.log({ data }); + refetch(); }, }); diff --git a/client/app/types/index.d.ts b/client/app/types/index.d.ts index f9d9e89..0c6bb6b 100644 --- a/client/app/types/index.d.ts +++ b/client/app/types/index.d.ts @@ -80,10 +80,12 @@ interface IProduct extends ITimestamp { location: string; id: number; histories: IHistory[]; + status: boolean; } interface IHistory extends ITimestamp { id: number; error?: string; published: boolean; + message?: string; } diff --git a/server/public/medias/products/gewgwegewewg/product-1755066754690.png b/server/public/medias/products/gewgwegewewg/product-1755066754690.png deleted file mode 100644 index a1e48aa..0000000 Binary files a/server/public/medias/products/gewgwegewewg/product-1755066754690.png and /dev/null differ diff --git a/server/public/medias/products/testessse/product-1755066484846.png b/server/public/medias/products/testessse/product-1755066484846.png deleted file mode 100644 index 6f25e90..0000000 Binary files a/server/public/medias/products/testessse/product-1755066484846.png and /dev/null differ diff --git a/server/public/medias/products/testssss/product-1755065436688.png b/server/public/medias/products/testssss/product-1755065436688.png deleted file mode 100644 index ac45bee..0000000 Binary files a/server/public/medias/products/testssss/product-1755065436688.png and /dev/null differ diff --git a/server/public/medias/products/testssss/product-1755065436701.png b/server/public/medias/products/testssss/product-1755065436701.png deleted file mode 100644 index b174a9b..0000000 Binary files a/server/public/medias/products/testssss/product-1755065436701.png and /dev/null differ diff --git a/server/src/entities/product.entity.ts b/server/src/entities/product.entity.ts index 380c6bd..174b9db 100644 --- a/server/src/entities/product.entity.ts +++ b/server/src/entities/product.entity.ts @@ -57,6 +57,9 @@ export class Product extends CoreEntity { @Column({ type: 'varchar', nullable: true }) location?: string; + @Column({ type: 'bool', default: false }) + status: boolean; + @OneToMany(() => PublistHistory, (publistHistory) => publistHistory.product) histories: PublistHistory[]; } diff --git a/server/src/entities/publist-history.entity.ts b/server/src/entities/publist-history.entity.ts index c16cc83..6ad0c03 100644 --- a/server/src/entities/publist-history.entity.ts +++ b/server/src/entities/publist-history.entity.ts @@ -7,6 +7,9 @@ export class PublistHistory extends CoreEntity { @Column({ type: 'varchar', nullable: true, default: null }) error: string; + @Column({ type: 'varchar', nullable: true, default: null }) + message: string; + @Column({ type: 'bool' }) published: boolean; diff --git a/server/src/modules/products/dtos/sync-item.dto.ts b/server/src/modules/products/dtos/sync-item.dto.ts new file mode 100644 index 0000000..b1d20c9 --- /dev/null +++ b/server/src/modules/products/dtos/sync-item.dto.ts @@ -0,0 +1,9 @@ +import { IsNumber, IsString } from 'class-validator'; + +export class SyncItemDto { + @IsString() + title: string; + + @IsNumber() + price: number; +} diff --git a/server/src/modules/products/dtos/syncs.dto.ts b/server/src/modules/products/dtos/syncs.dto.ts new file mode 100644 index 0000000..b94836e --- /dev/null +++ b/server/src/modules/products/dtos/syncs.dto.ts @@ -0,0 +1,10 @@ +import { IsArray, ValidateNested } from 'class-validator'; +import { Type } from 'class-transformer'; +import { SyncItemDto } from './sync-item.dto'; + +export class SyncDto { + @IsArray() + @ValidateNested({ each: true }) + @Type(() => SyncItemDto) + items: SyncItemDto[]; +} diff --git a/server/src/modules/products/products.controller.ts b/server/src/modules/products/products.controller.ts index 07b9d91..9537bfc 100644 --- a/server/src/modules/products/products.controller.ts +++ b/server/src/modules/products/products.controller.ts @@ -4,6 +4,7 @@ import { Body, Controller, Param, Post, Sse } from '@nestjs/common'; import { ProductsService } from './products.service'; import { CreateProductDto } from './dtos/create-product.dto'; import { PublistFinishDto } from './dtos/publist-finish.dto'; +import { SyncDto } from './dtos/syncs.dto'; @Controller('products') export class ProductsController extends CoreController< @@ -15,10 +16,15 @@ export class ProductsController extends CoreController< } @Post('') - async create(data: CreateProductDto): Promise { + async create(@Body() data: CreateProductDto): Promise { return this.service.create(data); } + @Post('sync') + async sync(@Body() data: SyncDto): Promise { + return this.service.sync(data); + } + @Post('publist/:id') async publist(@Param('id') id: Product['id']): Promise { return this.service.publist(id); @@ -31,9 +37,21 @@ export class ProductsController extends CoreController< ): Promise { return this.service.publistFinish(id, data); } + @Post('delete-finish/:id') + async deleteFinish( + @Param('id') id: Product['id'], + @Body() data: PublistFinishDto, + ): Promise { + return this.service.deleteFinish(id, data); + } @Sse('publist-stream') async publistStream() { - return this.service.sendEvents(); + return this.service.sendPublistEvents(); + } + + @Sse('delete-stream') + async deleteStream() { + return this.service.sendDeleteEvents(); } } diff --git a/server/src/modules/products/products.service.ts b/server/src/modules/products/products.service.ts index 3ea9dfa..b1cbf27 100644 --- a/server/src/modules/products/products.service.ts +++ b/server/src/modules/products/products.service.ts @@ -19,12 +19,15 @@ import { MediasService } from '../medias/medias.service'; import { CreateProductDto } from './dtos/create-product.dto'; import { PublistFinishDto } from './dtos/publist-finish.dto'; import { Request } from 'express'; +import { SyncDto } from './dtos/syncs.dto'; @Injectable() export class ProductsService extends CoreService { public static EVENTS = { SEND_PUBLIST: 'send-publist', + SEND_DELETE: 'send-delete', PUBLIST_FINISH: 'publist-finish', + DElETE_FINISH: 'delete-finish', }; constructor( @@ -60,7 +63,7 @@ export class ProductsService extends CoreService { data: Partial, req: Request, ): Promise { - // Xóa avatar nếu có + // Xóa images nếu có if (data.images?.length) { for (const image of data.images) { await this.mediasService.removeMediasFolder( @@ -71,6 +74,29 @@ export class ProductsService extends CoreService { } } + protected async beforeDelete( + id: number, + data: Partial, + req: Request, + ): Promise { + // Emit sự kiện để bắt đầu publish + this.eventService.sendEvent(ProductsService.EVENTS.SEND_DELETE, { + ...data, + }); + + // Đợi phản hồi từ client + const result = await this.waitForDeleteResult({ ...data, id }); + + if (!result) + throw new BadRequestException( + AppResponse.toResponse(false, { + message: SystemLang.getText('messages', 'try_again'), + }), + ); + + return true; + } + async create(data: CreateProductDto): Promise { const product = this.repo.create(data); @@ -187,6 +213,23 @@ export class ProductsService extends CoreService { } } + private async waitForDeleteResult( + data: Partial, + ): Promise { + try { + return await this.eventService.waitForEvent( + `${ProductsService.EVENTS.DElETE_FINISH}_${data.id}`, + 30000, + ); + } catch { + throw new BadRequestException( + AppResponse.toResponse(null, { + message: SystemLang.getText('messages', 'try_again'), + }), + ); + } + } + async publistFinish(id: Product['id'], data: PublistFinishDto) { const product = await this.repo.findOne({ where: { id } }); @@ -209,7 +252,29 @@ export class ProductsService extends CoreService { return AppResponse.toResponse(plainData); } - sendEvents(): Observable<{ data: any }> { + async deleteFinish(id: Product['id'], data: PublistFinishDto) { + const product = await this.repo.findOne({ where: { id } }); + + if (!product) + throw new NotFoundException( + AppResponse.toResponse(null, { + message: SystemLang.getText('messages', 'not_found'), + }), + ); + + const plainData = plainToClass(Product, product); + + const result = await this.historiesRepo.save({ ...data, product }); + + this.eventService.sendEvent( + `${ProductsService.EVENTS.DElETE_FINISH}_${plainData.id}`, + plainToClass(PublistHistory, result), + ); + + return AppResponse.toResponse(plainData); + } + + sendPublistEvents(): Observable<{ data: any }> { // Tạo Observable dựa trên sự kiện 'send publist' của eventEmitter return fromEvent( this.eventService.event, @@ -220,4 +285,89 @@ export class ProductsService extends CoreService { })), ); } + + sendDeleteEvents(): Observable<{ data: any }> { + // Tạo Observable dựa trên sự kiện 'send publist' của eventEmitter + return fromEvent( + this.eventService.event, + ProductsService.EVENTS.SEND_DELETE, + ).pipe( + map((data) => ({ + data, // gửi data về client + })), + ); + } + + async sync({ items }: SyncDto) { + const incomingTitles = new Set(items.map((d) => d.title)); + + // Lấy danh sách sản phẩm hiện tại trong DB + const products = await this.repo.find({ + select: ['id', 'title', 'status', 'price'], + }); + + const toDisable: Product[] = []; + const toEnable: { product: Product; price: number }[] = []; + const toInsert: { title: string; price: number }[] = []; + + const existingMap = new Map(products.map((p) => [p.title, p])); + + // Tìm sản phẩm cần disable + for (const product of products) { + if (!incomingTitles.has(product.title) && product.status) { + toDisable.push(product); + } + } + + // Tìm sản phẩm cần enable hoặc insert mới + for (const item of items) { + const existing = existingMap.get(item.title); + if (!existing) { + toInsert.push(item); + } else if (!existing.status || existing.price !== item.price) { + toEnable.push({ product: existing, price: item.price }); + } + } + + // Batch update disable + if (toDisable.length) { + await this.repo + .createQueryBuilder() + .update(Product) + .set({ status: false }) + .whereInIds(toDisable.map((p) => p.id)) + .execute(); + + await this.historiesRepo.save( + toDisable.map((product) => ({ + message: `Product was disabled at: ${new Date().toISOString()}`, + product, + published: false, + })), + ); + } + + // Update enable + update giá + log + for (const { product, price } of toEnable) { + await this.repo.update(product.id, { status: true, price }); + } + + // Insert sản phẩm mới + log + if (toInsert.length) { + const newProducts = this.repo.create( + toInsert.map((item) => ({ + title: item.title, + price: item.price, + status: true, + })), + ); + await this.repo.save(newProducts); + } + + return { + disabled: toDisable.length, + enabled: toEnable.length, + inserted: toInsert.length, + }; + } }