<script>(function () { const parent = document.currentScript.parentElement; if (!parent) return; const ID = 'cbs-simple-form-callback'; parent.querySelector('#' + ID)?.remove(); const root = document.createElement('div'); root.id = ID; root.className = 'cbs-simple-form'; parent.appendChild(root); const style = document.createElement('style'); style.textContent = ` #${ID}.cbs-simple-form{ position: relative; z-index: 100; pointer-events: auto; isolation: isolate; background: #063836; border: 1px solid rgba(255,255,255,.1); border-radius: .25rem; padding: 1.75rem; max-width: 36rem; width: 100%; box-sizing: border-box; color: hsla(0,0%,100%,.9); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; box-shadow: 0 16px 40px rgba(0,0,0,.45); } #${ID}.cbs-simple-form *, #${ID}.cbs-simple-form *::before, #${ID}.cbs-simple-form *::after { font-family: inherit; box-sizing: border-box; } #${ID} h2{ margin: 0 0 .5rem; font-size: 1.5rem; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; color: #fff; text-transform: uppercase; } #${ID} .form-lead{ margin: 0 0 1.4rem; font-size: .9375rem; line-height: 1.5; color: hsla(0,0%,100%,.7); } #${ID} .fields{ display: grid; gap: .65rem; } #${ID} input{ width: 100%; padding: .85rem .95rem; background: #022f2e; border: 1px solid rgba(255,255,255,.12); border-radius: .25rem; font-size: .9375rem; line-height: 1.4; color: hsla(0,0%,100%,.95); outline: none; transition: border-color .18s ease, background .18s ease; -webkit-appearance: none; appearance: none; } #${ID} input::placeholder{ color: hsla(0,0%,100%,.4); } #${ID} input:focus{ border-color: #5eead4; background: #011f1e; } #${ID} input:-webkit-autofill, #${ID} input:-webkit-autofill:focus, #${ID} input:-webkit-autofill:hover{ -webkit-text-fill-color: hsla(0,0%,100%,.95); box-shadow: inset 0 0 0 1000px #022f2e; caret-color: hsla(0,0%,100%,.95); } #${ID} input.field-invalid{ border-color: #ef4444 !important; } #${ID} .form-error{ margin: .9rem 0 0; font-size: .8125rem; line-height: 1.4; color: #fca5a5; display: none; } #${ID} .form-error.is-visible{ display: block; } #${ID} .submit{ margin-top: 1.25rem; width: 100%; padding: 14px 24px; font-size: 1rem; letter-spacing: .04em; border: none; cursor: pointer; } #${ID} .submit:disabled{ opacity: .65; cursor: progress; } #${ID} .form-foot{ margin: 1rem 0 0; font-size: .75rem; line-height: 1.45; color: hsla(0,0%,100%,.45); } #${ID} .form-foot a{ color: hsla(0,0%,100%,.7); text-decoration: underline; text-underline-offset: 2px; transition: color .18s ease; } #${ID} .form-foot a:hover{ color: #5eead4; } #${ID} .success{ padding: 2rem 1rem; text-align: center; } #${ID} .success-icon{ width: 56px; height: 56px; margin: 0 auto 1rem; border-radius: 999px; background: rgba(34,197,94,.15); display: inline-flex; align-items: center; justify-content: center; color: #22c55e; } #${ID} .success-icon svg{ width: 28px; height: 28px; } #${ID} .success h3{ margin: 0 0 .5rem; font-size: 1.25rem; font-weight: 700; color: #fff; text-transform: uppercase; letter-spacing: -.01em; } #${ID} .success p{ margin: 0; font-size: .9375rem; line-height: 1.5; color: hsla(0,0%,100%,.7); } `; root.appendChild(style); const getMeta = () => { const m = { referrer: localStorage.getItem('nooverride_referrer'), utm_source: sessionStorage.getItem('utm_source'), utm_medium: sessionStorage.getItem('utm_medium'), utm_campaign: sessionStorage.getItem('utm_campaign'), utm_content: sessionStorage.getItem('utm_content'), utm_term: sessionStorage.getItem('utm_term') }; Object.keys(m).forEach(k => (!m[k] || m[k] === 'empty' || m[k] === 'direct') && delete m[k]); return m; }; const metaText = m => { const entries = Object.entries(m); if (!entries.length) return ''; return '\n\n*Источник*:\n' + entries.map(([k, v]) => k + ': ' + v).join('\n'); }; /* Читаем выбор калькулятора из sessionStorage. Любые сбои — тихо игнорируем. */ function getCalcSelectionText() { try { if (typeof sessionStorage === 'undefined') return ''; var raw = sessionStorage.getItem('b2bsc-calc-selection'); if (!raw) return ''; var data = JSON.parse(raw); if (!data || typeof data !== 'object') return ''; var lines = []; if (typeof data.text === 'string' && data.text.trim()) { lines.push(data.text.trim()); } else { if (data.site && data.site.label) lines.push('Тип сайта: ' + data.site.label); var addons = []; if (data.domain && data.domain.label) addons.push(data.domain.label); if (data.ya && data.ya.label) addons.push(data.ya.label); if (data.gl && data.gl.label) addons.push(data.gl.label); if (addons.length) lines.push('Доп. услуги: ' + addons.join(', ')); if (data.totalText) lines.push('Итого: ' + data.totalText); else if (typeof data.total === 'number') lines.push('Итого: ' + data.total + ' ₽ / мес'); } if (!lines.length) return ''; return '\n\n*Конфигуратор тарифа*:\n' + lines.join('\n'); } catch (err) { return ''; } } /* Яндекс.Метрика: цели формы. */ function reachGoal(goal) { try { if (typeof window.ym === 'function' && window.Ya && window.Ya._metrika && window.Ya._metrika.counters) { Object.keys(window.Ya._metrika.counters).forEach(function (id) { window.ym(parseInt(id, 10), 'reachGoal', goal); }); return; } Object.keys(window).forEach(function (k) { var m = k.match(/^yaCounter(\d+)$/); if (m && window[k] && typeof window[k].reachGoal === 'function') { window[k].reachGoal(goal); } }); } catch (err) { /* metrika может быть не подключена / заблокирована */ } } const render = () => { root.innerHTML = ''; root.appendChild(style); root.insertAdjacentHTML('beforeend', ` <h2>Обратный звонок</h2> <p class="form-lead">Перезвоню вам в ближайшее время.</p> <div class="fields"> <input id="name" type="text" autocomplete="name" placeholder="Имя *"> <input id="email" type="email" autocomplete="email" placeholder="Email *"> <input id="phone" type="tel" autocomplete="tel" placeholder="Телефон *"> </div> <p class="form-error" role="alert"></p> <button class="submit cbs-accent-btn" type="button"><span>Запросить звонок</span></button> <p class="form-foot">Нажимая кнопку, вы соглашаетесь с <a href="/politika-konfidencialnosti/" target="_blank" rel="noopener">политикой обработки персональных данных</a>.</p> `); const fe = root.querySelector('.form-error'); const ni = root.querySelector('#name'); const ei = root.querySelector('#email'); const pi = root.querySelector('#phone'); const btn = root.querySelector('.submit'); function hideErr(){ fe.classList.remove('is-visible'); fe.textContent = ''; } [ni, ei, pi].forEach(n => n.addEventListener('input', () => { n.classList.remove('field-invalid'); hideErr(); })); btn.addEventListener('click', function (e) { e.preventDefault(); e.stopPropagation(); const setErr = (m) => { fe.textContent = m || ''; fe.classList.toggle('is-visible', !!m); }; root.querySelectorAll('.field-invalid').forEach(n => n.classList.remove('field-invalid')); setErr(''); const name = ni.value.trim(); const email = ei.value.trim(); const phone = pi.value.trim(); const empty = []; if (!name) { ni.classList.add('field-invalid'); empty.push('имя'); } if (!email) { ei.classList.add('field-invalid'); empty.push('email'); } if (!phone) { pi.classList.add('field-invalid'); empty.push('телефон'); } if (empty.length) { setErr('Пожалуйста, заполните: ' + empty.join(', ') + '.'); return; } reachGoal('contactFormSubmit'); const text = '✅ *Обратный звонок*\n\n' + '*Имя*: ' + name + '\n' + '*Email*: ' + email + '\n' + '*Телефон*: ' + phone + getCalcSelectionText() + metaText(getMeta()); btn.disabled = true; const origLabel = btn.querySelector('span'); if (origLabel) origLabel.textContent = 'Отправляем…'; fetch('https://form.b2b.engineering/api/createLead', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ origin: window.origin, text: text }) }).then(() => { root.innerHTML = ''; root.appendChild(style); root.insertAdjacentHTML('beforeend', ` <div class="success"> <div class="success-icon" aria-hidden="true"> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"/></svg> </div> <h3>Спасибо</h3> <p>Перезвоню вам в ближайшее время.</p> </div> `); }).catch(function (err) { console.error('Ошибка отправки заявки:', err); btn.disabled = false; if (origLabel) origLabel.textContent = 'Запросить звонок'; setErr('Не удалось отправить. Попробуйте ещё раз через минуту.'); }); }, true); }; render(); reachGoal('contactFormOpened');})();</script>