import{a3 as d,ag as f}from"./common-vYHpopNV.js";import"./_commonjsHelpers-BosuxZz1.js";let i;const l=async()=>{i=await chrome.tabs.create({url:"https://fansly.com",active:!1});const a=(await chrome.scripting.executeScript({target:{tabId:i.id},func:()=>{const e=JSON.parse(localStorage.getItem("session_active_session")||"null");return e&&(e.deviceId=localStorage.getItem("device_device_id")||""),e}}))[0].result;return a?(await chrome.storage.local.set({session:a}),i.id&&chrome.tabs.remove(i.id),!0):(await chrome.windows.update(i.windowId,{focused:!0}),await chrome.tabs.update(i.id,{active:!0}),!1)},s=async()=>{await l(),(await h("/")).id};chrome.runtime.onInstalled.addListener(t=>{t.reason==chrome.runtime.OnInstalledReason.INSTALL&&s()});chrome.action.onClicked.addListener(async()=>{s()});chrome.runtime.onMessage.addListener((t,a,e)=>(t.method=="RECHECK"&&l().then(e),t=="GET_TOKEN"&&chrome.storage.local.get("token").then(({token:o})=>e(o)),t.method=="getAccountInfo"&&d().then(o=>{e(o)}),t.method=="updateQuota"&&d().then(o=>{if(!o.value)return e(!1);f(o.value.email,o.value.token,t.payload||1).then(n=>{e(n)})}),t.method=="navigateTo"&&h(t.payload),t.method=="waitingSubscribe"&&m(t.payload).then(e),t.method=="Download"&&chrome.downloads.download({url:t.url,filename:t.filename,conflictAction:"overwrite",saveAs:!1}),t.method=="showModalOnFansly"&&chrome.tabs.query({active:!0,currentWindow:!0},o=>{var n;for(const c of o)if((n=c.url)!=null&&n.includes("fansly.com")){const{title:r,content:u,hasBackDrop:w}=t.payload;chrome.tabs.sendMessage(c.id,{method:"xdModal",payload:{title:r,content:u,hasBackDrop:w}})}}),!0));async function m(t){const a=await chrome.windows.create({url:t,type:"normal",focused:!0,state:"fullscreen"});return new Promise(e=>{const o=n=>{n==a.id&&(chrome.windows.onRemoved.removeListener(o),e())};chrome.windows.onRemoved.addListener(o)})}async function h(t){const a=chrome.runtime.getURL(`index.html#${t}`);return await y(a)}async function y(t,a={width:1440,height:800}){const e=await chrome.system.display.getInfo(),o=a.width,n=a.height,c=a.left||Math.ceil((e[0].bounds.width-o)/2),r=a.top||Math.ceil((e[0].bounds.height-n)/2);return await chrome.windows.create({url:t,type:"panel",focused:!0,width:o,height:n,left:c,top:r})}
