var popupDiv; var popupProductDiv; var toggleButton; var ysa_iframe; var hidedPopupDiv; var statusCircleDivHided; var chatcreatorlabelDiv1; var chatcreatorlabelImg1; var chatcreatorlabelDiv2; var chatcreatorlabelImg2; var hidedPopupDivTitle; var popupNotificationDiv; var TimeshowTitleTextTyper; // Get the height of the window's content area var ysa_windowHeight = window.innerHeight; var ysa_windowWidth = window.innerWidth; var ysa_delay_seconds = 1000; var ysa_contact_data = []; // Configuration for the popup const ysa_config = { showDelaySec: 2, includePatterns: "", excludePatterns: "", allowedIPs: "" }; var ysa_isMobile = false; if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|Android|Silk|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(navigator.userAgent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(navigator.userAgent.substr(0,4))) { // ipad ysa_isMobile = true; } if (ysa_getCookie('ysa_small_popup_status_OUqXxJ') == '' && ysa_isMobile == false) { ysa_setCookie('ysa_small_popup_status_OUqXxJ', true); } else if (ysa_getCookie('ysa_small_popup_status_OUqXxJ') == '' && ysa_isMobile == true) { ysa_setCookie('ysa_small_popup_status_OUqXxJ', false); } if (ysa_getCookie('ysa_open_status_OUqXxJ') == 'true') { ysa_delay_seconds = 0; } if (ysa_getCookie('ysa_local_unique_id_OUqXxJ') == '') { ysa_setCookie('ysa_local_unique_id_OUqXxJ', 'ae198efd3c5af3dabd3fe18b9969f35e'); } function ysa_waitForBody() { if (document.body) { var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://app.youshouldask.ai/chat/popup-styles.css.php?wai=k2jHff&wci=OUqXxJ&1733153361'; document.head.appendChild(link); // JavaScript to load Google Fonts dynamically var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://fonts.googleapis.com/css?family=Inter:400,600,700&display=swap'; // Specify the font and styles you need document.head.appendChild(link); // JavaScript to load Google Fonts dynamically var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://fonts.googleapis.com/css?family=Inter:400,600,700&display=swap'; // Specify the font and styles you need document.head.appendChild(link); // Find the element with the class 'ysa_popup-div' var element = document.querySelector('.ysa_popup-div'); if (element) { document.body.removeChild(element); } var element = document.querySelector('.ysa_popup_notification'); if (element) { document.body.removeChild(element); } var element = document.querySelector('.ysa_hided_popup_div'); if (element) { document.body.removeChild(element); } var element = document.querySelector('.ysa_status_hided'); if (element) { document.body.removeChild(element); } // Create the pop-up div and apply class popupDiv = document.createElement('div'); popupDiv.classList.add('ysa_popup-div'); popupDiv.style.height = '0px'; // Create the pop-up product div and apply class popupProductDiv = document.createElement('div'); popupProductDiv.classList.add('ysa_popup-product-div'); popupProductDiv.setAttribute('id','ysa_popup-product-div'); popupProductDiv.style.height = '0px'; // Create the toggle button and apply class toggleButton = document.createElement('div'); toggleButton.classList.add('ysa_toggle-button'); // Create the ysa_iframe to load the content ysa_iframe = document.createElement('iframe'); ysa_iframe.classList.add('ysa_iframe'); // Set ID ysa_iframe.setAttribute('id','ysa_iframe'); // Set the allow attribute to request permission for autoplay ysa_iframe.setAttribute('allow', 'autoplay'); // Append the iframe to the pop-up div popupDiv.appendChild(ysa_iframe); // Create small avatar when hided hidedPopupDiv = document.createElement('div'); hidedPopupDiv.classList.add('ysa_hided_popup_div'); hidedPopupDiv.style.backgroundImage = 'url("https://app.youshouldask.ai/uploads/avatar_files/19_188334a31f940331507cfd494f8da6e6.png")'; // Create the online status circle statusCircleDivHided = document.createElement('div'); statusCircleDivHided.className = 'ysa_status_hided'; // Create the label 1 chatcreatorlabelDiv1 = document.createElement('div'); chatcreatorlabelDiv1.className = 'chat_creator_label notification'; chatcreatorlabelDiv1.textContent = 'YouShouldAsk.ai'; chatcreatorlabelImg1 = document.createElement('div'); chatcreatorlabelImg1.className = 'chat_creator_label_image'; chatcreatorlabelDiv1.appendChild(chatcreatorlabelImg1); // Create the label 2 chatcreatorlabelDiv2 = document.createElement('div'); chatcreatorlabelDiv2.className = 'chat_creator_label chatwindow'; chatcreatorlabelDiv2.textContent = 'YouShouldAsk'; chatcreatorlabelImg2 = document.createElement('div'); chatcreatorlabelImg2.className = 'chat_creator_label_image'; chatcreatorlabelDiv2.appendChild(chatcreatorlabelImg2); // Append the toggleButton and popupDiv to the body of the document document.body.appendChild(toggleButton); document.body.appendChild(popupDiv); document.body.appendChild(hidedPopupDiv); document.body.appendChild(statusCircleDivHided); document.body.appendChild(popupProductDiv); // Toggle functionality for hided popup hidedPopupDiv.addEventListener('click', function(){ ysa_showLargePopup(); }); popupDiv.appendChild(chatcreatorlabelDiv2); if (ysa_shouldShowPopup()) { var link = document.createElement('link'); link.rel = 'stylesheet'; link.href = 'https://app.youshouldask.ai/chat/popup-custom.css.php?wai=k2jHff&wci=OUqXxJ&1733153361'; document.head.appendChild(link); if (ysa_getCookie('ysa_open_status_OUqXxJ') == 'true') { ysa_config.showDelaySec = 0; } // Configurable threshold (in seconds) and reset time (1 day) const thresholdSeconds = ysa_config.showDelaySec; // Change this to your desired time const oneDayInMilliseconds = 24 * 60 * 60 * 1000; // 1 day in milliseconds // Retrieve or initialize the timer and timestamp const currentTime = Date.now(); const storedTimestamp = localStorage.getItem('ysa_visitStartTime'); const storedDuration = parseInt(localStorage.getItem('ysa_visitDuration')) || 0; // Check if the stored timestamp is older than one day or doesn't exist if (!storedTimestamp || currentTime - parseInt(storedTimestamp) > oneDayInMilliseconds) { localStorage.setItem('ysa_visitStartTime', currentTime); // Reset timestamp localStorage.setItem('ysa_visitDuration', 0); // Reset duration } // Initialize the total time spent from localStorage let totalSeconds = storedDuration; // Increment the timer every second const timer = setInterval(() => { totalSeconds++; localStorage.setItem('ysa_visitDuration', totalSeconds); // Check if the threshold is reached if (totalSeconds >= thresholdSeconds) { clearInterval(timer); // Stop the timer ysa_firePopup(); // Call your custom function } //console.log(totalSeconds); }, 1000); // Cleanup on page unload window.addEventListener('beforeunload', () => { localStorage.setItem('ysa_visitDuration', totalSeconds); }); } } else { // Retry after a short delay setTimeout(ysa_waitForBody, 50); // Check again after 50ms } } // Start checking for the body ysa_waitForBody(); function ysa_showLargePopup() { hidedPopupDiv.classList.remove('visible'); statusCircleDivHided.classList.remove('visible'); popupNotificationDiv.classList.add('visible'); ysa_setCookie('ysa_small_popup_status_OUqXxJ', true); } function ysa_firePopup() { // Create the pop-up notification div and set its class popupNotificationDiv = document.createElement('div'); popupNotificationDiv.className = 'ysa_popup_notification'; popupNotificationDiv.setAttribute('id','ysa_popup_notification'); popupNotificationDiv.style.backgroundColor = '#ffffff'; // Create the persona avatar div, set its class, and background image style var personaAvatarDiv = document.createElement('div'); personaAvatarDiv.className = 'ysa_persona_avatar'; personaAvatarDiv.style.backgroundImage = 'url("https://app.youshouldask.ai/uploads/avatar_files/19_188334a31f940331507cfd494f8da6e6.png")'; // Create the online status circle var statusCircleDiv = document.createElement('div'); statusCircleDiv.className = 'ysa_status'; // Create the close button div, set its class, and text content var closebuttonDiv = document.createElement('div'); closebuttonDiv.className = 'ysa_close_button_small_popup'; // Create the title div, set its class, and text content var titleDiv = document.createElement('div'); titleDiv.className = 'ysa_title'; titleDiv.textContent = 'Janneke van Undiemeister'; //titleDiv.style.fontFamily = 'Inter'; titleDiv.style.color = '#000000'; // Create the description div, set its class, and text content var descriptionDiv = document.createElement('div'); descriptionDiv.className = 'ysa_description'; descriptionDiv.textContent = 'Hoi! Ik sta klaar om je te helpen met vragen over je bestelling of over onze webshop.'; //descriptionDiv.style.fontFamily = 'Inter'; descriptionDiv.style.color = '#000000'; // Create the collapse icon div, set its class var collapseIconDiv = document.createElement('div'); collapseIconDiv.className = 'ysa_collapse_icon'; collapseIconDiv.style.backgroundColor = '#e85b4f'; // Append all the created elements to the popupNotificationDiv popupNotificationDiv.appendChild(chatcreatorlabelDiv1); chatcreatorlabelDiv1.addEventListener('click', function() { window.open("https://www.youshouldask.ai?utm_source=webchat&utm_medium=webclick&utm_campaign=YSA%20label", "_blank"); }); popupNotificationDiv.appendChild(personaAvatarDiv); popupNotificationDiv.appendChild(statusCircleDiv); popupNotificationDiv.appendChild(titleDiv); popupNotificationDiv.appendChild(closebuttonDiv); popupNotificationDiv.appendChild(descriptionDiv); popupNotificationDiv.appendChild(collapseIconDiv); // Toggle functionality for toggleButton toggleButton.addEventListener('click', function() { ysa_toggleDiv(); }); chatcreatorlabelDiv2.addEventListener('click', function() { window.open("https://www.youshouldask.ai?utm_source=webchat&utm_medium=webclick&utm_campaign=YSA%20label", "_blank"); }); // Finally, append the popupNotificationDiv to the document body // This assumes you want to add it directly to the body document.body.appendChild(popupNotificationDiv); // After appending to the document, add the 'visible' class to trigger the transition // Use requestAnimationFrame to ensure the transition happens after the element is painted if (ysa_windowWidth < 800) { requestAnimationFrame(() => { requestAnimationFrame(() => { ysa_toggleNotificationDiv(); }); }); } else if ( ysa_getCookie('ysa_open_status_OUqXxJ') != 'true' && (ysa_getCookie('ysa_small_popup_status_OUqXxJ') == 'true' || ysa_getCookie('ysa_small_popup_status_OUqXxJ') == '') ) { requestAnimationFrame(() => { requestAnimationFrame(() => { popupNotificationDiv.classList.add('visible'); }); }); } // Toggle functionality for toggleButton titleDiv.addEventListener('click', function() { popupNotificationDiv.classList.add('visible'); ysa_toggleDiv(); }); personaAvatarDiv.addEventListener('click', function() { popupNotificationDiv.classList.add('visible'); ysa_toggleDiv(); }); descriptionDiv.addEventListener('click', function() { popupNotificationDiv.classList.add('visible'); ysa_toggleDiv(); }); collapseIconDiv.addEventListener('click', function() { popupNotificationDiv.classList.add('visible'); ysa_toggleDiv(); }); // Toggle functionality for toggleButton closebuttonDiv.addEventListener('click', function() { ysa_toggleNotificationDiv(); }); // Assuming popupNotificationDiv is your popup element var startTouchPositionX = 0; var endTouchPositionX = 0; popupNotificationDiv.addEventListener('touchstart', function(e) { startTouchPositionX = e.touches[0].clientX; }, { passive: true }); popupNotificationDiv.addEventListener('touchend', function(e) { endTouchPositionX = e.changedTouches[0].clientX; //handleSwipeGesture(); }, { passive: true }); if (ysa_getCookie('ysa_small_popup_status_OUqXxJ') == 'false') { hidedPopupDiv.classList.add('visible'); statusCircleDivHided.classList.add('visible'); popupNotificationDiv.classList.remove('visible'); } if (ysa_getCookie('ysa_open_status_OUqXxJ') == 'true') { if (!ysa_isMobile) { var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); if (ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') != '') { var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ/' + ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') + '?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); } ysa_iframe.setAttribute('src', src); var isMinimized = popupDiv.style.height === '0px'; popupDiv.style.height = isMinimized ? '650px' : '0px'; // Toggle height popupProductDiv.style.height = isMinimized ? '650px' : '0px'; // Toggle height toggleButton.style.bottom = isMinimized ? '675px' : '25px'; // Adjust button position toggleButton.classList.add('ysa_toggle-button-maximized'); popupDiv.classList.add('maximized'); popupProductDiv.classList.add('maximized'); popupNotificationDiv.classList.remove('visible'); } ysa_storePageView(); ysa_storePageReferrer(); ysa_triggerEvent('open_chat'); } } function ysa_showTitleTextTyper() { if (ysa_getCookie('ysa_hidedPopupDivTitle_OUqXxJ') == '') { ysa_setCookie('ysa_hidedPopupDivTitle_OUqXxJ', true); hidedPopupDivTitle.classList.add('visible'); //const hidedPopupDivTitle = document.getElementById('hidedPopupDivTitle'); const text = hidedPopupDivTitle.textContent; // Get the text from the div hidedPopupDivTitle.textContent = ''; // Clear the original text // Create a span for each letter and append it text.split('').forEach((char, index) => { const span = document.createElement('span'); span.textContent = char === ' ' ? '\u00A0' : char; // Use non-breaking space for spaces span.classList.add('ysa_letter'); // Add the letter class hidedPopupDivTitle.appendChild(span); // Set a delay for the fade-in effect setTimeout(() => { span.style.opacity = 1; // Trigger the fade-in }, index * 70); // Delay increases with each letter }); // Remove the visible class after 5 seconds setTimeout(() => { hidedPopupDivTitle.classList.remove('visible'); }, 5000); // 5000ms = 5 seconds } } function ysa_toggleNotificationDiv() { hidedPopupDiv.classList.add('visible'); statusCircleDivHided.classList.add('visible'); popupNotificationDiv.classList.remove('visible'); ysa_setCookie('ysa_small_popup_status_OUqXxJ', false); } function ysa_toggleDiv(modus = 'maximized') { if (ysa_isMobile == 'disabled') // temp test { var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); if (ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') != '') { var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ/' + ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') + '?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); } window.open(src, "_blank"); } else { var isMinimized = popupDiv.style.height === '0px'; popupDiv.style.height = isMinimized ? '650px' : '0px'; // Toggle height popupProductDiv.style.height = isMinimized ? '650px' : '0px'; // Toggle height toggleButton.style.bottom = isMinimized ? '675px' : '25px'; // Adjust button position // Toggle the class for the toggle button to change the image if (isMinimized) { clearInterval(TimeshowTitleTextTyper); var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); if (ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') != '') { var src = 'https://app.youshouldask.ai/chat/k2jHff/OUqXxJ/' + ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') + '?customParameters=&cpt=' + ysa_b64EncodeUnicode(document.title) + '&sqzllocal=' + ysa_getCookie('sqzllocal'); } ysa_iframe.setAttribute('src', src); toggleButton.classList.add('ysa_toggle-button-' + modus); ysa_setCookie('ysa_open_status_OUqXxJ', true); popupDiv.classList.add(modus); popupProductDiv.classList.add(modus); document.getElementById('ysa_popup_notification').classList.remove('visible'); ysa_storePageView(); ysa_storePageReferrer(); ysa_triggerEvent('open_chat'); } else { toggleButton.classList.remove('ysa_toggle-button-maximized'); toggleButton.classList.remove('ysa_toggle-button-centered'); ysa_setCookie('ysa_open_status_OUqXxJ', false); popupDiv.classList.remove('maximized'); popupDiv.classList.remove('centered'); popupProductDiv.classList.remove('maximized'); popupProductDiv.classList.remove('centered'); document.getElementById('ysa_popup_notification').classList.add('visible'); document.getElementById('ysa_popup-product-div').innerHTML = ''; ysa_triggerEvent('view_popup'); } } } var ysa_open_popup_centered = document.querySelector('.ysa_open_popup_centered'); if (ysa_open_popup_centered) { ysa_open_popup_centered.addEventListener('click', function(event) { event.preventDefault(); ysa_toggleDiv('centered'); }); } function ysa_setCookie(cName, cValue, expDays) { let date = new Date(); date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 7)); const expires = "expires=" + date.toUTCString(); document.cookie = cName + "=" + cValue + "; " + expires + "; path=/"; } function ysa_getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for(let i = 0; i { // Remove square brackets for exact matches and create a regex or exact match condition if (pattern.startsWith('[') && pattern.endsWith(']')) { return { type: 'exact', value: pattern.slice(1, -1) }; } else { return { type: 'partial', value: pattern }; } }); } // Check if the URL matches any of the patterns function ysa_matchesPattern(url, patterns, method) { if (patterns.length === 0) { return method; // No patterns to match against implies a match } return patterns.some(pattern => { if (pattern.type === 'exact') { return url === pattern.value; } else { return url.includes(pattern.value); } }); } function ysa_storePageReferrer() { const referrer = document.referrer; const currentDomain = window.location.hostname; const referrerDomain = ''; if (referrer) { try { referrerDomain = (new URL(referrer)).hostname; } catch (e) { //console.error('Invalid referrer URL'); } } if (referrerDomain !== currentDomain) { const xhr = new XMLHttpRequest(); xhr.open("POST", "https://app.youshouldask.ai/api/store_page_source.php"); xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); const body = JSON.stringify({ pageUrl: referrer, webchat_account_id: "k2jHff", webchat_channel_id: "OUqXxJ", webchat_thread_id: ysa_getCookie('ysa_webchat_thread_id_OUqXxJ'), webchat_ip_address: "3.148.117.237", webchat_unique_id: ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') }); xhr.onload = () => { }; xhr.send(body); } } function ysa_storePageView() { const xhr = new XMLHttpRequest(); xhr.open("POST", "https://app.youshouldask.ai/api/store_page_visit.php"); xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8"); const body = JSON.stringify({ pageUrl: window.location.href, pageTitle: document.title, webchat_account_id: 'k2jHff', webchat_channel_id: 'OUqXxJ', webchat_thread_id: ysa_getCookie('ysa_webchat_thread_id_OUqXxJ'), webchat_ip_address: '3.148.117.237', webchat_unique_id: ysa_getCookie('ysa_webchat_unique_id_OUqXxJ') }); xhr.onload = () => { }; xhr.send(body); } function ysa_get_contact_data() { try { ysa_contact_data = JSON.parse(ysa_getCookie("ysa_webchat_contact_data")); if (ysa_contact_data && typeof ysa_contact_data === 'object' && Object.keys(ysa_contact_data).length > 0) { for (let key in ysa_contact_data) { if (ysa_contact_data.hasOwnProperty(key) && ysa_contact_data[key] !== "" && ysa_contact_data[key] !== "null" && ysa_contact_data[key] != null) { let elements = document.querySelectorAll(".ysa_data__" + key.toLowerCase()); elements.forEach(function(element) { var htmlstring = ysa_contact_data[key]; if (element.getAttribute('prefix') != null && element.getAttribute('prefix') != 'null') { htmlstring = element.getAttribute('prefix') + htmlstring; } if (element.getAttribute('postfix') != null && element.getAttribute('postfix') != 'null') { htmlstring = htmlstring + element.getAttribute('postfix') ; } if (htmlstring != null && htmlstring != 'null') { element.innerHTML = htmlstring; } }); } } } } catch (e) { } } window.addEventListener('message', message => { const ysa_childWindow = document.getElementById('ysa_iframe').contentWindow; if (message.source === ysa_childWindow) { if (Array.isArray(message.data)) { if (message.data[0].type === 'triggerEvent') { if (Array.isArray(message.data[0].properties)) { ysa_triggerEvent(message.data[0].event, message.data[0].properties); } else { ysa_triggerEvent(message.data[0].event); } } } else if (message.data.includes('YSA:PRODUCT:') == true) { // open product const product_data = message.data.replace('YSA:PRODUCT:', ''); // Find the div by its ID const productDiv = document.getElementById('ysa_popup-product-div'); // Prepend the new content at the beginning of the div productDiv.insertAdjacentHTML('afterbegin', '
' + product_data + '
'); // Wait a moment, then apply the 'ysa_slide_in' class to all elements without it setTimeout(function() { // Select all elements inside the div that do not have the 'ysa_slide_in' class const elements = document.querySelectorAll('#ysa_popup-product-div .ysa_product_tile:not(.ysa_slide_in)'); // Loop through each element and add the 'ysa_slide_in' class elements.forEach(function(element) { element.classList.add('ysa_slide_in'); }); }, 100); // Adjust timing if needed } else if (message.data.includes('YSA:CONTACTDATA:') == true) { // open link const json_data = message.data.replace('YSA:CONTACTDATA:', ''); ysa_contact_data = JSON.parse(json_data); ysa_setCookie("ysa_webchat_contact_data", json_data); } else if (message.data.includes('YSA:OPENLINK:') == true) { // open link window.location.href = message.data.replace('YSA:OPENLINK:', ''); } else if (message.data.includes('YSA:STOREPAGEVIEW') == true) { ysa_storePageView(); } else if (message.data.includes('YSA:THREAD_ID:') == true) { ysa_setCookie("ysa_webchat_thread_id_OUqXxJ", message.data.replace('YSA:THREAD_ID:', '')); } else if (message.data == 'close_button') { ysa_toggleDiv(); } else { ysa_setCookie("ysa_webchat_unique_id_OUqXxJ", message.data); } ysa_get_contact_data(); } }); function ysa_b64EncodeUnicode(str) { return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { return String.fromCharCode('0x' + p1); })); } // Function to check if ysa_sandbox=true is in the URL function isSandboxMode() { var modus_sandbox = false; if (ysa_getCookie("ysa_webchat_modus_sandbox_OUqXxJ") == 'true') { return true; } else { let queryString = window.location.search; let urlParams = new URLSearchParams(queryString); modus_sandbox = urlParams.get('ysa_sandbox') === 'true'; ysa_setCookie("ysa_webchat_modus_sandbox_OUqXxJ", modus_sandbox); return modus_sandbox; } } function ysa_triggerEvent(action, additionalData = {}) { if (action === undefined || action == "" || !window.dataLayer) { console.log(action); return; } window.dataLayer = window.dataLayer || []; const events = { "view_popup": { event: "view_popup_youshouldask" }, "open_chat": { event: "open_chat_youshouldask" }, "start_chat": { event: "start_chat_youshouldask" }, "send_message": { event: "send_message_youshouldask" }, "send_picture": { event: "send_picture_youshouldask" }, "select_item": { event: "select_item_youshouldask", link_url: additionalData.link_url || "", item_name: additionalData.item_name || "" } }; if (events[action]) { const eventData = { ...events[action], ...additionalData }; window.dataLayer.push(eventData); //console.log("Event triggered:", eventData); // Debugging purpose } else { //console.warn(`Unknown action: ${action}`); } } ysa_get_contact_data();