function initHubreUI(window) { var config = { url: 'https://dashboard.hubre.ai/client/chitchat/message', bot_id: '526847021961707524', tenant_id: '519836917622112260', bottom: '30px', right: '20px', iframeWidth: '390px', iframeHeight: '600px', launcher_location: 'footer', launcher_auto_eject: true, launcher_eject_period: 10, btnImg: 'https://hubre.blob.core.windows.net/hubreai/img/bot/launcher/1.png?se=2025-04-06T07%3A18%3A38Z&sp=r&sv=2024-05-04&sr=b&sig=Y8mWcpgDaEczjy05HRUHJSbOCgV%2BSSd6PyCmTq3flk0%3D', btnBackgroudColor: '#249B6D', btnBackgroudColorOpacity: 100, launcherRemindTips: 'Need help? Talk to us now' } function isMobile() { var os = function () { var ua = navigator.userAgent, isWindowsPhone = /(?:Windows Phone)/.test(ua), isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone, isAndroid = /(?:Android)/.test(ua), isFireFox = /(?:Firefox)/.test(ua), isChrome = /(?:Chrome|CriOS)/.test(ua), isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)), isPhone = /(?:iPhone)/.test(ua) && !isTablet, isPc = !isPhone && !isAndroid && !isSymbian; return { isTablet: isTablet, isPhone: isPhone, isAndroid: isAndroid, isPc: isPc }; }(); return os; } function addRemoveMobile() { console.log(isMobile(), 'isMobile()') if(isMobile().isAndroid || isMobile().isPhone) { iframeBox.classList.add('intercom-namespace-mobile'); }else { iframeBox.classList.remove('intercom-namespace-mobile'); chatBox.style.display = 'block'; } } var iframeBox,chatBox,iframe; function loadInit() { iframeBox = document.createElement('div'); chatBox = document.createElement('div'); iframe = document.createElement('iframe'); iframeBox.classList.add('intercom-namespace'); iframeBox.setAttribute('id', 'iframeBox'); chatBox.classList.add('intercom-with-namespace'); chatBox.setAttribute('id', 'chatBox'); chatBox.innerHTML = `
${config.launcherRemindTips}
` addRemoveMobile() window.onresize = function () { addRemoveMobile() } closeIframe() iframe.setAttribute('id', 'iframeDom'); iframe.setAttribute('style', 'width: 100%; height: 100%;'); iframe.setAttribute('allowfullscreen', 'allowfullscreen'); iframe.setAttribute('allowtransparency', 'allowtransparency'); iframe.setAttribute('frameBorder', '0'); iframe.setAttribute('fallowTransparency', true); iframe.setAttribute('aria-hidden', true); iframe.setAttribute('scrolling', 'no'); iframe.setAttribute('width', '100%'); iframe.setAttribute('height', '100%'); iframe.setAttribute('Access-Control-Allow-Origin', '*'); iframe.setAttribute('cross-origin', '*'); iframe.setAttribute('allow', '*'); iframe.setAttribute('src', `${config.url}?bot_id=${config.bot_id}&tenant_id=${config.tenant_id}`); console.log(document.body) document.body.appendChild(iframeBox); document.body.appendChild(chatBox); iframe.addEventListener('load', function () { var iframeDom = document.getElementById('iframeDom'); if (iframeDom.contentWindow && config.launcher_auto_eject) { console.log('iframe加载完成'); setTimeout(function () { openIframe() }, config.launcher_eject_period * 1000) } }) } function addCssStyle() { var css = ` .intercom-namespace{ z-index: 2147483000; position: fixed; bottom: calc(${config.bottom} + 75px); right: ${config.bottom}; transform-origin: right bottom; height: min(${config.iframeHeight}, 100% - 104px); min-height: 80px; width: ${config.iframeWidth}; max-height: ${config.iframeHeight}; box-shadow: rgba(0, 0, 0, 0.16) 0px 5px 40px; border-radius: 16px; overflow: hidden; opacity: 1; transition: width 200ms ease 0s, height 200ms ease 0s, max-height 200ms ease 0s, transform 300ms cubic-bezier(0, 1.2, 1, 1) 0s, opacity 83ms ease-out 0s; pointer-events: all; z-index: 2147483100; box-sizing: border-box; } .intercom-namespace-mobile{ width: 100% !important; height: 100% !important; border-radius: 0; top: 0; left: 0; bottom: 0; right: 0; max-height: inherit; max-width: inherit; box-sizing: border-box; } .intercom-with-namespace{ user-select: none; z-index: 2147483000; position: fixed; bottom: 30px; right: 20px; width: auto; height: 58px; transition: transform 167ms cubic-bezier(0.33, 0, 0, 1) 0s; transform-origin: center center; cursor: pointer; box-sizing: border-box; } .intercom-with-namespace-r0cx9n{ z-index: 2147483000; width: auto; height: 58px; border-radius: 58px; color-scheme: none; filter: drop-shadow(rgba(0, 0, 0, 0.06) 0px 1px 6px) drop-shadow(rgba(0, 0, 0, 0.16) 0px 2px 32px); padding: 5px; display: flex; align-items: center; background: #ffffff; box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.16); box-sizing: border-box; } .intercom-1lbdzel--text{ flex: 0 0 auto; padding: 0 32px 0 20px; font-weight: 400; font-size: 12px; color: #333333; font-family: Poppins-Regular, Poppins, sans-serif; box-sizing: border-box; } .intercom-1lbdzel { flex: 0 0 auto; background: ${config.btnBackgroudColor}; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; backface-visibility: hidden; overflow: hidden; -webkit-font-smoothing: antialiased; display: flex; align-items: center; justify-content: center; transition: transform 0.16s linear 0s, opacity 0.08s linear 0s; transform: scale(1); padding: 12px; box-sizing: border-box; } .intercom-1lbdzel-img{ width: 100%; height: 100%; border-radius: 50%; cursor: pointer; box-sizing: border-box; } `; const style = document.createElement('style') style.appendChild(document.createTextNode(css)); document.head.appendChild(style) } function closeIframe() { iframeBox.style.transform = 'scale(0)'; iframeBox.style.transition = 'transform 100ms cubic-bezier(0, 1.2, 1, 1) 0s'; iframeBox.style.opacity = '0'; iframeBox.style.display = 'none'; } function openIframe() { iframeBox.style.transform = 'scale(1)'; iframeBox.style.transition = 'transform 100ms cubic-bezier(0, 1.2, 1, 1) 0s'; iframeBox.style.opacity = '1'; iframeBox.style.display = 'block'; } function loadKeFu() { document.getElementById('iframeBox').appendChild(iframe); chatBox.addEventListener('click', () => { if (!iframeBox.style.transform || iframeBox.style.transform === 'scale(1)') { closeIframe() } else { openIframe() } }) } function _initial() { setTimeout(function(){ addCssStyle() loadInit() loadKeFu() }, 1000) } var numberCount = 0; (window.onload = function() { if (numberCount === 0 && document.body) { _initial() numberCount = 1 }else { setTimeout(function(){ if (numberCount === 0 && document.body) { _initial() numberCount = 1 } }, 500) } })(); window.addEventListener('message', (event) => { if (event.data === 'close') { closeIframe() } }) } window.EmbedHubreUI = { init: initHubreUI };