(function() { // Генерируем уникальный ID для iframe const id = 'qupime-f6352ddcd1b3afe83a7578e429874945'; // Создаем стили const style = document.createElement('style'); style.textContent = ` .qupime-iframe { box-sizing: border-box; overflow: hidden; border: none; width: 100%; } .qupime-container { width: 100%; } `; document.head.appendChild(style); // Создаем контейнер и iframe const container = document.createElement('div'); container.className = 'qupime-container'; const iframe = document.createElement('iframe'); iframe.className = 'qupime-iframe'; iframe.id = id; iframe.src = 'https://assets.qupido.ru/embed/c/f6352ddcd1b3afe83a7578e429874945'; iframe.scrolling = 'no'; container.appendChild(iframe); // Вставляем в целевой div или создаем новый const targetDiv = document.getElementById('f6352ddcd1b3afe83a7578e429874945'); if (targetDiv) { targetDiv.appendChild(container); } else { // Если div не найден, создаем его const newDiv = document.createElement('div'); newDiv.id = 'f6352ddcd1b3afe83a7578e429874945'; newDiv.appendChild(container); document.body.appendChild(newDiv); } // Остальной JavaScript код для работы с iframe let lastScrollPosition = 0; let rafId = null; let iframeOffsetTop = null; function calculateIframeOffset() { const iframeRect = iframe.getBoundingClientRect(); const scrollY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop || 0; iframeOffsetTop = iframeRect.top + scrollY; } function sendScrollData() { if (!iframe || !iframe.contentWindow) return; if (iframeOffsetTop === null) return; const scrollY = window.scrollY || window.pageYOffset || document.documentElement.scrollTop || 0; iframe.contentWindow.postMessage({ type: 'parentScroll', scrollY: scrollY, windowHeight: window.innerHeight, iframeOffsetTop: iframeOffsetTop }, 'https://assets.qupido.ru'); } function onScroll() { if (rafId) { cancelAnimationFrame(rafId); } rafId = requestAnimationFrame(sendScrollData); } window.addEventListener('scroll', onScroll, { passive: true }); window.addEventListener('resize', () => { calculateIframeOffset(); onScroll(); }, { passive: true }); iframe.addEventListener('load', function() { setTimeout(() => { calculateIframeOffset(); sendScrollData(); }, 100); }); if (iframe.complete) { setTimeout(() => { calculateIframeOffset(); sendScrollData(); }, 100); } window.addEventListener('message', function (event) { if (event.origin !== 'https://assets.qupido.ru') return; if (!event.data) return; if (event.data.iframeHeightAuto) { iframe.style.height = 'auto'; } if (event.data.iframeHeight) { iframe.style.height = event.data.iframeHeight + 'px'; setTimeout(() => { calculateIframeOffset(); sendScrollData(); }, 50); } if (event.data.scrollTop) { const iframeRect = iframe.getBoundingClientRect(); const scrollOffset = window.scrollY || document.documentElement.scrollTop; const distanceToIframe = iframeRect.top + scrollOffset; switch (event.data.action) { case 'openPopup': { lastScrollPosition = window.scrollY || document.documentElement.scrollTop; window.scrollTo({ top: distanceToIframe, behavior: 'smooth' }); break; } case 'closePopup': { window.scrollTo({ top: lastScrollPosition, behavior: 'smooth' }); break; } case 'scrollToSaveBlock': { if (event.data.blockTop !== undefined) { const targetPosition = distanceToIframe + event.data.blockTop; window.scrollTo({ top: targetPosition, behavior: 'smooth' }); } break; } default: window.scrollTo({ top: distanceToIframe, behavior: 'smooth' }); } } }); })();