window.js_settings = {"user\/chat\/widget\/text":"\ud83e\udd16 Wie kann ich helfen?","user\/chat\/widget\/text_color":"white","user\/chat\/widget\/background":"#db3158","user\/chat\/widget\/text_font":"'Roboto','Helvetica Neue',Helvetica,Arial,sans-serif","user\/chat\/widget\/position":"bottom-left","base_url":"\/\/ai.mobweb.gmbh\/"};(function () { // Define the logging function function log(message, messageData) { // Prepare the message var messagePrefix = '[Chatbot Assistant] '; message = messagePrefix + message; // Log the message and message data to the console console.log(message, messageData); } // Log log('Initializing chatbot assistant widget'); // From the request, get the "client key" parameter to identify the current client var scriptUrl = document.currentScript.src; var clientKey = new URL(scriptUrl).searchParams.get('client_key'); // If no key could be loaded, we have to abort if (!clientKey) { log('No client key found in the script URL, aborting initialization'); return; } // Log the key log('Client key loaded:', clientKey); // Prepare the widget var widget = document.createElement('div'); // Fixed settings widget.style.zIndex = '9999'; widget.style.cursor = 'pointer'; widget.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)'; widget.style.padding = '10px 15px'; widget.style.borderRadius = '20px'; widget.style.fontWeight = 'bold'; widget.style.transition = 'transform 0.3s'; // Add hover styles widget.addEventListener('mouseenter', function () { widget.style.transform = 'scale(1.1)'; }); widget.addEventListener('mouseleave', function () { widget.style.transform = 'scale(1)'; }); // Dynamic settings widget.innerHTML = window.js_settings['user/chat/widget/text']; widget.style.color = window.js_settings['user/chat/widget/text_color']; widget.style.background = window.js_settings['user/chat/widget/background']; widget.style.fontFamily = window.js_settings['user/chat/widget/text_font']; // Set up the widget position if (window.js_settings['user/chat/widget/position'] === 'bottom-left') { widget.style.position = 'fixed'; widget.style.bottom = '20px'; widget.style.left = '20px'; } else if(window.js_settings['user/chat/widget/position'] === 'bottom-right') { widget.style.position = 'fixed'; widget.style.bottom = '20px'; widget.style.right = '20px'; } // Append button to body document.body.appendChild(widget); // Function to open the iFrame with the chat form function openIFrame() { // Set up the iFrame container var iFrameContainer = document.createElement('div'); iFrameContainer.style.position = 'fixed'; iFrameContainer.style.width = '100%'; iFrameContainer.style.height = '100%'; iFrameContainer.style.top = '0'; iFrameContainer.style.left = '0'; iFrameContainer.style.zIndex = '10000'; // Prepare the "Close" button which closes the iFrame var iFrameCloseButton = document.createElement('div'); iFrameCloseButton.innerHTML = '×'; iFrameCloseButton.style.position = 'absolute'; iFrameCloseButton.style.top = '12px'; iFrameCloseButton.style.right = '15px'; iFrameCloseButton.style.cursor = 'pointer'; iFrameCloseButton.style.fontSize = '24px'; iFrameCloseButton.style.color = '#333'; iFrameCloseButton.style.fontWeight = 'bold'; iFrameCloseButton.style.zIndex = '10001'; // Close the iFrame when the "Close" button is clicked iFrameCloseButton.addEventListener('click', function () { document.body.removeChild(iFrameContainer); }); // Prepare the iFrame itself var iFrame = document.createElement('iframe'); iFrame.src = window.js_settings['base_url'] + 'chatbot-assistant/chat?client_key=' + clientKey; iFrame.style.width = '100%'; iFrame.style.height = '100%'; iFrame.style.position = 'absolute'; iFrame.style.top = '0'; iFrame.style.left = '0'; // Append the elements to the body iFrameContainer.appendChild(iFrameCloseButton); iFrameContainer.appendChild(iFrame); document.body.appendChild(iFrameContainer); } // Open the iFrame when the widget is clicked widget.addEventListener('click', openIFrame); })();