File size: 3,795 Bytes
a74b879
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// 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);
    }
  });
})();