@vbrazo/widget
Version:
A standalone JavaScript widget for integrating Upriser ElevenLabs ConvAI into any website
1 lines • 24 kB
JavaScript
class UpriserWidget{constructor(e={}){this.config={agentId:"agent_8401k5nnvgqpezf9fd17t3tb7t69",widgetContainer:e.widgetContainer||null,debug:e.debug||!1,fontColor:e.fontColor||"#ffffff",linkColor:e.linkColor||"#ffffff",...e},this.isInitialized=!1,this.eventHandlers=new Map,this.mutationObserver=null,this.timeouts=new Map,this.intervals=new Map,this.isRelabelingComplete=!1}async init(){if(this.isInitialized)this.log("Widget already initialized");else try{await this.loadElevenLabsScript(),this.defineUpriserConvAIElement(),"undefined"!=typeof customElements&&customElements.get("upriser-convai")?this.createUpriserConvAIElement():this.createConvAIElement(),this.startRelabelFlow(),this.startAutoAcceptFlow(),this.isInitialized=!0,this.log("Widget initialized successfully")}catch(e){throw console.error("Failed to initialize Upriser Widget:",e),e}}loadElevenLabsScript(){if("undefined"!=typeof window&&window.__UPRISER_ELEVENLABS_SCRIPT_PROMISE)return window.__UPRISER_ELEVENLABS_SCRIPT_PROMISE;if("undefined"!=typeof customElements&&customElements.get("elevenlabs-convai"))return Promise.resolve();const e=document.querySelector('script[data-upriser-agent="true"], script[src*="@elevenlabs/convai-widget-embed"]'),t=new Promise(((t,i)=>{if(e){if(this.log("ElevenLabs script tag already present"),"undefined"!=typeof customElements&&customElements.get("elevenlabs-convai"))return void t();e.addEventListener&&e.addEventListener("load",(()=>t()));const i=setInterval((()=>{"undefined"!=typeof customElements&&customElements.get("elevenlabs-convai")&&(clearInterval(i),t())}),50);return void setTimeout((()=>{clearInterval(i),t()}),5e3)}const r=document.createElement("script");r.src="https://unpkg.com/@elevenlabs/convai-widget-embed@0.2.0/dist/index.js",r.async=!0,r.setAttribute("data-upriser-agent","true"),r.onload=()=>{this.log("ElevenLabs script loaded successfully"),t()},r.onerror=()=>{i(new Error("Failed to load ElevenLabs script"))},document.head.appendChild(r)}));return"undefined"!=typeof window&&(window.__UPRISER_ELEVENLABS_SCRIPT_PROMISE=t),t}createConvAIElement(){const e=this.config.widgetContainer||document.body,t=e.querySelector("elevenlabs-convai");t&&t.remove();const i=document.createElement("elevenlabs-convai");i.setAttribute("agent-id",this.config.agentId),e.appendChild(i),this.log("ConvAI element created with agent ID:",this.config.agentId)}createUpriserConvAIElement(){const e=this.config.widgetContainer||document.body,t=e.querySelector("upriser-convai");t&&t.remove();const i=document.createElement("upriser-convai");i.setAttribute("agent-id",this.config.agentId),i.setAttribute("font-color",this.config.fontColor),i.setAttribute("link-color",this.config.linkColor),e.appendChild(i),this.log("Upriser ConvAI element created with agent ID:",this.config.agentId)}defineUpriserConvAIElement(){if("undefined"==typeof customElements)return void this.log("Custom elements not supported");if(customElements.get("upriser-convai"))return void this.log("upriser-convai element already defined");const e=this;class t extends HTMLElement{constructor(){super(),this.elevenLabsElement=null,this.initialized=!1}connectedCallback(){this.initialized||this.init()}disconnectedCallback(){this.elevenLabsElement&&this.elevenLabsElement.remove()}static get observedAttributes(){return["agent-id","font-color","link-color"]}attributeChangedCallback(t,i,r){this.elevenLabsElement&&i!==r&&("agent-id"===t?this.elevenLabsElement.setAttribute("agent-id",r):"font-color"!==t&&"link-color"!==t||e.config&&("font-color"===t&&(e.config.fontColor=r),"link-color"===t&&(e.config.linkColor=r),setTimeout((()=>e.attemptRelabelEverywhere()),100)))}async init(){try{customElements.get("elevenlabs-convai")||await e.loadElevenLabsScript(),this.elevenLabsElement=document.createElement("elevenlabs-convai");const t=this.getAttribute("agent-id")||e.config.agentId;this.elevenLabsElement.setAttribute("agent-id",t);for(const e of this.attributes)["font-color","link-color"].includes(e.name)||this.elevenLabsElement.setAttribute(e.name,e.value);this.elevenLabsElement.style.cssText=this.style.cssText,this.appendChild(this.elevenLabsElement),this.initialized=!0;const i=this.getAttribute("font-color"),r=this.getAttribute("link-color");i&&(e.config.fontColor=i),r&&(e.config.linkColor=r),e.log("upriser-convai element initialized"),this.dispatchEvent(new CustomEvent("upriser:initialized",{bubbles:!0,detail:{element:this,agentId:t}}))}catch(e){console.error("Failed to initialize upriser-convai element:",e),this.dispatchEvent(new CustomEvent("upriser:error",{bubbles:!0,detail:{error:e,element:this}}))}}show(){if(this.elevenLabsElement&&"function"==typeof this.elevenLabsElement.show)return this.elevenLabsElement.show()}hide(){if(this.elevenLabsElement&&"function"==typeof this.elevenLabsElement.hide)return this.elevenLabsElement.hide()}toggle(){if(this.elevenLabsElement&&"function"==typeof this.elevenLabsElement.toggle)return this.elevenLabsElement.toggle()}destroy(){this.elevenLabsElement&&(this.elevenLabsElement.remove(),this.elevenLabsElement=null),this.initialized=!1}}try{customElements.define("upriser-convai",t),this.log("upriser-convai custom element defined successfully")}catch(e){console.error("Failed to define upriser-convai custom element:",e)}}relabelAndRewriteLinks(e){try{if(!e)return!1;let t=!1;if(!document.querySelector("#upriser-chat-styles")){const i=document.createElement("style");if(i.id="upriser-chat-styles",i.textContent=`\n .bg-base.shrink-0.flex.gap-2.p-4.items-start {\n align-items: center !important;\n }\n .bg-base.shrink-0[class*="items-start"] {\n align-items: center !important;\n }\n .bg-base.items-start {\n align-items: center !important;\n }\n /* Apply linkColor to all links within the widget */\n elevenlabs-convai a, \n upriser-convai a,\n elevenlabs-convai a:visited,\n upriser-convai a:visited,\n elevenlabs-convai a:hover,\n upriser-convai a:hover,\n elevenlabs-convai a:focus,\n upriser-convai a:focus {\n color: ${this.config.linkColor} !important;\n opacity: 1 !important;\n }\n \n /* Remove opacity classes that make links gray */\n elevenlabs-convai a.opacity-30,\n upriser-convai a.opacity-30,\n elevenlabs-convai a.opacity-50,\n upriser-convai a.opacity-50,\n elevenlabs-convai a.opacity-70,\n upriser-convai a.opacity-70 {\n opacity: 1 !important;\n }\n `,e.appendChild)try{e.appendChild(i),t=!0}catch{document.head.querySelector("#upriser-chat-styles")||(document.head.appendChild(i),t=!0)}else document.head.querySelector("#upriser-chat-styles")||(document.head.appendChild(i),t=!0)}(e.querySelectorAll?e.querySelectorAll("img"):[]).forEach((e=>{const i=e.src||e.getAttribute("src")||"";"true"!==e.getAttribute("data-upriser-protected")&&"true"!==e.getAttribute("data-upriser-conversation-logo")&&i.includes("data:image")&&!i.includes("/upriser-logo.svg")&&(e.src="/upriser-logo.svg",e.setAttribute("alt","Upriser AI Assistant"),e.setAttribute("data-upriser-replaced","true"),t=!0)}));(e.querySelectorAll?e.querySelectorAll("*"):[]).forEach((e=>{const i=getComputedStyle(e).backgroundImage||e.style.backgroundImage||"";i.includes("data:image")&&!i.includes("/upriser-logo.svg")&&(e.style.backgroundImage="url(/upriser-logo.svg)",e.style.backgroundSize="contain",e.style.backgroundPosition="center",e.style.backgroundRepeat="no-repeat",e.setAttribute("data-upriser-bg-replaced","true"),t=!0)}));let i=!1;try{i="true"===sessionStorage.getItem("upriser-conversation-started")}catch{i=!0===window.upriserConversationStarted}(e.querySelectorAll?e.querySelectorAll('.relative.shrink-0.w-48.h-48, [class*="relative"][class*="w-48"][class*="h-48"]'):[]).forEach((e=>{e.querySelectorAll('.absolute.inset-0.rounded-full.overflow-hidden.bg-base.bg-cover, [class*="absolute"][class*="inset-0"][class*="rounded-full"][class*="bg-cover"]').forEach((e=>{e.style.display="none"}));e.querySelectorAll('.el-wave-overlay, canvas, [class*="wave"]').forEach((e=>{e.style.display="none"}));const i=e.querySelector(".absolute.inset-0.rounded-full.bg-base-border"),r=e.getAttribute("data-upriser-hidden-conversation"),n="none"!==e.style.display;if(i&&!r&&n&&!e.getAttribute("data-upriser-logo-added")){const i=document.createElement("img");i.src="/upriser-logo.svg",i.alt="Upriser AI Assistant",i.style.cssText="\n position: absolute;\n inset: 0;\n width: 100%;\n height: 100%;\n object-fit: contain;\n padding: 20%;\n z-index: 100;\n ",i.setAttribute("data-upriser-logo","true"),i.setAttribute("data-upriser-protected","true"),e.appendChild(i),e.setAttribute("data-upriser-logo-added","true"),t=!0}}));const r=e.querySelectorAll?e.querySelectorAll('[class*="justify-end"]'):[],n=e.querySelectorAll?e.querySelectorAll('[class*="bg-accent"]'):[],o=e.querySelectorAll?e.querySelectorAll('[class*="pl-16"]'):[],s=e.querySelectorAll?e.querySelectorAll('[class*="text-accent-primary"]'):[];if(r.length>0||n.length>0||o.length>0||s.length>0){(e.querySelectorAll?e.querySelectorAll(".bg-base.shrink-0.flex.gap-2.p-4"):[]).forEach((i=>{const r=i.querySelector(".animate-text");if(r&&r.textContent&&r.textContent.includes("Chatting with AI Agent")&&!i.getAttribute("data-upriser-hidden")){i.style.transition="opacity 0.3s ease-out",i.style.opacity="0",setTimeout((()=>{i.style.display="none"}),300),i.setAttribute("data-upriser-hidden","true"),t=!0;(e.querySelectorAll?e.querySelectorAll('.relative.shrink-0.w-48.h-48, [class*="relative"][class*="w-48"][class*="h-48"]'):[]).forEach((e=>{e.style.display="none",e.setAttribute("data-upriser-hidden-conversation","true")}));try{sessionStorage.setItem("upriser-conversation-started","true")}catch{window.upriserConversationStarted=!0}}}));(e.querySelectorAll?e.querySelectorAll('.px-4.pb-3.grow.flex.flex-col.gap-3, [class*="px-4"][class*="pb-3"][class*="grow"][class*="flex-col"]'):[]).forEach((e=>{e.getAttribute("data-upriser-padded")||(e.style.paddingTop="15px",e.setAttribute("data-upriser-padded","true"),t=!0)}))}(e.querySelectorAll?e.querySelectorAll('.bg-base.shrink-0, .bg-base.items-start, [class*="bg-base"][class*="items-start"]'):[]).forEach((e=>{e.classList.contains("items-start")&&!e.getAttribute("data-upriser-centered")&&(e.style.setProperty("align-items","center","important"),e.setAttribute("data-upriser-centered","true"),t=!0)}));(e.querySelectorAll?e.querySelectorAll("span.opacity-30, .opacity-30"):[]).forEach((e=>{if("Powered by ElevenLabs"===(e.textContent?e.textContent.trim():"")){if("true"===e.getAttribute("data-upriser-branded"))return;e.textContent="Powered by Upriser.ai",e.style.fontFamily="Plus Jakarta Sans, sans-serif",e.classList.remove("opacity-30","opacity-50","opacity-70"),e.classList.add("upriser-white"),e.setAttribute("data-upriser-branded","true"),e.style.setProperty("color",this.config.fontColor,"important"),e.style.setProperty("opacity","1","important"),t=!0}}));return(e.querySelectorAll?e.querySelectorAll("a[href]"):[]).forEach((e=>{const i=e.getAttribute("href")||"",r=(e.textContent||"").trim();if(e.getAttribute("data-upriser-color-applied")||(e.style.setProperty("color",this.config.linkColor,"important"),e.style.setProperty("opacity","1","important"),e.classList.remove("opacity-30","opacity-50","opacity-70"),e.setAttribute("data-upriser-color-applied","true"),t=!0),i.includes("elevenlabs")||"Conversational AI"===r||r.includes("ElevenLabs")){if("true"===e.getAttribute("data-upriser-processed"))return;e.style.fontFamily="Plus Jakarta Sans, sans-serif",e.setAttribute("href","https://www.upriser.ai"),e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"),e.setAttribute("data-upriser-processed","true");const i=e.cloneNode(!0);e.parentNode.replaceChild(i,e),i.addEventListener("click",(e=>{try{e.preventDefault()}catch{}try{window.open("https://www.upriser.ai","_blank","noopener,noreferrer")}catch{window.location.href="https://www.upriser.ai"}}),{once:!0}),r.includes("ElevenLabs")&&(i.textContent=r.replace(/ElevenLabs/g,"Upriser.ai")),t=!0}})),t}catch{return!1}}attemptRelabelEverywhere(){try{let e=this.relabelAndRewriteLinks(document.body);const t=document.querySelector("upriser-convai"),i=document.querySelector("elevenlabs-convai"),r=t||i;r&&r.shadowRoot&&(e=this.relabelAndRewriteLinks(r.shadowRoot)||e,r._upriserObserverSetup||(this.setupShadowRootObserver(r.shadowRoot),r._upriserObserverSetup=!0));try{document.querySelectorAll("*").forEach((t=>{const i=t.shadowRoot;i&&(e=this.relabelAndRewriteLinks(i)||e)}))}catch{}return e}catch(e){return this.log("Error in attemptRelabelEverywhere:",e),!1}}setupShadowRootObserver(e){new MutationObserver((t=>{let i=!1;t.forEach((e=>{if("childList"===e.type)e.addedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e;("IMG"===t.tagName||t.querySelector&&t.querySelector("img"))&&(i=!0)}}));else if("attributes"===e.type&&e.target instanceof HTMLImageElement&&"src"===e.attributeName){e.target.src.includes("data:image")&&(i=!0)}})),i&&setTimeout((()=>{this.relabelAndRewriteLinks(e)}),50)})).observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src"]})}startRelabelFlow(){this.setupMutationObserver(),this.attemptRelabelEverywhere();const e=setInterval((()=>{const t=document.querySelector("upriser-convai"),i=document.querySelector("elevenlabs-convai"),r=t||i;r&&(r.shadowRoot||t&&t.querySelector("elevenlabs-convai"))&&(this.log("Widget loaded, attempting relabeling..."),this.attemptRelabelEverywhere()&&(this.log("Relabeling successful, stopping retry interval"),clearInterval(e),this.intervals.delete("relabel-retry"),this.isRelabelingComplete=!0))}),1e3);this.intervals.set("relabel-retry",e);const t=setTimeout((()=>{const e=this.intervals.get("relabel-retry");e&&(clearInterval(e),this.intervals.delete("relabel-retry")),this.log("Stopped retrying relabeling after 30 seconds")}),3e4);this.timeouts.set("relabel-timeout",t)}setupMutationObserver(){this.mutationObserver&&this.mutationObserver.disconnect();let e=null;this.mutationObserver=new MutationObserver((t=>{let i=!1;t.forEach((e=>{if("childList"===e.type)e.addedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e;("IMG"===t.tagName||t.querySelector&&t.querySelector("img"))&&(i=!0)}}));else if("attributes"===e.type&&e.target instanceof HTMLImageElement&&"src"===e.attributeName){e.target.src.includes("data:image")&&(i=!0)}})),e&&clearTimeout(e),e=setTimeout((()=>{this.attemptRelabelEverywhere()}),100)})),this.mutationObserver.observe(document.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["src","style","class"]})}startAutoAcceptFlow(){let e=!1,t=!1;const i=t=>{if(!t||e)return!1;const r=t.querySelectorAll?t.querySelectorAll('button, [role="button"], span, div'):[];for(let t=0;t<r.length;t++){const n=r[t];if("Accept"===(n.textContent||"").trim()){try{n.dispatchEvent(new MouseEvent("click",{bubbles:!0}))}catch{n.click&&n.click()}return e=!0,!0}const o=n.shadowRoot;if(o&&i(o))return!0}return!1},r=(e=!1)=>{try{this.wireStartCallHide(document.body),this.removeNeedHelpElement(document.body);const t=document.querySelector("elevenlabs-convai");t&&t.shadowRoot&&(this.wireStartCallHide(t.shadowRoot),this.removeNeedHelpElement(t.shadowRoot)),e&&this.showWidgetAfterDelay(500)}catch{}},n=()=>{try{const e=document.querySelector("upriser-convai"),i=document.querySelector("elevenlabs-convai");(e||i)&&!t?(this.hideWidgetInitially(),t=!0,setTimeout((()=>{r(!0)}),100)):r(!1)}catch{}let e=i(document.body);const n=document.querySelector("upriser-convai"),o=document.querySelector("elevenlabs-convai"),s=n||o;if(s&&s.shadowRoot)e=i(s.shadowRoot)||e;else if(n&&n.querySelector("elevenlabs-convai")){const t=n.querySelector("elevenlabs-convai");t.shadowRoot&&(e=i(t.shadowRoot)||e)}return e};let o=0;const s=setInterval((()=>{(n()||++o>=120)&&(clearInterval(s),this.intervals.delete("auto-accept"))}),500);this.intervals.set("auto-accept",s);new MutationObserver((e=>{const i=document.querySelector("upriser-convai"),o=document.querySelector("elevenlabs-convai");let s=!1,l=!1;if((i||o)&&!t)return this.hideWidgetInitially(),t=!0,void setTimeout((()=>{r(!0)}),100);e.forEach((e=>{"childList"===e.type&&(e.addedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e;(t.textContent&&t.textContent.includes("Need help?")||t.querySelector&&t.querySelector('[text*="Need help?"]'))&&(s=!0);const i=t.textContent?t.textContent.toLowerCase():"";(i.includes("start a call")||i.includes("send message"))&&(l=!0)}})),e.removedNodes.forEach((e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e,i=t.textContent?t.textContent.toLowerCase():"";(i.includes("calling")||i.includes("connected")||i.includes("recording"))&&(l=!0)}})))})),l&&setTimeout((()=>{try{this.resetWidgetToInitialState()}catch{}}),100),r(!1),n()})).observe(document.documentElement,{childList:!0,subtree:!0});const l=new MutationObserver((()=>{r(!1)})),a=()=>{const e=document.querySelector("upriser-convai"),t=document.querySelector("elevenlabs-convai"),i=e||t;if(i&&i.shadowRoot)try{l.observe(i.shadowRoot,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0})}catch{}else if(e&&e.querySelector("elevenlabs-convai")){const t=e.querySelector("elevenlabs-convai");if(t.shadowRoot)try{l.observe(t.shadowRoot,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0})}catch{}}},c=setInterval(a,1e3);this.intervals.set("shadow-check",c),a(),document.addEventListener("click",(e=>{const t=e.target;t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"true"===t.contentEditable||t.closest("input, textarea, [contenteditable]")||"textbox"===t.getAttribute("role"))&&this.cancelHideTimeout()}),{capture:!0})}hideWidgetInitially(){const e=document.querySelector("upriser-convai"),t=document.querySelector("elevenlabs-convai"),i=e||t;i&&(i.style.setProperty("visibility","hidden","important"),i.style.setProperty("opacity","0","important"))}showWidgetAfterDelay(e=500){const t=setTimeout((()=>{const e=document.querySelector("upriser-convai"),t=document.querySelector("elevenlabs-convai"),i=e||t;if(i)try{i.style.removeProperty("visibility"),i.style.removeProperty("opacity")}catch{}}),e);this.timeouts.set("show-widget",t)}hideWidgetTemporarily(e=500){const t=document.querySelector("upriser-convai"),i=document.querySelector("elevenlabs-convai"),r=t||i;if(!r)return;const n=this.timeouts.get("hide-widget");n&&clearTimeout(n),r.style.setProperty("visibility","hidden","important"),r.style.setProperty("opacity","0","important");const o=setTimeout((()=>{try{r.style.removeProperty("visibility"),r.style.removeProperty("opacity"),this.timeouts.delete("hide-widget")}catch{}}),e);this.timeouts.set("hide-widget",o)}cancelHideTimeout(){const e=this.timeouts.get("hide-widget");if(e){clearTimeout(e),this.timeouts.delete("hide-widget");const t=document.querySelector("upriser-convai"),i=document.querySelector("elevenlabs-convai"),r=t||i;if(r)try{r.style.removeProperty("visibility"),r.style.removeProperty("opacity")}catch{}}}removeNeedHelpElement(e){try{if(!e)return!1;let t=!1;return(e.querySelectorAll?e.querySelectorAll("div"):[]).forEach((e=>{if("Need help?"===(e.textContent||"").trim()){let i=e,r=e.parentElement;for(;r;){const e=r.className||"";if(e.includes("relative")&&e.includes("inline-flex")&&e.includes("shrink-0")&&e.includes("justify-center")&&e.includes("items-center")&&e.includes("transition-")&&e.includes("min-w-0")&&e.includes("z-1")){i=r;break}r=r.parentElement}try{i.remove(),t=!0}catch(e){i.style.setProperty("display","none","important"),t=!0}}})),t}catch{return!1}}wireStartCallHide(e){(e.querySelectorAll?e.querySelectorAll('button, [role="button"]'):[]).forEach((e=>{if(e.dataset&&"1"===e.dataset.upriserWired)return;const t=(e.textContent||"").trim();"Start a call"!==t&&"Send message"!==t&&!t.includes("Call")||e.closest("input, textarea, [contenteditable]")||e.querySelector("input, textarea, [contenteditable]")||(e.dataset&&(e.dataset.upriserWired="1"),e.addEventListener("click",(e=>{const t=e.target;t&&("INPUT"===t.tagName||"TEXTAREA"===t.tagName||"true"===t.contentEditable||t.closest("input, textarea, [contenteditable]"))||this.hideWidgetTemporarily(500)}),{capture:!0}));const i=e.shadowRoot;i&&this.wireStartCallHide(i)}))}resetWidgetToInitialState(){try{const e=document.querySelector("upriser-convai"),t=document.querySelector("elevenlabs-convai"),i=e||t;if(!i)return;if(this.clearWidgetWiring(document.body),i.shadowRoot)this.clearWidgetWiring(i.shadowRoot);else if(e&&e.querySelector("elevenlabs-convai")){const t=e.querySelector("elevenlabs-convai");t.shadowRoot&&this.clearWidgetWiring(t.shadowRoot)}if(i.shadowRoot){const e=i.shadowRoot;e.querySelectorAll('button, [role="button"]').forEach((e=>{const t=(e.textContent||"").trim().toLowerCase();if(t.includes("end")||t.includes("close")||t.includes("hang up")||"×"===t)try{e.click()}catch{}})),setTimeout((()=>{try{this.removeNeedHelpElement(e),this.wireStartCallHide(e),this.removeNeedHelpElement(document.body),this.wireStartCallHide(document.body)}catch{}}),500)}}catch(e){this.log("Error resetting widget state:",e)}}clearWidgetWiring(e){try{(e.querySelectorAll?e.querySelectorAll('button, [role="button"]'):[]).forEach((e=>{e.dataset&&delete e.dataset.upriserWired}))}catch{}}updateConfig(e){this.config={...this.config,...e},this.log("Configuration updated:",e)}destroy(){this.timeouts.forEach((e=>{clearTimeout(e)})),this.timeouts.clear(),this.intervals.forEach((e=>{clearInterval(e)})),this.intervals.clear(),this.mutationObserver&&(this.mutationObserver.disconnect(),this.mutationObserver=null);const e=document.querySelector("upriser-convai"),t=document.querySelector("elevenlabs-convai");e&&e.remove(),t&&t.remove(),this.clearWidgetWiring(document.body);const i=document.querySelector("#upriser-chat-styles");i&&i.remove(),this.isInitialized=!1,this.isRelabelingComplete=!1,this.eventHandlers.clear(),this.log("Widget destroyed and cleaned up")}test(){this.log("Testing Upriser Widget functionality...");const e=this.attemptRelabelEverywhere();return this.log("Relabel test result:",e),this.log("Widget test completed"),{relabeling:e,isInitialized:this.isInitialized}}log(...e){this.config.debug&&console.log("[Upriser Widget]",...e)}}"undefined"!=typeof module&&module.exports&&(module.exports=UpriserWidget),function(){"use strict";function e(){try{if(window.upriserWidget&&window.upriserWidget.isInitialized)return console.log("[Upriser Widget] Already initialized"),window.upriserWidget;const e=new UpriserWidget(window.UPRISER_WIDGET_CONFIG);return e.init().catch((function(e){console.error("[Upriser Widget] Initialization failed:",e)})),window.upriserWidget=e,e}catch(e){return console.error("[Upriser Widget] Failed to create widget:",e),null}}"undefined"!=typeof window&&"undefined"!=typeof document&&(window.UpriserWidget=UpriserWidget,window.UPRISER_WIDGET_CONFIG||(window.UPRISER_WIDGET_CONFIG={agentId:"agent_8401k5nnvgqpezf9fd17t3tb7t69",debug:!1}),window.UPRISER_DISABLE_AUTO_INIT||("complete"!==document.readyState&&"interactive"!==document.readyState?("loading"===document.readyState&&document.addEventListener("DOMContentLoaded",e),window.addEventListener("load",(function(){window.upriserWidget&&window.upriserWidget.isInitialized||e()})),"undefined"!=typeof jQuery&&jQuery(document).ready((function(){window.upriserWidget&&window.upriserWidget.isInitialized||e()}))):e()),window.initUpriserWidget=e)}();