(()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>s});const n="v1";var o;!function(e){e.BACKGROUND="BACKGROUND",e.CONTENT_SCRIPT="CONTENT_SCRIPT",e.EXTENSION_PAGE="EXTENSION_PAGE",e.POPUP="POPUP",e.OPTIONS="OPTIONS",e.SIDEBAR="SIDEBAR",e.DEVELOPER_TOOLS="DEVELOPER_TOOLS",e.UNIDENTIFIED_CONTEXT="UNIDENTIFIED_CONTEXT"}(o||(o={}));var i=function(e,t,n,o){return new(n||(n=Promise))((function(i,s){function r(e){try{c(o.next(e))}catch(e){s(e)}}function a(e){try{c(o.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((o=o.apply(e,t||[])).next())}))};const s=new class{constructor(){this.version="1.12.2",this.apiOrigin="https://api.extensionboost.com",this.sessionId=null,this.windowIsDefined="undefined"!=typeof window,this.chromeGlobalIsDefined="undefined"!=typeof chrome,this.isManifestV2=null,this.usesExtensionProtocol=!!this.windowIsDefined&&"chrome-extension:"===window.location.protocol,this.extensionId=null,this.extensionName=null,this.chromeGlobalIsDefined&&(this.extensionId=chrome.runtime.id,this.extensionName=chrome.runtime.getManifest().name,this.isManifestV2="2"===chrome.runtime.getManifest().version),!1===this.isManifestV2&&!this.windowIsDefined&&this.chromeGlobalIsDefined||!0===this.isManifestV2&&this.windowIsDefined&&window===chrome.extension.getBackgroundPage()?this.engineContext=o.BACKGROUND:this.windowIsDefined&&this.chromeGlobalIsDefined&&this.usesExtensionProtocol?this.engineContext=o.EXTENSION_PAGE:this.windowIsDefined&&this.chromeGlobalIsDefined&&!this.usesExtensionProtocol?this.engineContext=o.CONTENT_SCRIPT:this.engineContext=o.UNIDENTIFIED_CONTEXT,this.engineInit()}engineInit(){switch(this.engineContext){case o.BACKGROUND:this.initBackground();case o.CONTENT_SCRIPT:case o.DEVELOPER_TOOLS:case o.EXTENSION_PAGE:case o.OPTIONS:case o.POPUP:}}renderSlotDataOrError({exboostSlotId:e,target:t,containerClass:n,linkClass:o},s={}){return i(this,void 0,void 0,(function*(){const i=yield this.loadSlotDataOrError({exboostSlotId:e});t.innerHTML=`
\n ${i.anchorData.map((e=>`${e.text}`)).join("")}\n
`}))}loadSlotDataOrError({exboostSlotId:e},t={}){return i(this,void 0,void 0,(function*(){if(!e)throw new Error("Must provide exboostSlotId");const n={exboostSlotId:e,engineContext:this.engineContext,options:t},o=yield chrome.runtime.sendMessage(n);if(!o.success)throw new Error("Failed to load ExBoost slot data");return o.exboostSlotData}))}initBackground(){this.sessionId=crypto.randomUUID(),chrome.runtime.onMessage.addListener(((e,t,o)=>{if(!Object.keys(e).includes("exboostSlotId"))return;const i=[n,"links"].join("/"),s=new URLSearchParams({sessionId:this.sessionId,engineContext:e.engineContext,slotId:e.exboostSlotId,version:this.version,publisherExtensionId:this.extensionId,publisherExtensionName:this.extensionName});return fetch(`${this.apiOrigin}/${i}?nonce=${Date.now()}&${s.toString()}`).then((e=>{if(200!==e.status){const e={success:!1,exboostSlotData:{anchorData:[]}};return Promise.resolve(e)}return e.json().then((e=>({success:!0,exboostSlotData:e})))})).then((e=>o(e))),!0}))}};module.exports=t})();