(function() { var chatLoaded = false; function openChat() { var chatContainer = document.getElementById('mychat-container'); var buttonImg = document.getElementById('mybutton-img'); var chatButton = document.getElementById('myact-chat-button'); if (!chatLoaded) { buttonImg.src = 'https://35bc28c6733c7c1f4037e5151c40eee7.cdn.bubble.io/f1715882138611x417174930992066240/YlWC.gif'; chatButton.classList.add('loading'); if (!chatContainer) { chatContainer = document.createElement('div'); chatContainer.id = 'mychat-container'; chatContainer.style.display = 'none'; var chatIframe = document.createElement('iframe'); chatIframe.id = 'mychat-iframe'; var chatId = getCookie('chatId'); if (!chatId) { chatId = generateUniqueId(); var expirationDate = new Date(); expirationDate.setDate(expirationDate.getDate() + 7); document.cookie = "chatId=" + chatId + "; expires=" + expirationDate.toUTCString() + "; path=/"; } var iframeUrl = 'https://app.warplan.com/ai_chat_snippet/1717771813345x160803893529280500'; if (chatId) { iframeUrl += '?chatId=' + encodeURIComponent(chatId); } chatIframe.src = iframeUrl; chatIframe.frameBorder = '0'; chatIframe.onload = function() { buttonImg.src = 'https://35bc28c6733c7c1f4037e5151c40eee7.cdn.bubble.io/f1715884764724x519702217578905900/down%20%281%29.svg'; chatButton.classList.remove('loading'); chatLoaded = true; chatContainer.style.display = 'block'; }; chatContainer.appendChild(chatIframe); document.body.appendChild(chatContainer); } } else { if (chatContainer.style.display === 'block') { chatContainer.style.display = 'none'; buttonImg.src = 'https://35bc28c6733c7c1f4037e5151c40eee7.cdn.bubble.io/f1704303357620x392831682353280000/chat%20%282%29.svg'; } else { chatContainer.style.display = 'block'; buttonImg.src = 'https://35bc28c6733c7c1f4037e5151c40eee7.cdn.bubble.io/f1715884764724x519702217578905900/down%20%281%29.svg'; } } } function generateUniqueId() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); return v.toString(16); }); } function getCookie(name) { var cookieName = name + "="; var decodedCookie = decodeURIComponent(document.cookie); var cookieArray = decodedCookie.split(';'); for (var i = 0; i < cookieArray.length; i++) { var cookie = cookieArray[i]; while (cookie.charAt(0) == ' ') { cookie = cookie.substring(1); } if (cookie.indexOf(cookieName) == 0) { return cookie.substring(cookieName.length, cookie.length); } } return ""; } // Expose the openChat function to the global scope window.myNamespace = { openChat: openChat }; })();