/** * Delta Consulting — ИИ-бухгалтер виджет * Подключение: * Можно настроить через window.DeltaWidgetConfig до загрузки скрипта */ (function () { const cfg = window.DeltaWidgetConfig || {}; const ACCENT = cfg.accentColor || '#ff6b2c'; const BOT_NAME = cfg.botName || 'ИИ-бухгалтер Delta Consulting'; const POSITION = cfg.position || 'right'; // 'right' | 'left' const SYSTEM_PROMPT = `Ты — ИИ-бухгалтер компании Delta Consulting. Консультируешь предпринимателей России по бухгалтерии и налогам. Отвечай чётко, конкретно, на русском языке. Темы: УСН (6%/15%), ОСНО, патент, НПД — расчёт и сравнение; ИП vs ООО; зарплата, НДФЛ, страховые взносы; НДС; сроки отчётности ФНС/СФР/Росстат. Правила: 1. Используй конкретные цифры 2. Структурируй ответ списком или короткими абзацами 3. В конце каждого ответа добавь: "💼 Нужна помощь бухгалтера? Оставьте заявку на сайте." Данные 2026: МРОТ ~22 440 руб/мес, взносы ИП ~53 658 руб/год, НДФЛ 13% до 2,4 млн и 15% свыше.`; const QUICK = [ { icon: '📐', text: 'УСН или Патент?' }, { icon: '🏢', text: 'ИП или ООО?' }, { icon: '📅', text: 'Сроки отчётности' }, { icon: '👥', text: 'Расчёт зарплаты' }, ]; // ── Inject styles ────────────────────────────────────────── const style = document.createElement('style'); style.textContent = ` #dw-wrap * { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, 'Segoe UI', sans-serif; } #dw-wrap { position: fixed; bottom: 24px; ${POSITION}: 24px; z-index: 99999; display: flex; flex-direction: column; align-items: ${POSITION === 'right' ? 'flex-end' : 'flex-start'}; gap: 12px; } /* Bubble button */ #dw-btn { width: 58px; height: 58px; border-radius: 50%; background: ${ACCENT}; border: none; cursor: pointer; box-shadow: 0 4px 20px rgba(0,0,0,0.3); display: flex; align-items: center; justify-content: center; font-size: 24px; transition: transform 0.2s, box-shadow 0.2s; } #dw-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,0.4); } #dw-badge { position: absolute; top: -4px; ${POSITION}: -4px; width: 16px; height: 16px; border-radius: 50%; background: #34d399; border: 2px solid #fff; animation: dw-pulse 2s infinite; } @keyframes dw-pulse { 0% { box-shadow: 0 0 0 0 rgba(52,211,153,0.6); } 70% { box-shadow: 0 0 0 7px rgba(52,211,153,0); } 100% { box-shadow: 0 0 0 0 rgba(52,211,153,0); } } /* Panel */ #dw-panel { width: 360px; background: #0f131a; border: 1px solid #232a35; border-radius: 18px; overflow: hidden; box-shadow: 0 12px 48px rgba(0,0,0,0.55); display: none; flex-direction: column; max-height: 520px; animation: dw-slide-up 0.25s ease; } #dw-panel.open { display: flex; } @keyframes dw-slide-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } } /* Header */ #dw-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px; background: #0a0d12; border-bottom: 1px solid #232a35; flex-shrink: 0; } #dw-ava { width: 36px; height: 36px; border-radius: 50%; background: ${ACCENT}; display: flex; align-items: center; justify-content: center; font-size: 16px; flex-shrink: 0; } #dw-header .dw-name { font-weight: 700; font-size: 13px; color: #f2f0ea; } #dw-header .dw-status { font-size: 11px; color: #34d399; display: flex; align-items: center; gap: 4px; } #dw-header .dw-status::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: #34d399; } #dw-close { margin-left: auto; background: none; border: none; color: #8b92a0; font-size: 18px; cursor: pointer; padding: 2px; } #dw-close:hover { color: #f2f0ea; } /* Quick buttons */ #dw-quick { display: flex; gap: 7px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid #232a35; flex-shrink: 0; background: #0a0d12; } .dw-qbtn { background: #141920; border: 1px solid #232a35; color: #c0c6d0; border-radius: 100px; padding: 6px 12px; font-size: 11.5px; font-weight: 600; cursor: pointer; transition: border-color 0.15s, color 0.15s; } .dw-qbtn:hover { border-color: ${ACCENT}; color: ${ACCENT}; } /* Messages */ #dw-msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; scroll-behavior: smooth; } #dw-msgs::-webkit-scrollbar { width: 3px; } #dw-msgs::-webkit-scrollbar-thumb { background: #232a35; border-radius: 3px; } .dw-msg { display: flex; gap: 8px; max-width: 88%; } .dw-msg.user { align-self: flex-end; flex-direction: row-reverse; } .dw-msg-ava { width: 26px; height: 26px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; flex-shrink: 0; } .dw-msg.bot .dw-msg-ava { background: ${ACCENT}; } .dw-msg.user .dw-msg-ava { background: #1c2230; border: 1px solid #232a35; } .dw-bubble { background: #1c2230; border: 1px solid #232a35; border-radius: 12px; padding: 10px 13px; font-size: 13px; line-height: 1.55; color: #e8eaf0; } .dw-msg.user .dw-bubble { background: rgba(255,107,44,0.15); border-color: rgba(255,107,44,0.3); } .dw-cta { margin-top: 10px; padding: 9px 11px; background: rgba(255,107,44,0.12); border: 1px solid rgba(255,107,44,0.3); border-radius: 8px; font-size: 12px; color: #c0c6d0; } .dw-cta-btn { display: inline-block; margin-top: 7px; background: ${ACCENT}; color: #0a0d12; border: none; border-radius: 6px; font-size: 12px; font-weight: 700; padding: 7px 14px; cursor: pointer; } /* Typing */ .dw-typing { display: flex; gap: 4px; padding: 10px 13px; background: #1c2230; border: 1px solid #232a35; border-radius: 12px; width: fit-content; } .dw-typing span { width: 6px; height: 6px; background: #8b92a0; border-radius: 50%; animation: dw-dot 1.2s infinite; } .dw-typing span:nth-child(2) { animation-delay: .2s; } .dw-typing span:nth-child(3) { animation-delay: .4s; } @keyframes dw-dot { 0%,60%,100%{transform:translateY(0);opacity:.4} 30%{transform:translateY(-5px);opacity:1} } /* Input */ #dw-footer { display: flex; gap: 8px; padding: 12px 14px; border-top: 1px solid #232a35; background: #0a0d12; flex-shrink: 0; } #dw-input { flex: 1; background: #1c2230; border: 1px solid #232a35; border-radius: 10px; padding: 10px 13px; color: #f2f0ea; font-size: 13px; outline: none; resize: none; line-height: 1.4; } #dw-input::placeholder { color: #5d6573; } #dw-input:focus { border-color: ${ACCENT}; } #dw-send { width: 38px; height: 38px; flex-shrink: 0; background: ${ACCENT}; border: none; border-radius: 10px; color: #0a0d12; font-size: 15px; cursor: pointer; display: flex; align-items: center; justify-content: center; } #dw-send:disabled { opacity: 0.4; cursor: not-allowed; } /* Powered by */ #dw-powered { text-align: center; padding: 6px; font-size: 10px; color: #5d6573; background: #0a0d12; border-top: 1px solid #1a1f28; } @media (max-width: 420px) { #dw-panel { width: calc(100vw - 28px); } #dw-wrap { bottom: 16px; ${POSITION}: 14px; } } `; document.head.appendChild(style); // ── Build DOM ────────────────────────────────────────────── const wrap = document.createElement('div'); wrap.id = 'dw-wrap'; wrap.innerHTML = `
🤖
${BOT_NAME}
Онлайн — отвечает мгновенно
${QUICK.map(q => ``).join('')}
Delta Consulting · ИИ-ассистент на базе Claude
`; document.body.appendChild(wrap); // ── State ────────────────────────────────────────────────── let history = []; let busy = false; let opened = false; const panel = document.getElementById('dw-panel'); const btn = document.getElementById('dw-btn'); const msgs = document.getElementById('dw-msgs'); const input = document.getElementById('dw-input'); const sendBtn = document.getElementById('dw-send'); function toggle() { opened = !opened; panel.classList.toggle('open', opened); btn.innerHTML = opened ? '✕' : '🤖'; if (opened && msgs.children.length === 0) addWelcome(); if (opened) input.focus(); } function addWelcome() { addMsg('Привет! Я ИИ-бухгалтер Delta Consulting 👋 Задайте вопрос по налогам, отчётности или выбору системы налогообложения — отвечу бесплатно.', false); } function addMsg(text, isUser, cta = false) { const div = document.createElement('div'); div.className = `dw-msg ${isUser ? 'user' : 'bot'}`; const clean = text.replace(/💼 Нужна помощь.*$/s, '').trim().replace(/\n/g, '
'); const ctaHtml = cta ? `
💼 Нужна помощь бухгалтера?
` : ''; div.innerHTML = `
${isUser ? '👤' : '🤖'}
${clean}${ctaHtml}
`; msgs.appendChild(div); msgs.scrollTop = msgs.scrollHeight; } function showTyping() { const d = document.createElement('div'); d.className = 'dw-msg bot'; d.id = 'dw-typing'; d.innerHTML = `
🤖
`; msgs.appendChild(d); msgs.scrollTop = msgs.scrollHeight; } function hideTyping() { const e = document.getElementById('dw-typing'); if (e) e.remove(); } async function send(override) { if (busy) return; const text = override || input.value.trim(); if (!text) return; if (!override) { input.value = ''; input.style.height = 'auto'; } addMsg(text, true); history.push({ role: 'user', content: text }); busy = true; sendBtn.disabled = true; showTyping(); try { const res = await fetch('https://api.anthropic.com/v1/messages', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ model: 'claude-sonnet-4-6', max_tokens: 900, system: SYSTEM_PROMPT, messages: history }) }); const data = await res.json(); const reply = data.content?.[0]?.text || 'Ошибка. Попробуйте ещё раз.'; history.push({ role: 'assistant', content: reply }); hideTyping(); addMsg(reply, false, true); } catch (_) { hideTyping(); addMsg('Ошибка подключения. Проверьте интернет и попробуйте снова.', false); } busy = false; sendBtn.disabled = false; } // ── Events ───────────────────────────────────────────────── btn.addEventListener('click', toggle); document.getElementById('dw-close').addEventListener('click', toggle); sendBtn.addEventListener('click', () => send()); input.addEventListener('keydown', e => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); send(); } }); input.addEventListener('input', function () { this.style.height = 'auto'; this.style.height = Math.min(this.scrollHeight, 100) + 'px'; }); document.querySelectorAll('.dw-qbtn').forEach(b => { const map = { 'УСН или Патент?': 'Сравни УСН 6%, УСН 15% и патент для ИП с доходом 3 млн рублей в год', 'ИП или ООО?': 'Что лучше: ИП или ООО для небольшого бизнеса?', 'Сроки отчётности':'Какие сроки сдачи отчётности для ИП на УСН в 2026 году?', 'Расчёт зарплаты': 'Как рассчитать зарплату, НДФЛ и страховые взносы для сотрудника с окладом 60000 рублей?', }; b.addEventListener('click', () => { if (!opened) toggle(); send(map[b.textContent.replace(/^[^\w]+/, '').trim()] || b.textContent.trim()); }); }); })();
Made on
Tilda