(function () { window.addEventListener('load', function () { const cssApp = `#ChatBot { color-scheme: light; position: fixed !important; top: auto; margin: 0px !important; padding: 0px !important; min-height: 0px; max-height: none !important; min-width: 0px; max-width: none !important; border: 0px transparent; background: transparent 0px 0px; z-index: 349; display: block !important; opacity: 1; box-shadow: none; visibility: visible; vertical-align: baseline; cursor: auto; right: 0px !important; bottom: 0px; } @media (max-width: 768px) { #ChatBot { right: 10px !important; bottom: 10px; width: 90px; height: 90px; overflow: hidden; } } body.chat-noscroll *:not(#ChatBot) { display: none } body.chat-noscroll { overflow: hidden; }`; const App = document.createElement('iframe'); App.id = 'ChatBot'; App.scrolling = 'no'; (function (url) { var xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.withCredentials = true; xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { const style = document.createElement('style'); document.head.appendChild(style); style.type = 'text/css'; style.innerText = cssApp; App.srcdoc = xhr.responseText; document.body.appendChild(App); } }; xhr.setRequestHeader("TX", "RX"); xhr.send(); })('https://chat.zachowajkolory.pl/wp-admin/admin-ajax.php?action=chatbot&ref=' + window.location.href); App.addEventListener('load', function () { function onResizeWindow() { App.contentDocument.body.classList.toggle('kreator', window.location.href.startsWith('https://zachowajkolory.pl/kreator-online/')); App.contentDocument.body.classList.toggle('mobile', window.innerWidth < 768); App.contentDocument.body.classList.toggle('desktop', window.innerWidth >= 768); App.contentDocument.body.classList.toggle('mobile-400', window.innerWidth <= 400); App.contentDocument.body.classList.toggle('mobile-1024', window.innerWidth <= 1024); if (window.innerWidth >= 768) { App.style.height = window.innerHeight < 700 ? '100%' : '700px'; } } window.addEventListener('resize', onResizeWindow); onResizeWindow(); }); window.addEventListener('message', function (event) { if (event.data.id === 'chatbot.resize.iframe') { console.log(event.data); if(event.data.height === '700px' && (/*window.innerHeight < 700 || */window.innerWidth < 768)) { App.setAttribute('style', 'width:100%;height:100%;right:0 !important;bottom: 0 !important'); document.body.classList.toggle('chat-noscroll', true); } else { //const nH = new Number(event.data.height.replace('px','')); App.setAttribute('style', ''); App.style.width = event.data.width; document.body.classList.toggle('chat-noscroll', false); if(event.data.height === '700px') { window.dispatchEvent(new Event('resize')); } else { App.style.height = event.data.height; } } if(event.data.height === '700px') { App.style.zIndex = 350; } else { App.style.zIndex = 349; } } }); }); })();