!function(){let t;(()=>{const e="app",n="production",s=!1;if(t=globalThis.app,t)return;const i={name:e,env:n,get:t=>t in i?i[t]:null,...JSON.parse('{"version":"28.0.6","manifestVersion":3}')},r=function t(e){const n=e===i,r=n&&s,l={},c=t=>Object.assign(e,t);return new Proxy(e,{get:function(s,i){if("assign"===i)return c;if(n&&!String(i).startsWith("$"))return e[i];if(!(i in e)){if(e[i]={},n){const t=a.bind(null,"log",i,!1),n=a.bind(null,"log",i,!0),s=a.bind(null,"warn",i,!1),r=a.bind(null,"warn",i,!0),l=a.bind(null,"error",i,!1),c=a.bind(null,"error",i,!0),u=o.bind(null,i);Object.defineProperties(e[i],{log:{get:()=>t},logDev:{get:()=>n},warn:{get:()=>s},warnDev:{get:()=>r},error:{get:()=>l},errorDev:{get:()=>c},Error:{get:()=>u}})}l[i]=t(e[i]),r&&(globalThis[i]=e[i])}return i in l?l[i]:e[i]},set:function(t,n,s){return e[n]=s,l[n]=s,r&&(globalThis[n]=e[n]),!0}})}(i);function a(t,e,n,...s){if(n)return;const[i,r,a]=l(e);console[t](`%c[${e}]`,`color: rgb(${i}, ${r}, ${a})`,...s)}function o(t,e,...n){return n.length>0&&a("error",t,!1,e,...n),new Error(`[${t}] ${e}`)}function l(t){let e=0;t.split("").forEach(((n,s)=>{e=t.charCodeAt(s)+((e<<5)-e)}));const n=(16711680&e)>>16,s=(65280&e)>>8,i=255&e;return n+s+i<300?l(`$${t}`):[n,s,i]}globalThis.app=r,t=r})();const{$utils:e}=app;e.callAsync=async(t,...e)=>new Promise((n=>{t(...e,n)}));const{$utils:n}=app;n.canvasToBlob=async(t,{type:e="image/jpeg",quality:n=.8}={})=>await new Promise(((s,i)=>{t.toBlob((t=>{t?s(t):i("canvas.toBlob failed")}),e,n)}));const{$utils:s,$bus:i}=app;s.extractFrame=async(t,e=0)=>{if("undefined"==typeof document)return await i.send("utils.extractFrame",t,e);const n=await s.objectUrl.create(t),r=document.createElement("video");r.src=n,r.muted=!0,await new Promise((t=>r.addEventListener("loadedmetadata",t))),r.currentTime=e*r.duration,await new Promise((t=>r.addEventListener("timeupdate",t)));const a=document.createElement("canvas"),o=a.getContext("2d");a.width=r.videoWidth,a.height=r.videoHeight,o.drawImage(r,0,0);return await new Promise((t=>a.toBlob(t,"image/jpeg")))};const{$utils:r}=app;r.is={null:t=>null===t,defined:t=>void 0!==t,undefined:t=>void 0===t,nil:t=>null==t,boolean:t=>"boolean"==typeof t,number:t=>"number"==typeof t,string:t=>"string"==typeof t,symbol:t=>"symbol"==typeof t,function:t=>"function"==typeof t,map:t=>t instanceof Map,set:t=>t instanceof Set,url:t=>t instanceof URL,blob:t=>t instanceof Blob,file:t=>t instanceof File,error:t=>t instanceof Error,regexp:t=>t instanceof RegExp,array:t=>Array.isArray(t),object:t=>"[object Object]"===Object.prototype.toString.call(t),nan:t=>Number.isNaN(t),nonPrimitive:t=>r.is.object(t)||r.is.array(t),numeric:t=>!r.is.nan(Number(t)),empty:t=>!!r.is.nil(t)||(r.is.array(t)?0===t.length:r.is.object(t)?0===Object.keys(t).length:!!r.is.string(t)&&0===t.trim().length)};const{$utils:a,$bus:o}=app;a.loadImage=async t=>{if("undefined"==typeof document)return await o.send("utils.loadImage",t);const e=await a.objectUrl.create(t),n=document.createElement("img");return await new Promise(((t,s)=>{n.onload=t,n.onerror=s,n.src=e})),{img:n,width:n.width,height:n.height,ratio:n.width/n.height}};const{$utils:l,$bus:c}=app;l.loadVideoMetadata=async t=>{if("undefined"==typeof document)return await c.send("utils.loadVideoMetadata",t);const e="string"==typeof t?t:await l.objectUrl.create(t),n=document.createElement("video");n.src=e,n.muted=!0,n.volume=0,n.preload="metadata",n.play();const s={};return await new Promise(((t,e)=>{n.addEventListener("loadedmetadata",(async()=>{await l.waitFor((()=>n.webkitAudioDecodedByteCount),100),s.width=n.videoWidth,s.height=n.videoHeight,s.ratio=n.videoWidth/n.videoHeight,s.duration=n.duration,s.hasAudio=n.webkitAudioDecodedByteCount>0,t()})),n.addEventListener("error",(()=>{e(n.error)}))})),n.remove(),s};const{$utils:u,$bus:d}=app;u.ls={get:function(t,e){if(!this._supported())return d.send("utils.ls.get",t,e);const n=localStorage.getItem(t);if(null==n)return e;if("true"===n)return!0;if("false"===n)return!1;if(n.startsWith("[")||n.startsWith("{"))return JSON.parse(n);const s=Number(n);return Number.isNaN(s)?n:s},set:function(t,e){if(!this._supported())return d.send("utils.ls.set",t,e);try{"string"==typeof e?localStorage.setItem(t,e):localStorage.setItem(t,JSON.stringify(e))}catch(n){u.error("ls.set failed",{key:t,value:e,details:n})}},has:function(t){return this._supported()?t in localStorage:d.send("utils.ls.has",t)},remove:function(t){if(!this._supported())return d.send("utils.ls.remove",t);localStorage.removeItem(t)},_supported:function(){return!!globalThis.localStorage}};const{$utils:h,$bus:m}=app;h.objectUrl={create:function(t,e=!1){if(!URL.createObjectURL)return m.send("utils.objectUrl.create",t,e);const n=URL.createObjectURL(t);if(e){const t=h.is.number(e)?e:6e4;setTimeout((()=>URL.revokeObjectURL(n)),t)}return n},revoke:function(t){if(!URL.revokeObjectURL)return m.send("utils.objectUrl.revoke",t);URL.revokeObjectURL(t)}};const{$utils:f,$bus:g}=app;f.scaler={scaleToFitSize:async function(t,e,n,{type:s="image/jpeg",quality:i=.8}={}){if("undefined"==typeof document)return await g.send("utils.scaler.scaleToFitRatio",...arguments);const{img:r,width:a,height:o}=await f.loadImage(t),l=e/a,c=n/o,u=Math.min(l,c),d=document.createElement("canvas");d.width=a*u,d.height=o*u;const h=d.getContext("2d");return h.drawImage(r,0,0,a,o,0,0,d.width,d.height),await f.canvasToBlob(d,{type:s,quality:i})},scaleToFitRatio:async function(t,e,{type:n="image/jpeg",quality:s=.8}={}){if("undefined"==typeof document)return await g.send("utils.scaler.scaleToFitRatio",...arguments);const{img:i,width:r,height:a,ratio:o}=await f.loadImage(t),l=document.createElement("canvas");o>e?(l.width=r,l.height=r/e):(l.height=a,l.width=a*e);const c=l.getContext("2d"),u=(l.width-r)/2,d=(l.height-a)/2;return c.drawImage(i,u,d,r,a),await f.canvasToBlob(l,{type:n,quality:s})}};const{$utils:b}=app,p=36e5,_=864e5;b.time={SECOND:1e3,MINUTE:6e4,HOUR:p,DAY:_,WEEK:6048e5,MONTH:26784e5,weekdays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"]};const{$utils:w}=app;w.waitFor=async(t,e=null)=>{let n,s;return"number"==typeof e?(n=e,s=100):e?(n=e.timeout||3e4,s=e.frequency||100):(n=3e4,s=100),new Promise(((e,i)=>{const r=t();if(r)return void e(r);const a=setInterval((()=>{const n=t();n&&(clearInterval(a),e(n))}),s);setTimeout((()=>{clearInterval(a),e(null)}),n)}))};const{$env:y}=app;y.getLocus=()=>"chrome-extension:"!==location.protocol&&chrome.runtime?"cs":"chrome-extension:"!==location.protocol?"nj":"/inssist.html"===location.pathname?"pp":"/offscreen.html"===location.pathname?"os":"bg";const{$bus:v,$env:I,$utils:T}=app;{var $;const t=null===($=app.get("$bus").controller)||void 0===$?void 0:$._njOnMsg;t&&window.removeEventListener("message",t)}v.controller={init:function(){v.on=this.on.bind(this),v.off=this.off.bind(this),v.once=this.once.bind(this),v.send=this._wrapThrowIfError(this.send),v.call=this._wrapThrowIfError(this.call),v.poll=this.poll.bind(this),v.getTabId=this.getTabId.bind(this),v.getWindowId=this.getWindowId.bind(this),this._locus=I.getLocus(),this._serialize=this._serialize.bind(this),this._handlers={},this._is("pp")?this._setupPp():this._is("bg")?(this._blobs={},this._channel=new BroadcastChannel("bus.channel"),this._setupBg()):this._is("cs")?this._setupCs():this._is("nj")?this._setupNj():this._is("os")?(v.setIframe=t=>this._iframe=t,this._iframe=null,this._channel=new BroadcastChannel("bus.channel"),this._setupOs()):this._is("oi")&&this._setupOi()},on:function(t,e,n=null){this._on(t,null,e,n)},off:function(t,e=null){this._off(t,null,e)},once:function(t,e){const n=async(...s)=>(this.off(t,n),await e(...s));this.on(t,n)},send:async function(t,...e){if(!T.is.nan(Number(t))){const n=Number(t);return t=e[0],e=e.slice(1),await this._sendToTab(n,t,...e)}if(this._is("pp"))return await this._sendToExt(t,...e);if(this._is("nj"))return await this._sendToPage(t,...e);if(this._is("oi"))return await this._sendToParent(t,...e);if(this._is("bg","cs","os"))return await this._pick([this._sendToExt(t,...e),this._callHandlers({name:t,args:e},(t=>t.proxy))]);if(this._is("fg")){if("store.actions"===t)return;if("idb.change"===t)return;v.log(t,...e)}},call:async function(t,...e){return this._callHandlers({name:t,args:e},(t=>!t.proxy))},poll:async function(t,...e){return await T.waitFor((()=>this.send(t,...e)))},getTabId:async function(){if(this._is("bg"))return null;const{tabId:t}=await this.send("bus.getTabData");return t},getWindowId:async function(){if(this._is("bg"))return null;const{windowId:t}=await this.send("bus.getTabData");return t},_on:function(t,e,n,s=null){this._handlers[t]||(this._handlers[t]=[]),this._is("cs","nj","oi")&&0===this._handlers[t].length&&this._sendToProxier("bus.proxy",t,!0);const i={fn:n,name:t};e&&(i.proxy=e),s&&(i.this=s),this._handlers[t].push(i)},_off:function(t,e=null,n=null){this._handlers[t]&&(this._handlers[t]=this._handlers[t].filter((t=>{const s=!n||n===t.fn,i=e===(t.proxy||null);return!s||!i})),this._is("cs","nj","oi")&&0===this._handlers[t].length&&this._sendToProxier("bus.proxy",t,!1))},_setupPp:function(){chrome.runtime.onMessage.addListener(((t,e,n)=>{if(!(null==t?void 0:t.$bus))return;const s=this._callHandlers(t);return s?(s.then(this._serialize).then(n),!0):void 0}))},_setupBg:function(){chrome.runtime.onMessage.addListener(((t,e,n)=>{var s;if(!(null==t?void 0:t.$bus))return;const i=(null===(s=e.tab)||void 0===s?void 0:s.id)||null;if("bus.proxy"===t.name)return void(async()=>{const[e,n]=await this._deserialize(t.argsStr);i&&(n?this._on(e,i,((...t)=>this._sendToTab(i,e,...t))):this._off(e,i))})();if("bus.getTabData"===t.name){var r;const t=(null===(r=e.tab)||void 0===r?void 0:r.windowId)||null;return n(this._serialize({tabId:i,windowId:t})),!0}if("bus.sendToTab"===t.name)return(async()=>{const e=await this._deserialize(t.argsStr),s=await this._sendToTab(...e);n(this._serialize(s))})(),!0;if("bus.blobIdToObjectUrl"===t.name)return(async()=>{const[e]=await this._deserialize(t.argsStr),s=await this._blobIdToObjectUrl(e);n(this._serialize(s))})(),!0;const a=this._callHandlers(t,(t=>t.proxy!==i));return a?(a.then(this._serialize).then(n),!0):void 0})),chrome.tabs.onRemoved.addListener((t=>{for(const e in this._handlers)this._handlers[e]=this._handlers[e].filter((e=>e.proxy!==t))}))},_setupCs:function(){chrome.runtime.onMessage.addListener(((t,e,n)=>{if(!t.$bus)return;const s=this._callHandlers(t);return s?(s.then(this._serialize).then(n),!0):void 0})),window.addEventListener("message",(async({data:t})=>{if(!(null==t?void 0:t.$bus))return;if("nj"!==t.locus)return;if("bus.proxy"===t.name){const[e,n]=t.args;return void(n?this._on(e,"nj",((...t)=>this._sendToPage(e,...t))):this._off(e,"nj"))}const e=await this._pick([this._sendToExt(t.name,...t.args),this._callHandlers(t,(t=>!t.proxy))]);window.postMessage({resId:t.reqId,result:e},"*")}))},_setupNj:function(){this._njOnMsg=async({data:t})=>{if(!(null==t?void 0:t.$bus))return;if("cs"!==t.locus)return;const e=await this._callHandlers(t);window.postMessage({resId:t.reqId,result:e},"*")},window.addEventListener("message",this._njOnMsg)},_setupOs:function(){chrome.runtime.onMessage.addListener(((t,e,n)=>{if(!(null==t?void 0:t.$bus))return;const s=this._callHandlers(t);return s?(s.then(this._serialize).then(n),!0):void 0})),window.addEventListener("message",(async({data:t})=>{if(!(null==t?void 0:t.$bus))return;if("bus.proxy"===t.name){const[e,n]=t.args;return void(n?this._on(e,"oi",((...t)=>this._sendToIframe(e,...t))):this._off(e,"oi"))}const e=await this._pick([this._sendToExt(t.name,...t.args),this._callHandlers(t,(t=>!t.proxy))]);this._iframe.contentWindow.postMessage({resId:t.reqId,result:e},"*")})),this._channel.addEventListener("message",(({data:t})=>{const{blob:e,reqId:n}=t,s=T.objectUrl.create(e,!0);this._channel.postMessage({resId:n,objectUrl:s})}))},_setupOi:function(){window.addEventListener("message",(async({data:t})=>{if(!(null==t?void 0:t.$bus))return;const e=await this._callHandlers(t);window.parent.postMessage({resId:t.reqId,result:e},"*")}))},_sendToExt:async function(t,...e){const n={$bus:!0,name:t,argsStr:this._serialize(e)},s=await new Promise((t=>{try{chrome.runtime.sendMessage(n,(e=>{chrome.runtime.lastError?t(null):t(e)}))}catch(e){if("Extension context invalidated."===e.message)return;v.error(e),t(null)}}));return await this._deserialize(s)},_sendToTab:async function(t,e,...n){var s;if(!(null===(s=chrome.tabs)||void 0===s?void 0:s.sendMessage))return await this.send("bus.sendToTab",t,e,...n);const i={$bus:!0,name:e,argsStr:this._serialize(n)},r=await new Promise((e=>{chrome.tabs.sendMessage(t,i,(t=>{chrome.runtime.lastError?e(null):e(t)}))}));return await this._deserialize(r)},_sendToPage:async function(t,...e){const n=this._generateId(),s={$bus:!0,name:t,args:e,reqId:n,locus:this._locus};return window.postMessage(s,"*"),await this._waitForResponseMessage(n)},_sendToIframe:async function(t,...e){if(!this._iframe)return null;const n=this._generateId(),s={$bus:!0,name:t,args:e,reqId:n};return this._iframe.contentWindow.postMessage(s,"*"),await this._waitForResponseMessage(n)},_sendToParent:async function(t,...e){const n=this._generateId(),s={$bus:!0,name:t,args:e,reqId:n};return parent.postMessage(s,"*"),await this._waitForResponseMessage(n)},_sendToProxier:async function(t,...e){return this._is("cs")?await this._sendToExt(t,...e):this._is("nj")?await this._sendToPage(t,...e):this._is("oi")?await this._sendToParent(t,...e):void 0},_waitForResponseMessage:async function(t){return await new Promise((e=>{const n=({data:s})=>{!(!s||s.resId!==t)&&(window.removeEventListener("message",n),e(s.result))};window.addEventListener("message",n)}))},_callHandlers:function({name:t,args:e,argsStr:n},s=null){let i=this._handlers[t];return i?(s&&(i=i.filter(s)),0===i.length?null:new Promise((async t=>{n&&(e=await this._deserialize(n));t(await this._pick(i.map((async t=>{try{return await t.fn.call(t.this,...e)}catch(e){return v.error(`failed to handle "${t.name}".`,e),e}}))))}))):null},_serialize:function(t){return T.is.nil(t)?null:JSON.stringify(t,((t,e)=>{if(T.is.blob(e)){if(this._is("bg")){const t=this._generateId();return this._blobs[t]=e,`bus.blob.${t}`}return`bus.blob.${T.objectUrl.create(e,!0)}`}return T.is.error(e)?`bus.error.${e.message}`:e}))},_deserialize:async function(t){if(!T.is.string(t))return null;const e=new Map,n=JSON.parse(t,((t,n)=>{const s=T.is.string(n);return s&&n.startsWith("bus.blob.")?(e.set(n,n.slice("bus.blob.".length)),n):s&&n.startsWith("bus.error.")?new Error(n.slice("bus.error.".length)):n}));return await Promise.all([...e.keys()].map((async t=>{let n;const s=e.get(t);n=s.startsWith("blob:")?s:await this._sendToExt("bus.blobIdToObjectUrl",s);const i=await fetch(n).then((t=>t.blob()));e.set(t,i)}))),this._applyBlobs(n,e)},_applyBlobs:function(t,e){if(e.has(t))return e.get(t);if(T.is.array(t)||T.is.object(t))for(const n in t)t[n]=this._applyBlobs(t[n],e);return t},_blobIdToObjectUrl:async function(t){const e=this._blobs[t];let n;return T.is.string(e)?n=e:(n=await this._blobToObjectUrl(e),this._blobs[t]=n),setTimeout((()=>delete this._blobs[t]),6e4),n},_blobToObjectUrl:async function(t){const e=this._generateId();return this._channel.postMessage({reqId:e,blob:t}),await new Promise((t=>{const n=({data:s})=>{!(!s||s.resId!==e)&&(this._channel.removeEventListener("message",n),t(s.objectUrl))};this._channel.addEventListener("message",n)}))},_is:function(...t){return t.includes(this._locus)},_generateId:function(){return`bus-${Date.now()}-${Math.random().toString(36).slice(2)}`},_wrapThrowIfError:function(t){return async(...e)=>{const n=await t.call(this,...e);if(T.is.error(n))throw n;return n}},_pick:async function(t=[]){return 0===t.length?null:await new Promise((e=>{let n=0;t.forEach((async s=>{const i=await s;return T.is.nil(i)?n===t.length-1?e(null):void n++:e(i)}))}))}};const{$offscreen:j}=app;j.controller={init:function(){j.utilsController.init()}};const{$offscreen:E,$utils:M,$bus:x}=app;E.utilsController={init:function(){const t=M.ls;x.on("utils.ls.get",t.get,t),x.on("utils.ls.set",t.set,t),x.on("utils.ls.has",t.has,t),x.on("utils.ls.remove",t.remove,t);const e=M.objectUrl;x.on("utils.objectUrl.create",e.create,e),x.on("utils.objectUrl.revoke",e.revoke,e);const n=M.scaler;x.on("utils.scaler.scaleToFitRatio",n.scaleToFitRatio,n),x.on("utils.scaler.scaleToFitRatio",n.scaleToFitRatio,n),x.on("utils.extractFrame",M.extractFrame),x.on("utils.loadImage",M.loadImage),x.on("utils.loadVideoMetadata",M.loadVideoMetadata)}};const{$igApi:O,$utils:P,$bus:k}=app;O.controller={init:function(){k.on("igApi.toJpeg",this._toJpeg,this)},_toJpeg:async function(t){const e=document.createElement("img");e.src=await P.objectUrl.create(t),await new Promise((t=>e.addEventListener("load",t)));const n=document.createElement("canvas");n.width=e.width,n.height=e.height;n.getContext("2d").drawImage(e,0,0);return await new Promise((t=>n.toBlob(t,"image/jpeg",.8)))}};const{$timer:L,$bus:U,$utils:S}=app;L.aliveController={init:function(){this._keepBgAlive()},_keepBgAlive:function(){setInterval((()=>U.send("timer.ping")),20*S.time.SECOND)}};const{$timer:R}=app;R.controller={init:function(){R.aliveController.init(),R.timingController.init(),R.workerController.init()}};const{$timer:C,$bus:F}=app;C.timingController={init:function(){this._timerIds=new Set,this._intervals={},F.on("timer.setTimeout",this._setTimeout,this),F.on("timer.clearTimeout",this._clearTimeout,this),F.on("timer.setInterval",this._setInterval,this),F.on("timer.clearInterval",this._clearInterval,this)},hasTimers:function(){return this._timerIds.size>0},_setTimeout:async function(t,e){this._timerIds.add(t),await new Promise((n=>{setTimeout((()=>{this._timerIds.delete(t),n()}),e)}))},_clearTimeout:function(t){this._timerIds.delete(t)},_setInterval:function(t,e){this._timerIds.add(t),this._intervals[t]=setInterval((()=>{F.send(`timer.setIntervalCall:${t}`)}),e)},_clearInterval:function(t){this._timerIds.delete(t),clearInterval(this._intervals[t]),delete this._intervals[t]}};const{$timer:N}=app;N.workerController={init:function(){this._MAX_ID=2147483647,this._lastId=0,this._idToCallback={},this._setupWorker("/js/timer-worker.min.js")},_generateId:function(){do{this._lastId===this._MAX_ID?this._lastId=0:this._lastId++}while(this._idToCallback.hasOwnProperty(this._lastId));return this._lastId},_setupWorker:function(t){const e=this._idToCallback;try{const n=new Worker(t);window.setInterval=(t,s)=>{const i=this._generateId();return e[i]={callback:t,parameters:Array.prototype.slice.call(arguments,2)},n.postMessage({name:"setInterval",id:i,time:s}),i},window.clearInterval=t=>{e.hasOwnProperty(t)&&(delete e[t],n.postMessage({name:"clearInterval",id:t}))},window.setTimeout=(t,s)=>{const i=this._generateId();return e[i]={callback:t,parameters:Array.prototype.slice.call(arguments,2),isTimeout:!0},n.postMessage({name:"setTimeout",id:i,time:s}),i},window.clearTimeout=t=>{e.hasOwnProperty(t)&&(delete e[t],n.postMessage({name:"clearTimeout",id:t}))},n.onmessage=t=>{const n=t.data.id;if(!n||!e.hasOwnProperty(n))return;const s=e[n],i=s.parameters;let r=s.callback;if(s.isTimeout&&delete e[n],"string"==typeof r)try{r=new Function(r)}catch(t){N.error("error parsing callback code string",t)}"function"==typeof r&&r.apply(window,i)},n.onerror=t=>{N.error("worker posted an error event",t)}}catch(t){N.error("failed setting up timer worker",t)}}};const{$startup:z,$bus:A,$offscreen:B,$igApi:W,$timer:D}=app;z.controller={init:async function(){await A.controller.init(),await D.controller.init(),await B.controller.init(),await W.controller.init(),A.on("startup.osReady",(()=>!0)),z.logDev("os ready")}},z.controller.init()}();