2 lines
2.8 KiB
JavaScript
2 lines
2.8 KiB
JavaScript
import"./modulepreload-polyfill.b7f2da20.js";function n(){return window.innerWidth<=800&&window.innerHeight<=930}const m={desktop:{"account-setup":{height:"334px",width:"375px"},timeline:{height:"595px",width:"375px"}},mobile:{"account-setup":{height:"100vh",width:"100vw"},timeline:{height:"100vh",width:"100vw"}}};function i(){const t=document.querySelector(".chatterbox-iframe"),e=document.querySelector(".start");t.style.display!=="none"?(t.style.display="none",document.querySelector(".start-chat-btn").classList.remove("start-background-minimized"),t.contentWindow.postMessage({action:"minimize"},"*"),n()&&(e.style.display="block")):(t.contentWindow.postMessage({action:"maximize"},"*"),t.style.display="block",document.querySelector(".start-chat-btn").classList.add("start-background-minimized"),n()&&(e.style.display="none"))}function u(t){const{view:e}=t,o=n()?"mobile":"desktop",a=m[o][e];if(!a)return;const{height:r,width:c}=a,s=document.querySelector(".chatterbox-iframe");r&&(s.style.height=r),c&&(s.style.width=c)}function h(){document.querySelector(".chatterbox-iframe")?.remove(),document.querySelector(".start").remove()}const d=document.querySelector("#chatterbox-script").src,f=new URL(d).origin;function b(){w();const t=document.createElement("div");t.className="start";const e=p();t.appendChild(e),document.body.appendChild(t),window.localStorage.getItem("chatterbox-should-load-in-background")&&(l(!0),i())}function p(){const t=document.createElement("button");return t.className="start-chat-btn",t.setAttribute("aria-label","Start chat"),t.onclick=()=>window.isIframeLoaded?i():l(),t.appendChild(x()),t}function x(){const t=document.createElement("span");return t.className="notification-badge hidden",t}function w(){const t=document.createElement("link");t.rel="stylesheet",t.href=new URL("CSS_FILE_NAME",d).href,document.head.appendChild(t)}function l(t=!1){const e=document.createElement("iframe"),o=window.CHATTERBOX_CONFIG_LOCATION;if(!o)throw new Error("CHATTERBOX_CONFIG_LOCATION is not set");e.src=new URL(`../chatterbox.html?config=${o}${t?"&minimized=true":""}`,f).href,e.className="chatterbox-iframe",document.body.appendChild(e),window.isIframeLoaded=!0,document.querySelector(".start-chat-btn").classList.add("start-background-minimized"),n()&&(document.querySelector(".start").style.display="none")}window.isIframeLoaded=!1;window.__chatterbox=()=>document.querySelector(".chatterbox-iframe")?.contentWindow;function g(t){const e=document.querySelector(".notification-badge");t===0?e.classList.add("hidden"):(e.innerText=t,e.classList.remove("hidden"))}window.addEventListener("message",t=>{const{action:e}=t.data;switch(e){case"resize-iframe":t.data.view==="timeline"&&window.localStorage.setItem("chatterbox-should-load-in-background","true"),u(t.data);break;case"minimize":i();break;case"unread-message":g(t.data.count);break;case"error":h();break}});b();
|