(function() { // Function to get query parameters from the script URL function getScriptParams() { const scripts = document.getElementsByTagName('script'); const lastScript = scripts[scripts.length - 1]; const scriptSrc = lastScript.src; const urlParams = new URLSearchParams(scriptSrc.split('?')[1]); return { autoOpen: urlParams.get('autoOpen') === 'true' }; } const params = getScriptParams(); // Create the chatbot icon var chatbotIcon = document.createElement('div'); chatbotIcon.classList.add('chatbot-icon'); chatbotIcon.innerHTML = ''; document.body.appendChild(chatbotIcon); // Create the chatbox container var chatboxContainer = document.createElement('div'); chatboxContainer.classList.add('chatbox-container'); chatboxContainer.innerHTML = `
Chat ×
`; document.body.appendChild(chatboxContainer); // Add event listeners chatbotIcon.addEventListener('click', function() { chatboxContainer.style.display = 'flex'; chatboxContainer.style.transform = 'translateY(0)'; }); document.querySelector('.chatbox-close').addEventListener('click', function() { chatboxContainer.style.transform = 'translateY(100%)'; setTimeout(() => chatboxContainer.style.display = 'none', 300); }); // Add styles var style = document.createElement('style'); style.innerHTML = ` .chatbot-icon { position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background-color: #000; color: white; display: flex; align-items: center; justify-content: center; cursor: pointer; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); z-index: 1000; } .chatbot-icon i { font-size: 24px; } .chatbox-container { font-family: Arial, sans-serif; font-size:100%; position: fixed; bottom: 90px; right: 20px; width: 350px; max-width: 90%; height: 500px; border-radius: 8px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); background-color: white; display: none; flex-direction: column; z-index: 1000; transform: translateY(100%); transition: transform 0.3s ease-in-out; } .chatbox-header { padding: 10px; background-color: #000; color: white; border-top-left-radius: 8px; border-top-right-radius: 8px; } .chatbox-body { flex: 1; overflow: hidden; overflow-y:hidden; } .chatbox-body iframe { width: 100%; height: 100%; border: none; } .chatbox-close { position: absolute; top: 5px; right: 10px; cursor: pointer; font-size:20px; } `; document.head.appendChild(style); // Load Font Awesome for the chat icon var fontAwesome = document.createElement('link'); fontAwesome.rel = 'stylesheet'; fontAwesome.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css'; document.head.appendChild(fontAwesome); // Auto open chatbox if configured if (params.autoOpen) { chatboxContainer.style.display = 'flex'; setTimeout(() => chatboxContainer.style.transform = 'translateY(0)', 0); } })();