function aiImproveDescription() { const token = localStorage.getItem('indmart_token'); const user = JSON.parse(localStorage.getItem('indmart_user') || '{}'); if (!token || user.user_type !== 'paid') { const modal = document.createElement('div'); modal.style.cssText = 'position:fixed;inset:0;z-index:10000;background:rgba(0,0,0,0.6);display:flex;align-items:center;justify-content:center;'; modal.innerHTML = '

Функция для подписчиков

AI улучшает текст объявления так, чтобы оборудование продалось быстрее. Доступно на тарифе Платный.

Подключить за 2 990 ₽/мес
'; document.body.appendChild(modal); modal.addEventListener('click', e => { if(e.target===modal) modal.remove(); }); return; } const title = document.getElementById('n-title')?.value || ''; const description = document.getElementById('n-description')?.value || ''; if (!title && !description) { alert('Сначала заполните название и описание'); return; } const btn = document.getElementById('aiImproveBtn'); const status = document.getElementById('aiImproveStatus'); btn.disabled = true; btn.innerHTML = '⏳ Улучшаем...'; status.style.display = 'block'; status.textContent = 'AI улучшает текст...'; fetch('/api/ai/improve-listing', { method: 'POST', headers: {'Content-Type':'application/json','Authorization':'Bearer '+token}, body: JSON.stringify({title, description}) }) .then(r => r.json()) .then(data => { if (data.improved) { document.getElementById('n-description').value = data.improved; status.textContent = '✅ Текст улучшен'; setTimeout(() => { status.style.display = 'none'; }, 3000); } }) .catch(() => { status.textContent = '❌ Ошибка. Попробуйте ещё раз.'; }) .finally(() => { btn.disabled=false; btn.innerHTML='✨ Улучшить текст с AI PRO'; }); }