(function () { let token = getCookie("chatToken"); if (token === "") { setCookie("chatToken", createToken(32), 365); } })() function openModalWithIframe(iframeSrc) { // Создание элементов модального окна const modal = document.createElement('div'); const modalContent = document.createElement('div'); const closeButton = document.createElement('span') const iframeContainer = document.createElement('div'); const iframe = document.createElement('iframe'); // Настройка стилей для модального окна modal.style.display = 'block'; modal.style.position = 'fixed'; modal.style.zIndex = '1000'; modal.style.left = '0'; modal.style.top = '0'; modal.style.width = '100%'; modal.style.height = '100%'; modal.style.overflow = 'hidden'; modal.style.backgroundColor = 'rgba(0,0,0,0.4)'; closeButton.style.position = 'absolute'; closeButton.id = 'close-modal-button'; closeButton.style.top = '-40px'; closeButton.style.right = '10px'; closeButton.style.color = '#dfdfdf'; closeButton.style.fontSize = '28px'; closeButton.style.fontWeight = 'bold'; closeButton.style.cursor = 'pointer'; closeButton.innerHTML = '×'; // HTML символ крестика // Настройка стилей для содержимого модального окна modalContent.style.backgroundColor = '#fefefe'; modalContent.style.margin = '10% auto'; modalContent.style.border = '1px solid #888'; modalContent.style.borderRadius = '8px 8px'; modalContent.style.width = '800px'; // Настройка стилей для контейнера iframe iframeContainer.style.position = 'relative'; // Настройка iframe iframe.id = 'ai_lead'; iframe.src = iframeSrc; iframe.width = '100%'; iframe.height = '650px'; // Вы можете изменить высоту по своему усмотрению iframe.style.border = 'none'; iframe.style.borderRadius = '8px'; iframe.dataset.token = getCookie('chatToken') // Добавление элементов в модальное окно iframeContainer.appendChild(iframe); iframeContainer.appendChild(closeButton); modalContent.appendChild(iframeContainer); modal.appendChild(modalContent); document.body.appendChild(modal); // Закрыть модальное окно при нажатии вне его window.onclick = function (event) { if (event.target === modal) { closeModal() } }; function handleTabOrBrowserClose(event) { const confirmationMessage = 'Are you sure you want to close dialog?'; event.returnValue = confirmationMessage; closeModal() return confirmationMessage; } // window.addEventListener('beforeunload', handleTabOrBrowserClose); closeButton.onclick = function () { closeModal() }; function closeModal() { iframe.contentWindow.postMessage(JSON.stringify({ url: 'https://next-app.hire-a-robot.com/api/lead/analyze', token: getCookie("chatToken") }), '*'); modal.style.display = 'none' } window.closeModal = closeModal; window.addEventListener('message', function (event) { if (event.data === 'closeModal') { eraseCookie('chatToken') closeModal(); } }, false); } function createToken(length) { let result = ''; const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; const charactersLength = characters.length; let counter = 0; while (counter < length) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); counter += 1; } return result; } function setCookie(cname, cvalue, exdays) { const d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } function getCookie(cname) { let name = cname + "="; let ca = document.cookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; while (c.charAt(0) === ' ') { c = c.substring(1); } if (c.indexOf(name) === 0) { return c.substring(name.length, c.length); } } return ""; } function eraseCookie(name) { document.cookie = name + '=; Max-Age=-99999999;'; } // Пример вызова функции с заданным URL iframe openModalWithIframe('https://next-app.hire-a-robot.com/ai/lead-content?hash=ZFO7X5XDKDTKvLXCKskrcrnclDXoNJnz&token=' + getCookie("chatToken"));