// Patch for index.html audit button - connects to backend API and redirects to portal (function() { const originalHandler = document.getElementById('audit-btn')?.onclick; document.getElementById('audit-btn').addEventListener('click', async function(){ const n = document.getElementById('inp-name').value.trim(); const e = document.getElementById('inp-email').value.trim(); const p = document.getElementById('inp-phone').value.trim(); if(!n || !e || !p){ this.textContent = ' يرجى ملء الحقول المطلوبة'; this.style.background = '#c0392b'; this.style.color = '#fff'; setTimeout(() => { this.textContent = 'تحليل المحركات الـ 5 ←'; this.style.background = ''; this.style.color = 'var(--p)'; }, 2500); return; } document.getElementById('st1').className = 'fstep done'; document.getElementById('st2').className = 'fstep active'; document.getElementById('form-panel').style.display = 'none'; document.getElementById('load-panel').style.display = 'block'; let m = 0; const msgs = [ ['جاري تحليل SEO Engine...', 'نفحص ترتيبك في Google والكلمات المفتاحية'], ['جاري تحليل AI Visibility...', 'نفحص ظهورك في ChatGPT وGemini'], ['جاري تحليل Ads Engine...', 'نفحص الـ Funnel والتحويلات'], ['جاري تحليل Trust Engine...', 'نفحص تقييماتك ومصداقيتك الرقمية'], ['جاري إعداد التقرير...', '5 محركات — تقريرك في طريقه إليك'] ]; const iv = setInterval(() => { m++; if(m < msgs.length){ document.getElementById('load-text').textContent = msgs[m][0]; document.getElementById('load-sub').textContent = msgs[m][1]; } }, 850); try { const ssdQ = document.getElementById('ssd-q').value.trim() || 'Company'; const res = await fetch('http://localhost:8001/api/jobs', { method: 'POST', headers: {'Content-Type': 'application/json'}, body: JSON.stringify({ url: ssdQ, org_name: n, org_url: ssdQ, max_pages: 3, runs: 1 }) }); const data = await res.json(); if(data.ok){ localStorage.setItem('clientName', n); localStorage.setItem('clientEmail', e); localStorage.setItem('clientPhone', p); localStorage.setItem('jobId', data.job_id); setTimeout(() => { clearInterval(iv); document.getElementById('st2').className = 'fstep done'; document.getElementById('st3').className = 'fstep active'; document.getElementById('load-panel').style.display = 'none'; document.getElementById('result-panel').style.display = 'block'; setTimeout(() => { window.location.href = '/portal.html?job=' + data.job_id; }, 2000); }, 4500); } else { throw new Error(data.error || 'فشل الاتصال'); } } catch(err) { clearInterval(iv); document.getElementById('load-panel').style.display = 'none'; document.getElementById('form-panel').style.display = 'block'; document.getElementById('st1').className = 'fstep'; document.getElementById('st2').className = 'fstep'; this.textContent = '❌ ' + err.message; this.style.background = '#c0392b'; this.style.color = '#fff'; setTimeout(() => { this.textContent = 'تحليل المحركات الـ 5 ←'; this.style.background = ''; this.style.color = 'var(--p)'; }, 3000); } }); })();