// assume jquery is already loaded var chatBot_autoOpen = true; var chatBot_n = #N#; var chatBot_interval = 1000; var chatBot_nInitial = chatBot_n; var chatBot_showActions = false; var chatBot_language = ""; var chatBot_started = false; var chatBot_cookie = localStorage.getItem('chatbot-cookie'); const urlParams = new URLSearchParams(window.location.search); const botEnable = urlParams.get('bot'); if (#BOT_ON# || botEnable == "1") { console.log("cookie 1: " + chatBot_cookie); if (!chatBot_cookie) { chatBot_cookie = Math.random().toString(36).substr(2, 9); localStorage.setItem('chatbot-cookie', chatBot_cookie); console.log("cookie 2: " + chatBot_cookie); } // workaround to get $ from wordpress version of jQuery jQuery(document).ready(function ($) { console.log("loading 2"); // bot styles (#1025978) $('head').append(''); // bootstrap function dynamicallyLoadScript(url) { var script = document.createElement("script"); script.src = url; document.head.appendChild(script); } // bootstrap js dynamicallyLoadScript('https://botcompany.de/1014036/raw/1025981?contentType=text/javascript'); // scripts for bot function chatBot_open() { console.log("Opening chat bot"); $('#qnimate').addClass('popup-box-on'); $("#scrollme").scrollTop(1E10); $('#status_message').focus(); if (!chatBot_started) { chatBot_started = true; try { if (GTranslateGetCurrentLang) chatBot_language = GTranslateGetCurrentLang(); console.log("lang: " + chatBot_language); } catch (err) { console.log(err); } chatBot_start(); } } $(function(){ $(".chatOpenAction").click(function () { chatBot_open(); return false; }); $("#removeClass").click(function () { $('#qnimate').removeClass('popup-box-on'); return false; }); }); function chatBot_showAction(action) { if (chatBot_showActions) { $("#actionMsg").html(action); $("#actionMsg").show(); } console.log(action); } window.chatBot_appendAction = function(action) { if (chatBot_showActions) { $("#actionMsg").append(" | " + action); $("#actionMsg").show(); } }; window.chatBot_hideAction = function() { $("#actionMsg").hide(); $("#actionMsg").html(""); }; window.chatBot_start = function() { url = "#INCREMENTALURL#"; if (url != '' && url != ("#INC" + "REMENTALURL#")) { url += chatBot_n + "&cookie=" + chatBot_cookie; if (chatBot_language) url += "&language_default=" + chatBot_language; chatBot_showAction("Loading " + url); $.get(url, function(src) { chatBot_showAction("Loaded"); var match = src.match(/\d+/); if (match != null) { var newN = parseInt(match[0]); if (src.match(/NEW DIALOG -->/)) $(".direct-chat-messages").html(src); else { // hide old buttons $(".direct-chat-msg:has(.direct-chat-buttons)").hide(); $(".chatbot-choice-button, .chat-button-span").hide(); $(".direct-chat-messages").append(src); } chatBot_n = newN; $("#scrollme").scrollTop(1E10); chatBot_showAction("Appended " + src.length); console.log(src); } else chatBot_showAction("chatBot_n=" + chatBot_n + " (initial=" + chatBot_nInitial + ")"); chatBot_appendAction("Rescheduling"); setTimeout(chatBot_start, chatBot_interval); chatBot_appendAction("Rescheduled"); }, 'text') .fail(function() { chatBot_showAction("Rescheduling after fail"); setTimeout(chatBot_start, chatBot_interval); }); } }; // also focuses input field window.chatBot_setInput = function(text, placeholder) { if (placeholder == '') placeholder = "Type a message..."; $('#status_message').attr('placeholder', placeholder) .val(text) .select() .focus(); }; window.submitAMsg = function(msg) { status_message.value = msg; submitMsg(); }; window.submitMsg = function() { /*if (status_message.value == 'new dialog') document.forms['msgform'].submit(); else*/ { url = '#MSGURL#' + encodeURIComponent(status_message.value) + "&cookie=" + chatBot_cookie; if (chatBot_language) url += "&language_default=" + chatBot_language; chatBot_showAction('Submitting ' + url); $.get(url); status_message.value = ''; } }; $('body').append(`