(function(){document.documentElement.dataset.bloomExt="true";const c=new Set(["bloom.activeWalletGroup","bloom.audioSettings","bloom.backgroundImage","bloom.backgroundGifUrl","bloom.backgroundOpacity","bloom.devSellSettings","bloom.includeFees","bloom.limitSettings","bloom.multiSelectGroups","bloom.pnlBackgroundImage","bloom.pnlBackgroundOpacity","bloom.presets","bloom.quickBuyButton","bloom.quickBuyAmount","bloom.reduceMotion","bloom.scraperSettings","bloom.sitePreferences","bloom.wallets","bloom.walletGroups","bloom.walletSettings","bloom.user_id"]),b=new Set(["bloom.user_id"]);function m(o){return c.has(o)}function g(o){return c.has(o)&&!b.has(o)}async function d(){const{"bloom.token":o,"bloom.expires_at":r}=await chrome.storage.local.get(["bloom.token","bloom.expires_at"]);return typeof o=="string"&&o.length>0&&typeof r=="number"&&r>Date.now()}document.addEventListener("bloom:request",async o=>{const r=o,{id:e,type:n,payload:a}=r.detail,s=t=>{document.dispatchEvent(new CustomEvent("bloom:response",{detail:t}))};try{switch(n){case"get":case"getAll":{const t=a.keys.filter(m);if(t.length===0){s({id:e,data:{}});break}const l=await chrome.storage.local.get(t);s({id:e,data:l});break}case"set":case"setMultiple":{const t=a.items,l={};for(const[i,u]of Object.entries(t))g(i)&&(l[i]=u);if(Object.keys(l).length===0){s({id:e,error:"No writable keys provided"});break}await chrome.storage.local.set(l),s({id:e,data:{success:!0}});break}case"refreshWallets":{const t=await chrome.runtime.sendMessage({message:"refreshWallets"});s({id:e,data:t});break}case"isLoggedIn":{const t=await d();s({id:e,data:{loggedIn:t}});break}default:s({id:e,error:`Unknown request type: ${n}`})}}catch(t){s({id:e,error:t instanceof Error?t.message:"Unknown error"})}});document.addEventListener("bloom:auth-write",o=>{const e=o.detail;if(!e||typeof e.token!="string"||typeof e.expiresAt!="number"||typeof e.userId!="string")return;const n={"bloom.token":e.token,"bloom.expires_at":e.expiresAt,"bloom.user_id":e.userId};typeof e.referralCode=="string"&&(n["bloom.referral_code"]=e.referralCode),chrome.storage.local.set(n)});chrome.storage.onChanged.addListener((o,r)=>{if(r!=="local")return;const e={};for(const[n,a]of Object.entries(o))m(n)&&(e[n]={newValue:a.newValue,oldValue:a.oldValue});Object.keys(e).length>0&&document.dispatchEvent(new CustomEvent("bloom:storage-changed",{detail:{changes:e}})),("bloom.token"in o||"bloom.expires_at"in o)&&d().then(n=>{document.dispatchEvent(new CustomEvent("bloom:login-changed",{detail:{loggedIn:n}}))})});
})()
