joermd commited on
Commit
d0d3666
·
verified ·
1 Parent(s): 91e5a7d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +938 -19
index.html CHANGED
@@ -1,19 +1,938 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ar" dir="rtl">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>نظام المقارنة والترجمة الخاص بشركة موندو لينجوا</title>
7
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
8
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
9
+ <style>
10
+ @keyframes gradient {
11
+ 0% { background-position: 0% 50%; }
12
+ 50% { background-position: 100% 50%; }
13
+ 100% { background-position: 0% 50%; }
14
+ }
15
+ .animate-gradient {
16
+ background-size: 200% 200%;
17
+ animation: gradient 15s ease infinite;
18
+ }
19
+ .transition-all { transition: all 0.3s ease-in-out; }
20
+ .animate-scale { transition: transform 0.2s ease-in-out; }
21
+ .animate-scale:hover { transform: scale(1.02); }
22
+ .file-drop-active { border-color: #3B82F6; background-color: rgba(59,130,246,0.1); }
23
+ .text-comparison { line-height: 1.8; white-space: pre-wrap; }
24
+ /* تمييز اختلاف الأرقام */
25
+ .highlight-number {
26
+ background-color: #FDE68A;
27
+ padding: 0 2px;
28
+ border-radius: 2px;
29
+ }
30
+ /* تمييز النصوص الناقصة */
31
+ .highlight-missing {
32
+ background-color: #BFDBFE;
33
+ padding: 0 2px;
34
+ border-radius: 2px;
35
+ }
36
+ /* تمييز اختلاف المعنى */
37
+ .highlight-meaning {
38
+ color: #EF4444;
39
+ font-weight: bold;
40
+ }
41
+ /* تقسيم شاشة المعاينة إلى جزئين */
42
+ .split-view {
43
+ display: grid;
44
+ grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
45
+ gap: 1rem;
46
+ }
47
+ .result-section {
48
+ border-top: 3px solid #E0E7FF;
49
+ margin-top: 2rem;
50
+ padding-top: 2rem;
51
+ }
52
+ /* تنسيق كل سطر مع رقم السطر */
53
+ .line-item {
54
+ display: flex;
55
+ align-items: flex-start;
56
+ margin-bottom: 0.5rem;
57
+ }
58
+ .line-number {
59
+ width: 30px;
60
+ font-weight: bold;
61
+ color: #4B5563;
62
+ flex-shrink: 0;
63
+ }
64
+ .line-text {
65
+ flex: 1;
66
+ }
67
+ /* تحسينات إضافية للواجهة */
68
+ .card-hover {
69
+ transition: all 0.3s ease;
70
+ }
71
+ .card-hover:hover {
72
+ box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.1), 0 10px 10px -5px rgba(59, 130, 246, 0.04);
73
+ transform: translateY(-2px);
74
+ }
75
+ .pulse-animation {
76
+ animation: pulse 2s infinite;
77
+ }
78
+ @keyframes pulse {
79
+ 0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
80
+ 70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
81
+ 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
82
+ }
83
+ /* زر التنزيل */
84
+ .download-btn {
85
+ background-color: #10B981;
86
+ transition: all 0.3s ease;
87
+ }
88
+ .download-btn:hover {
89
+ background-color: #059669;
90
+ transform: translateY(-2px);
91
+ }
92
+ /* تنسيق اسم الملف */
93
+ .file-name {
94
+ max-width: 200px;
95
+ overflow: hidden;
96
+ text-overflow: ellipsis;
97
+ white-space: nowrap;
98
+ }
99
+ /* تنسيق معلومات الملف */
100
+ .file-info {
101
+ background-color: #F3F4F6;
102
+ border-radius: 8px;
103
+ padding: 8px 12px;
104
+ margin-top: 8px;
105
+ font-size: 0.9rem;
106
+ }
107
+ /* تنسيق مؤشر التقدم */
108
+ .progress-bar {
109
+ width: 100%;
110
+ height: 8px;
111
+ background-color: #E5E7EB;
112
+ border-radius: 4px;
113
+ overflow: hidden;
114
+ margin-top: 8px;
115
+ }
116
+ .progress-fill {
117
+ height: 100%;
118
+ background-color: #3B82F6;
119
+ width: 0%;
120
+ transition: width 0.3s ease;
121
+ }
122
+ </style>
123
+ </head>
124
+ <body class="bg-gradient-to-br from-gray-50 via-blue-50 to-indigo-50 min-h-screen">
125
+ <div class="min-h-screen pb-12">
126
+ <!-- Header -->
127
+ <header class="bg-gradient-to-r from-blue-600 via-indigo-600 to-purple-600 animate-gradient text-white py-10 mb-10 shadow-xl">
128
+ <div class="max-w-6xl mx-auto px-4">
129
+ <h1 class="text-5xl font-bold text-center mb-4 animate-scale">نظام شركة موندو لينجوا</h1>
130
+ <p class="text-center text-xl text-blue-100 opacity-90">مقارنة وتحليل النصوص – المصدر مرجع أساسي</p>
131
+ </div>
132
+ </header>
133
+
134
+ <!-- Main Content -->
135
+ <main class="max-w-6xl mx-auto px-4">
136
+ <!-- قسم رفع الملفات -->
137
+ <div class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 hover:shadow-xl transition-all animate-scale mb-8 card-hover">
138
+ <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center border-b pb-3">
139
+ <i class="fas fa-file-upload text-blue-600 ml-2"></i> تحليل الملفات مباشرة
140
+ </h2>
141
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
142
+ <!-- ملف السورس -->
143
+ <div class="group border-2 border-dashed border-blue-200 rounded-xl p-8 text-center hover:border-blue-500 transition-colors duration-300 bg-blue-50 hover:bg-blue-100">
144
+ <label class="cursor-pointer block">
145
+ <input type="file" id="sourceFile" accept=".docx,.pdf,.txt" class="hidden">
146
+ <i class="fas fa-file-upload text-5xl text-blue-500 mb-4"></i>
147
+ <span class="text-lg text-blue-600 group-hover:text-blue-700">ملف السورس</span>
148
+ <p class="text-sm text-gray-500 mt-2">(.docx, .pdf, .txt)</p>
149
+ <div id="sourceFileInfo" class="mt-2 text-sm text-gray-600"></div>
150
+ </label>
151
+ </div>
152
+ <!-- ملف التارجت -->
153
+ <div class="group border-2 border-dashed border-purple-200 rounded-xl p-8 text-center hover:border-purple-500 transition-colors duration-300 bg-purple-50 hover:bg-purple-100">
154
+ <label class="cursor-pointer block">
155
+ <input type="file" id="targetFile" accept=".docx,.pdf,.txt" class="hidden">
156
+ <i class="fas fa-file-download text-5xl text-purple-500 mb-4"></i>
157
+ <span class="text-lg text-purple-600 group-hover:text-purple-700">ملف التارجت</span>
158
+ <p class="text-sm text-gray-500 mt-2">(.docx, .pdf, .txt)</p>
159
+ <div id="targetFileInfo" class="mt-2 text-sm text-gray-600"></div>
160
+ </label>
161
+ </div>
162
+ </div>
163
+ <div id="processStatus" class="hidden mt-4">
164
+ <div class="flex items-center justify-center space-x-3 bg-blue-100 rounded-xl p-4">
165
+ <div class="animate-spin h-8 w-8 border-4 border-blue-600 rounded-full border-t-transparent"></div>
166
+ <span class="text-lg text-blue-700">جارٍ معالجة الملفات...</span>
167
+ </div>
168
+ <div class="progress-bar mt-2">
169
+ <div id="progressFill" class="progress-fill"></div>
170
+ </div>
171
+ </div>
172
+ <!-- زر تحليل الملفات -->
173
+ <button id="analyzeFilesBtn" class="w-full mt-6 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-700 hover:to-indigo-700 text-white font-bold py-4 px-6 rounded-xl transition-all transform hover:scale-105 focus:ring-blue-200 text-lg shadow-lg hover:shadow-xl">
174
+ <div class="flex items-center justify-center">
175
+ <i class="fas fa-file-search ml-2"></i> تحليل الملفات
176
+ </div>
177
+ </button>
178
+ </div>
179
+
180
+ <!-- إدخال النصوص يدويًا -->
181
+ <div class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 hover:shadow-xl transition-all animate-scale mb-8 card-hover">
182
+ <h2 class="text-2xl font-bold mb-6 text-gray-800 flex items-center border-b pb-3">
183
+ <i class="fas fa-keyboard text-blue-600 ml-2"></i> إدخال النصوص يدوياً
184
+ </h2>
185
+ <div class="space-y-6">
186
+ <!-- النص المصدر -->
187
+ <div class="group">
188
+ <label class="block text-lg font-bold text-gray-700 mb-3 flex items-center">
189
+ <i class="fas fa-language text-blue-600 ml-2"></i> النص المصدر
190
+ </label>
191
+ <textarea id="sourceText" dir="rtl" class="w-full px-6 py-4 border-2 border-gray-200 rounded-xl focus:ring-blue-200 focus:border-blue-400 transition-all resize-none text-lg" rows="6" placeholder="اكتب النص المصدر هنا..."></textarea>
192
+ </div>
193
+ <!-- النص الهدف -->
194
+ <div class="group">
195
+ <label class="block text-lg font-bold text-gray-700 mb-3 flex items-center">
196
+ <i class="fas fa-language text-purple-600 ml-2"></i> النص الهدف
197
+ </label>
198
+ <textarea id="targetText" dir="ltr" class="w-full px-6 py-4 border-2 border-gray-200 rounded-xl focus:ring-purple-200 focus:border-purple-400 transition-all resize-none text-lg" rows="6" placeholder="اكتب النص الهدف هنا..."></textarea>
199
+ </div>
200
+ </div>
201
+ <!-- زر تحليل النصوص -->
202
+ <button id="submitBtn" class="w-full mt-6 bg-gradient-to-r from-blue-600 to-purple-600 hover:from-blue-700 hover:to-purple-700 text-white font-bold py-4 px-6 rounded-xl transition-all transform hover:scale-105 focus:ring-blue-200 text-lg shadow-lg hover:shadow-xl pulse-animation">
203
+ <div class="flex items-center justify-center">
204
+ <i class="fas fa-sync-alt ml-2"></i> تحليل النصوص
205
+ </div>
206
+ </button>
207
+ </div>
208
+
209
+ <!-- شاشة نتائج التحليل (المعاينة المقسمة) -->
210
+ <div id="resultSection" class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 hover:shadow-xl transition-all animate-scale mb-8 hidden card-hover">
211
+ <h2 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-3 flex items-center">
212
+ <i class="fas fa-search text-green-600 ml-2"></i> نتائج التحليل والمقارنة
213
+ </h2>
214
+ <!-- هنا يتم عرض الأخطاء والاختلافات فقط -->
215
+ <div id="errorsList" class="space-y-3 mb-6"></div>
216
+ <div class="result-section split-view">
217
+ <!-- عرض النص المصدر بعد التعليم مع تقسيمه إلى أسطر -->
218
+ <div>
219
+ <h4 class="text-lg font-bold text-gray-700 mb-3 flex items-center">
220
+ <i class="fas fa-file-alt text-blue-600 ml-2"></i> النص المصدر (مع التعليم)
221
+ </h4>
222
+ <div id="sourceTextReview" class="bg-blue-50 rounded-xl p-6 min-h-[200px] border-2 border-blue-100 text-comparison"></div>
223
+ </div>
224
+ <!-- عرض النص الهدف بعد التعليم مع تقسيمه إلى أسطر -->
225
+ <div>
226
+ <h4 class="text-lg font-bold text-gray-700 mb-3 flex items-center">
227
+ <i class="fas fa-file-alt text-purple-600 ml-2"></i> النص الهدف (مع التعليم)
228
+ </h4>
229
+ <div id="targetTextReview" class="bg-gray-50 rounded-xl p-6 min-h-[200px] border-2 border-gray-200 text-comparison"></div>
230
+ </div>
231
+ </div>
232
+
233
+ <!-- زر تنزيل التقرير -->
234
+ <div class="mt-8 flex justify-center">
235
+ <button id="downloadReportBtn" class="download-btn text-white font-bold py-4 px-8 rounded-xl shadow-lg flex items-center">
236
+ <i class="fas fa-download ml-2"></i> تنزيل تقرير التحليل
237
+ </button>
238
+ </div>
239
+ </div>
240
+
241
+ <!-- صندوق شرح الاختلافات -->
242
+ <div id="explanationBox" class="bg-white rounded-2xl shadow-lg p-8 border border-gray-100 hover:shadow-xl transition-all animate-scale mb-8 hidden card-hover">
243
+ <h2 class="text-2xl font-bold mb-6 text-gray-800 border-b pb-3 flex items-center">
244
+ <i class="fas fa-info-circle text-green-600 ml-2"></i> شرح الاختلافات
245
+ </h2>
246
+ <div id="explanationText" class="text-lg text-gray-700"></div>
247
+ </div>
248
+ </main>
249
+ </div>
250
+
251
+ <!-- JavaScript -->
252
+ <script>
253
+ // API URL ومفتاح API (تم التحديث لاستخدام DeepSeek API)
254
+ const API_URL = 'https://api.deepseek.com/v1/files/analyze';
255
+ const API_KEY = 'sk-15606736ed9e4aea8b7cc11a195d2b01';
256
+
257
+ // متغيرات عامة لتخزين نتائج التحليل
258
+ let analysisResults = {
259
+ sourceText: "",
260
+ targetText: "",
261
+ analysisOutput: "",
262
+ explanationHTML: "",
263
+ numDiffCount: 0,
264
+ missingDiffCount: 0,
265
+ meaningDiffCount: 0,
266
+ timestamp: "",
267
+ sourceFileName: "",
268
+ targetFileName: ""
269
+ };
270
+
271
+ // دالة لحساب عدد الكلمات
272
+ function countWords(text) {
273
+ return text.trim().split(/\s+/).filter(word => word !== "").length;
274
+ }
275
+
276
+ // دالة لمساعدة في الهروب من أحرف regex الخاصة
277
+ function escapeRegExp(string) {
278
+ return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
279
+ }
280
+
281
+ // دالة تطبيق التمييز على النص باستخدام العلامات في نتيجة التحليل
282
+ function applyHighlights(originalText, analysisOutput) {
283
+ let highlightedText = originalText;
284
+ // تمييز اختلافات الأرقام
285
+ const numberRegex = /<([^<>]+)>/g;
286
+ let match;
287
+ while ((match = numberRegex.exec(analysisOutput)) !== null) {
288
+ const phrase = match[1].trim();
289
+ if (phrase) {
290
+ const replacement = `<span class="highlight-number">${phrase}</span>`;
291
+ const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
292
+ highlightedText = highlightedText.replace(phraseRegex, replacement);
293
+ }
294
+ }
295
+ // تمييز النصوص الناقصة
296
+ const missingRegex = /__(.*?)__/g;
297
+ while ((match = missingRegex.exec(analysisOutput)) !== null) {
298
+ const phrase = match[1].trim();
299
+ if (phrase) {
300
+ const replacement = `<span class="highlight-missing">__${phrase}__</span>`;
301
+ const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
302
+ highlightedText = highlightedText.replace(phraseRegex, replacement);
303
+ }
304
+ }
305
+ // تمييز اختلاف المعنى
306
+ const meaningRegex = /\[MEANING\](.*?)\[\/MEANING\]/g;
307
+ while ((match = meaningRegex.exec(analysisOutput)) !== null) {
308
+ const phrase = match[1].trim();
309
+ if (phrase) {
310
+ const replacement = `<span class="highlight-meaning">${phrase}</span>`;
311
+ const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
312
+ highlightedText = highlightedText.replace(phraseRegex, replacement);
313
+ }
314
+ }
315
+ return highlightedText;
316
+ }
317
+
318
+ // دالة تقسيم النص إلى أسطر مع عرض رقم السطر
319
+ function splitIntoLines(text) {
320
+ const lines = text.split('\n');
321
+ let html = "";
322
+ lines.forEach((line, index) => {
323
+ html += `<div class="line-item"><span class="line-number">${index + 1}:</span> <span class="line-text">${line}</span></div>`;
324
+ });
325
+ return html;
326
+ }
327
+
328
+ // دالة للحصول على رقم السطر لظهور عبارة معينة في النص
329
+ function getLineNumber(text, substring) {
330
+ const index = text.indexOf(substring);
331
+ if (index === -1) return "غير محدد";
332
+ return text.substring(0, index).split("\n").length;
333
+ }
334
+
335
+ // دالة توليد شرح الاختلافات
336
+ function generateExplanation(sourceText, analysisOutput) {
337
+ let explanation = "";
338
+ // شرح النصوص الناقصة
339
+ const missingRegex = /__(.*?)__/g;
340
+ let match;
341
+ while ((match = missingRegex.exec(analysisOutput)) !== null) {
342
+ const phrase = match[1].trim();
343
+ if (phrase) {
344
+ const lineNum = getLineNumber(sourceText, phrase);
345
+ explanation += `<p>في السطر ${lineNum}: النص "${phrase}" مفقود في النص الهدف.</p>`;
346
+ }
347
+ }
348
+ // شرح اختلاف الأرقام
349
+ const numberRegex = /<([^<>]+)>/g;
350
+ while ((match = numberRegex.exec(analysisOutput)) !== null) {
351
+ const phrase = match[1].trim();
352
+ if (phrase) {
353
+ const lineNum = getLineNumber(sourceText, phrase);
354
+ explanation += `<p>في السطر ${lineNum}: اختلاف في الرقم "${phrase}".</p>`;
355
+ }
356
+ }
357
+ // شرح اختلاف المعنى
358
+ const meaningRegex = /\[MEANING\](.*?)\[\/MEANING\]/g;
359
+ while ((match = meaningRegex.exec(analysisOutput)) !== null) {
360
+ const phrase = match[1].trim();
361
+ if (phrase) {
362
+ const lineNum = getLineNumber(sourceText, phrase);
363
+ explanation += `<p>في السطر ${lineNum}: اختلاف في المعنى: "${phrase}".</p>`;
364
+ }
365
+ }
366
+ if (explanation === "") {
367
+ explanation = `<p>[MATCH] النصوص متطابقة تماماً.</p>`;
368
+ }
369
+ return explanation;
370
+ }
371
+
372
+ // دالة عرض الأخطاء أو الرسائل
373
+ function addError(message, type = 'error') {
374
+ const errorsList = document.getElementById('errorsList');
375
+ if (!errorsList) return;
376
+ const errorDiv = document.createElement('div');
377
+ errorDiv.className = `p-4 rounded-xl ${type === 'error' ? 'bg-red-50 text-red-700' : 'bg-yellow-50 text-yellow-700'}`;
378
+ errorDiv.innerHTML = `<div class="flex items-center">
379
+ <i class="fas fa-${type === 'error' ? 'exclamation-circle' : 'info-circle'} ml-2 text-${type === 'error' ? 'red' : 'yellow'}-500"></i>
380
+ <span>${message}</span>
381
+ </div>`;
382
+ errorsList.appendChild(errorDiv);
383
+ }
384
+
385
+ // دالة تحليل النصوص
386
+ async function analyzeTexts(sourceText, targetText) {
387
+ // مسح الرسائل السابقة وإظهار قسم النتائج
388
+ document.getElementById('errorsList').innerHTML = '';
389
+ document.getElementById('resultSection').classList.remove('hidden');
390
+ document.getElementById('explanationBox').classList.remove('hidden');
391
+
392
+ if (!sourceText || !targetText) {
393
+ addError('يرجى إدخال كلا النصين المصدر والهدف');
394
+ return;
395
+ }
396
+
397
+ try {
398
+ // عرض مؤشر التقدم أثناء انتظار الرد
399
+ const progressDiv = document.createElement('div');
400
+ progressDiv.className = "bg-blue-100 p-4 rounded-xl mb-4";
401
+ progressDiv.innerHTML = `<div class="flex items-center">
402
+ <div class="animate-spin h-6 w-6 border-4 border-blue-600 rounded-full border-t-transparent ml-3"></div>
403
+ <span>جارٍ التحليل...</span>
404
+ </div>`;
405
+ document.getElementById('errorsList').appendChild(progressDiv);
406
+
407
+ // إنشاء ملفات بلوب من النصوص المدخلة
408
+ const sourceBlob = new Blob([sourceText], { type: 'text/plain' });
409
+ const targetBlob = new Blob([targetText], { type: 'text/plain' });
410
+
411
+ // إنشاء FormData وإضافة الملفات إليها
412
+ const formData = new FormData();
413
+ formData.append('source_file', sourceBlob, 'source.txt');
414
+ formData.append('target_file', targetBlob, 'target.txt');
415
+ formData.append('analysis_type', 'text_comparison');
416
+ formData.append('instructions', `
417
+ أنت خبير في تحليل النصوص ومقارنتها. قم بمقارنة النص المصدر والنص الهدف بدقة عالية واكتشف الاختلافات التالية فقط:
418
+
419
+ 1. اختلافات الأرقام: ضع الرقم المختلف بين علامتي "<" و ">"
420
+ 2. النصوص المفقودة: إذا كان هناك نص موجود في المصدر ومفقود في الهدف، ضع النص المفقود بين "__" و "__"
421
+ 3. اختلافات المعنى: إذا كانت هناك كلمة أو عبارة تختلف في المعنى، ضعها بين [MEANING] و [/MEANING]
422
+
423
+ إذا كانت النصوص متطابقة تماماً، اكتب [MATCH] فقط.
424
+
425
+ اعتبر النص المصدر هو المرجع الأساسي للمقارنة.
426
+
427
+ ملاحظة مهمة: قم بفحص النصوص بدقة عالية. إذا كانت هناك اختلافات حتى بسيطة، يجب تحديدها. لا تكتب [MATCH] إلا إذا كانت النصوص متطابقة تماماً بنسبة 100%.
428
+ `);
429
+
430
+ // إرسال الطلب مع الملفات مباشرة
431
+ const response = await fetch(API_URL, {
432
+ method: 'POST',
433
+ headers: {
434
+ 'Authorization': 'Bearer ' + API_KEY
435
+ },
436
+ body: formData
437
+ });
438
+
439
+ if (!response.ok) {
440
+ throw new Error('حدث خطأ بالشبكة: ' + response.statusText);
441
+ }
442
+
443
+ const data = await response.json();
444
+ const analysisOutput = data.analysis_result;
445
+
446
+ progressDiv.remove();
447
+
448
+ // تخزين نتائج التحليل
449
+ analysisResults = {
450
+ sourceText: sourceText,
451
+ targetText: targetText,
452
+ analysisOutput: analysisOutput,
453
+ timestamp: new Date().toLocaleString('ar-SA'),
454
+ sourceFileName: "إدخال يدوي",
455
+ targetFileName: "إدخال يدوي"
456
+ };
457
+
458
+ if (analysisOutput.includes('[MATCH]')) {
459
+ const checkDiv = document.createElement('div');
460
+ checkDiv.className = "p-4 rounded-xl bg-green-50 text-green-700 flex items-center";
461
+ checkDiv.innerHTML = `<i class="fas fa-check-circle ml-2 text-lg"></i> <span class="text-lg">النصوص متطابقة تماماً</span>`;
462
+ document.getElementById('errorsList').appendChild(checkDiv);
463
+ document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceText);
464
+ document.getElementById('targetTextReview').innerHTML = splitIntoLines(targetText);
465
+ document.getElementById('explanationText').innerHTML = `<p>[MATCH] لا توجد اختلافات.</p>`;
466
+
467
+ analysisResults.explanationHTML = `<p>[MATCH] لا توجد اختلافات.</p>`;
468
+ analysisResults.numDiffCount = 0;
469
+ analysisResults.missingDiffCount = 0;
470
+ analysisResults.meaningDiffCount = 0;
471
+ } else {
472
+ const sourceHighlighted = applyHighlights(sourceText, analysisOutput);
473
+ const targetHighlighted = applyHighlights(targetText, analysisOutput);
474
+ // تقسيم النصوص المُظّلّة إلى أسطر مع رقم السطر
475
+ document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceHighlighted);
476
+ document.getElementById('targetTextReview').innerHTML = splitIntoLines(targetHighlighted);
477
+
478
+ // توليد شرح الاختلافات
479
+ const explanationHTML = generateExplanation(sourceText, analysisOutput);
480
+ document.getElementById('explanationText').innerHTML = explanationHTML;
481
+
482
+ // تخزين شرح الاختلافات
483
+ analysisResults.explanationHTML = explanationHTML;
484
+
485
+ // عرض ملخص الاختلافات إن وُجدت
486
+ const numDiffCount = (analysisOutput.match(/<([^<>]+)>/g) || []).length;
487
+ const missingDiffCount = (analysisOutput.match(/__(.*?)__/g) || []).length;
488
+ const meaningDiffCount = (analysisOutput.match(/\[MEANING\](.*?)\[\/MEANING\]/g) || []).length;
489
+
490
+ // تخزين عدد الاختلافات
491
+ analysisResults.numDiffCount = numDiffCount;
492
+ analysisResults.missingDiffCount = missingDiffCount;
493
+ analysisResults.meaningDiffCount = meaningDiffCount;
494
+
495
+ if (numDiffCount > 0 || missingDiffCount > 0 || meaningDiffCount > 0) {
496
+ const summaryDiv = document.createElement('div');
497
+ summaryDiv.className = "p-4 rounded-xl bg-yellow-50 text-gray-800";
498
+ let summaryText = '<div class="font-bold mb-2">ملخص الاختلافات:</div><ul class="list-disc mr-6 space-y-1">';
499
+ if (numDiffCount > 0) summaryText += `<li>اختلاف في الأرقام: ${numDiffCount}</li>`;
500
+ if (missingDiffCount > 0) summaryText += `<li>نصوص مفقودة: ${missingDiffCount}</li>`;
501
+ if (meaningDiffCount > 0) summaryText += `<li>اختلاف في المعنى: ${meaningDiffCount}</li>`;
502
+ summaryText += '</ul>';
503
+ summaryDiv.innerHTML = summaryText;
504
+ document.getElementById('errorsList').appendChild(summaryDiv);
505
+ }
506
+ }
507
+
508
+ return true;
509
+ } catch (error) {
510
+ document.getElementById('errorsList').innerHTML = '';
511
+ addError(`خطأ في التحليل: ${error.message}`);
512
+ return false;
513
+ }
514
+ }
515
+
516
+ // دالة تحليل الملفات
517
+ async function analyzeFiles(sourceFile, targetFile) {
518
+ // مسح الرسائل السابقة وإظهار قسم النتائج
519
+ document.getElementById('errorsList').innerHTML = '';
520
+ document.getElementById('resultSection').classList.remove('hidden');
521
+ document.getElementById('explanationBox').classList.remove('hidden');
522
+
523
+ if (!sourceFile || !targetFile) {
524
+ addError('يرجى تحميل كلا الملفين المصدر والهدف');
525
+ return;
526
+ }
527
+
528
+ try {
529
+ // عرض مؤشر التقدم أثناء انتظار الرد
530
+ const progressDiv = document.createElement('div');
531
+ progressDiv.className = "bg-blue-100 p-4 rounded-xl mb-4";
532
+ progressDiv.innerHTML = `<div class="flex items-center">
533
+ <div class="animate-spin h-6 w-6 border-4 border-blue-600 rounded-full border-t-transparent ml-3"></div>
534
+ <span>جارٍ تحليل الملفات...</span>
535
+ </div>`;
536
+ document.getElementById('errorsList').appendChild(progressDiv);
537
+
538
+ // تحديث شريط التقدم
539
+ document.getElementById('progressFill').style.width = '30%';
540
+
541
+ // إنشاء FormData وإضافة الملفات إليها
542
+ const formData = new FormData();
543
+ formData.append('source_file', sourceFile);
544
+ formData.append('target_file', targetFile);
545
+ formData.append('analysis_type', 'text_comparison');
546
+ formData.append('instructions', `
547
+ أنت خبير في تحليل النصوص ومقارنتها. قم بمقارنة النص المصدر والنص الهدف بدقة عالية واكتشف الاختلافات التالية فقط:
548
+
549
+ 1. اختلافات الأرقام: ضع الرقم المختلف بين علامتي "<" و ">"
550
+ 2. النصوص المفقودة: إذا كان هناك نص موجود في المصدر ومفقود في الهدف، ضع النص المفقود بين "__" و "__"
551
+ 3. اختلافات المعنى: إذا كانت هناك كلمة أو عبارة تختلف في المعنى، ضعها بين [MEANING] و [/MEANING]
552
+
553
+ إذا كانت النصوص متطابقة تماماً، اكتب [MATCH] فقط.
554
+
555
+ اعتبر النص المصدر هو المرجع الأساسي للمقارنة.
556
+
557
+ ملاحظة مهمة: قم بفحص النصوص بدقة عالية. إذا كانت هناك اختلافات حتى بسيطة، يجب تحديدها. لا تكتب [MATCH] إلا إذا كانت النصوص متطابقة تماماً بنسبة 100%.
558
+ `);
559
+
560
+ // تحديث شريط التقدم
561
+ document.getElementById('progressFill').style.width = '50%';
562
+
563
+ // إرسال الطلب مع الملفات مباشرة
564
+ const response = await fetch(API_URL, {
565
+ method: 'POST',
566
+ headers: {
567
+ 'Authorization': 'Bearer ' + API_KEY
568
+ },
569
+ body: formData
570
+ });
571
+
572
+ // تحديث شريط التقدم
573
+ document.getElementById('progressFill').style.width = '80%';
574
+
575
+ if (!response.ok) {
576
+ throw new Error('حدث خطأ بالشبكة: ' + response.statusText);
577
+ }
578
+
579
+ const data = await response.json();
580
+ const analysisOutput = data.analysis_result;
581
+ // استخراج النصوص المقارنة من النتائج
582
+ const extractedSourceText = data.extracted_source_text || "لم يتم استخراج النص المصدر";
583
+ const extractedTargetText = data.extracted_target_text || "لم يتم استخراج النص الهدف";
584
+
585
+ // تحديث شريط التقدم
586
+ document.getElementById('progressFill').style.width = '100%';
587
+ progressDiv.remove();
588
+
589
+ // تخزين نتائج التحليل
590
+ analysisResults = {
591
+ sourceText: extractedSourceText,
592
+ targetText: extractedTargetText,
593
+ analysisOutput: analysisOutput,
594
+ timestamp: new Date().toLocaleString('ar-SA'),
595
+ sourceFileName: sourceFile.name,
596
+ targetFileName: targetFile.name
597
+ };
598
+
599
+ if (analysisOutput.includes('[MATCH]')) {
600
+ const checkDiv = document.createElement('div');
601
+ checkDiv.className = "p-4 rounded-xl bg-green-50 text-green-700 flex items-center";
602
+ checkDiv.innerHTML = `<i class="fas fa-check-circle ml-2 text-lg"></i> <span class="text-lg">النصوص متطابقة تماماً</span>`;
603
+ document.getElementById('errorsList').appendChild(checkDiv);
604
+ document.getElementById('sourceTextReview').innerHTML = splitIntoLines(extractedSourceText);
605
+ document.getElementById('targetTextReview').innerHTML = splitIntoLines(extractedTargetText);
606
+ document.getElementById('explanationText').innerHTML = `<p>[MATCH] لا توجد اختلافات.</p>`;
607
+
608
+ analysisResults.explanationHTML = `<p>[MATCH] لا توجد اختلافات.</p>`;
609
+ analysisResults.numDiffCount = 0;
610
+ analysisResults.missingDiffCount = 0;
611
+ analysisResults.meaningDiffCount = 0;
612
+ } else {
613
+ const sourceHighlighted = applyHighlights(extractedSourceText, analysisOutput);
614
+ const targetHighlighted = applyHighlights(extractedTargetText, analysisOutput);
615
+ // تقسيم النصوص المُظّلّة إلى أسطر مع رقم السطر
616
+ document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceHighlighted);
617
+ document.getElementById('targetTextReview').innerHTML = splitIntoLines(targetHighlighted);
618
+
619
+ // توليد شرح الاختلافات
620
+ const explanationHTML = generateExplanation(extractedSourceText, analysisOutput);
621
+ document.getElementById('explanationText').innerHTML = explanationHTML;
622
+
623
+ // تخزين شرح الاختلافات
624
+ analysisResults.explanationHTML = explanationHTML;
625
+
626
+ // عرض ملخص الاختلافات إن وُجدت
627
+ const numDiffCount = (analysisOutput.match(/<([^<>]+)>/g) || []).length;
628
+ const missingDiffCount = (analysisOutput.match(/__(.*?)__/g) || []).length;
629
+ const meaningDiffCount = (analysisOutput.match(/\[MEANING\](.*?)\[\/MEANING\]/g) || []).length;
630
+
631
+ // تخزين عدد الاختلافات
632
+ analysisResults.numDiffCount = numDiffCount;
633
+ analysisResults.missingDiffCount = missingDiffCount;
634
+ analysisResults.meaningDiffCount = meaningDiffCount;
635
+
636
+ if (numDiffCount > 0 || missingDiffCount > 0 || meaningDiffCount > 0) {
637
+ const summaryDiv = document.createElement('div');
638
+ summaryDiv.className = "p-4 rounded-xl bg-yellow-50 text-gray-800";
639
+ let summaryText = '<div class="font-bold mb-2">ملخص الاختلافات:</div><ul class="list-disc mr-6 space-y-1">';
640
+ if (numDiffCount > 0) summaryText += `<li>اختلاف في الأرقام: ${numDiffCount}</li>`;
641
+ if (missingDiffCount > 0) summaryText += `<li>نصوص مفقودة: ${missingDiffCount}</li>`;
642
+ if (meaningDiffCount > 0) summaryText += `<li>اختلاف في المعنى: ${meaningDiffCount}</li>`;
643
+ summaryText += '</ul>';
644
+ summaryDiv.innerHTML = summaryText;
645
+ document.getElementById('errorsList').appendChild(summaryDiv);
646
+ }
647
+ }
648
+
649
+ return true;
650
+ } catch (error) {
651
+ document.getElementById('errorsList').innerHTML = '';
652
+ addError(`خطأ في تحليل الملفات: ${error.message}`);
653
+ return false;
654
+ } finally {
655
+ document.getElementById('processStatus').classList.add('hidden');
656
+ }
657
+ }
658
+
659
+ // عرض معلومات الملف بعد اختياره
660
+ document.getElementById('sourceFile')?.addEventListener('change', async (event) => {
661
+ const file = event.target.files[0];
662
+ if (!file) return;
663
+
664
+ const fileInfo = document.getElementById('sourceFileInfo');
665
+ fileInfo.innerHTML = `
666
+ <div class="file-info">
667
+ <div class="file-name"><strong>الملف:</strong> ${file.name}</div>
668
+ <div><strong>الحجم:</strong> ${(file.size / 1024).toFixed(2)} كيلوبايت</div>
669
+ <div><strong>النوع:</strong> ${file.type || 'غير محدد'}</div>
670
+ </div>
671
+ `;
672
+
673
+ // تخزين اسم الملف
674
+ analysisResults.sourceFileName = file.name;
675
+ });
676
+
677
+ document.getElementById('targetFile')?.addEventListener('change', async (event) => {
678
+ const file = event.target.files[0];
679
+ if (!file) return;
680
+
681
+ const fileInfo = document.getElementById('targetFileInfo');
682
+ fileInfo.innerHTML = `
683
+ <div class="file-info">
684
+ <div class="file-name"><strong>الملف:</strong> ${file.name}</div>
685
+ <div><strong>الحجم:</strong> ${(file.size / 1024).toFixed(2)} كيلوبايت</div>
686
+ <div><strong>النوع:</strong> ${file.type || 'غير محدد'}</div>
687
+ </div>
688
+ `;
689
+
690
+ // تخزين اسم الملف
691
+ analysisResults.targetFileName = file.name;
692
+ });
693
+
694
+ // عند الضغط على زر تحليل النصوص المدخلة يدوياً
695
+ document.getElementById('submitBtn').addEventListener('click', async () => {
696
+ const sourceText = document.getElementById('sourceText').value;
697
+ const targetText = document.getElementById('targetText').value;
698
+ await analyzeTexts(sourceText, targetText);
699
+ });
700
+
701
+ // عند الضغط على زر تحليل الملفات
702
+ document.getElementById('analyzeFilesBtn').addEventListener('click', async () => {
703
+ const sourceFileInput = document.getElementById('sourceFile');
704
+ const targetFileInput = document.getElementById('targetFile');
705
+
706
+ if (!sourceFileInput.files.length || !targetFileInput.files.length) {
707
+ addError('يرجى تحميل كلا الملفين المصدر والهدف');
708
+ document.getElementById('resultSection').classList.remove('hidden');
709
+ return;
710
+ }
711
+
712
+ document.getElementById('processStatus').classList.remove('hidden');
713
+ document.getElementById('progressFill').style.width = '0%';
714
+
715
+ try {
716
+ // تحليل الملفات مباشرة
717
+ await analyzeFiles(sourceFileInput.files[0], targetFileInput.files[0]);
718
+ } catch (error) {
719
+ console.error('Error analyzing files:', error);
720
+ document.getElementById('resultSection').classList.remove('hidden');
721
+ addError(`خطأ في تحليل الملفات: ${error.message}`);
722
+ } finally {
723
+ document.getElementById('processStatus').classList.add('hidden');
724
+ }
725
+ });
726
+
727
+ // دالة إنشاء تقرير HTML
728
+ function generateHTMLReport() {
729
+ const { sourceText, targetText, analysisOutput, explanationHTML, numDiffCount, missingDiffCount, meaningDiffCount, timestamp, sourceFileName, targetFileName } = analysisResults;
730
+
731
+ // تطبيق التمييز على النصوص
732
+ const sourceHighlighted = applyHighlights(sourceText, analysisOutput);
733
+ const targetHighlighted = applyHighlights(targetText, analysisOutput);
734
+
735
+ // إنشاء محتوى HTML للتقرير
736
+ let reportHTML = `
737
+ <!DOCTYPE html>
738
+ <html lang="ar" dir="rtl">
739
+ <head>
740
+ <meta charset="UTF-8">
741
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
742
+ <title>تقرير تحليل النصوص - موندو لينجوا</title>
743
+ <style>
744
+ body {
745
+ font-family: Arial, sans-serif;
746
+ line-height: 1.6;
747
+ color: #333;
748
+ max-width: 1200px;
749
+ margin: 0 auto;
750
+ padding: 20px;
751
+ }
752
+ h1, h2, h3 {
753
+ color: #2563EB;
754
+ }
755
+ .header {
756
+ text-align: center;
757
+ margin-bottom: 30px;
758
+ padding-bottom: 20px;
759
+ border-bottom: 2px solid #E0E7FF;
760
+ }
761
+ .summary {
762
+ background-color: #FFFBEB;
763
+ border: 1px solid #FEF3C7;
764
+ padding: 15px;
765
+ border-radius: 8px;
766
+ margin-bottom: 20px;
767
+ }
768
+ .explanation {
769
+ background-color: #F3F4F6;
770
+ padding: 15px;
771
+ border-radius: 8px;
772
+ margin-bottom: 20px;
773
+ }
774
+ .text-container {
775
+ display: grid;
776
+ grid-template-columns: 1fr 1fr;
777
+ gap: 20px;
778
+ margin-bottom: 30px;
779
+ }
780
+ .text-box {
781
+ border: 1px solid #E5E7EB;
782
+ padding: 15px;
783
+ border-radius: 8px;
784
+ background-color: #F9FAFB;
785
+ }
786
+ .highlight-number {
787
+ background-color: #FDE68A;
788
+ padding: 0 2px;
789
+ border-radius: 2px;
790
+ }
791
+ .highlight-missing {
792
+ background-color: #BFDBFE;
793
+ padding: 0 2px;
794
+ border-radius: 2px;
795
+ }
796
+ .highlight-meaning {
797
+ color: #EF4444;
798
+ font-weight: bold;
799
+ }
800
+ .footer {
801
+ text-align: center;
802
+ margin-top: 30px;
803
+ padding-top: 20px;
804
+ border-top: 2px solid #E0E7FF;
805
+ color: #6B7280;
806
+ font-size: 0.9em;
807
+ }
808
+ .line-item {
809
+ display: flex;
810
+ margin-bottom: 8px;
811
+ }
812
+ .line-number {
813
+ width: 30px;
814
+ font-weight: bold;
815
+ color: #6B7280;
816
+ }
817
+ .line-text {
818
+ flex: 1;
819
+ }
820
+ .file-info {
821
+ background-color: #EFF6FF;
822
+ padding: 10px;
823
+ border-radius: 8px;
824
+ margin-bottom: 15px;
825
+ }
826
+ </style>
827
+ </head>
828
+ <body>
829
+ <div class="header">
830
+ <h1>تقرير تحليل النصوص</h1>
831
+ <p>شركة موندو لينجوا للترجمة والتحليل اللغوي</p>
832
+ <p>تاريخ التحليل: ${timestamp}</p>
833
+ </div>
834
+
835
+ <div class="file-info">
836
+ <h2>معلومات الملفات</h2>
837
+ <p><strong>الملف المصدر:</strong> ${sourceFileName}</p>
838
+ <p><strong>الملف الهدف:</strong> ${targetFileName}</p>
839
+ </div>
840
+
841
+ <div class="summary">
842
+ <h2>ملخص التحليل</h2>
843
+ `;
844
+
845
+ if (numDiffCount === 0 && missingDiffCount === 0 && meaningDiffCount === 0) {
846
+ reportHTML += `<p>النصوص متطابقة تماماً [MATCH]</p>`;
847
+ } else {
848
+ reportHTML += `<ul>`;
849
+ if (numDiffCount > 0) reportHTML += `<li>اختلاف في الأرقام: ${numDiffCount}</li>`;
850
+ if (missingDiffCount > 0) reportHTML += `<li>نصوص مفقودة: ${missingDiffCount}</li>`;
851
+ if (meaningDiffCount > 0) reportHTML += `<li>اختلاف في المعنى: ${meaningDiffCount}</li>`;
852
+ reportHTML += `</ul>`;
853
+ }
854
+
855
+ reportHTML += `
856
+ </div>
857
+
858
+ <div class="explanation">
859
+ <h2>شرح الاختلافات</h2>
860
+ ${explanationHTML}
861
+ </div>
862
+
863
+ <h2>النصوص المقارنة</h2>
864
+ <div class="text-container">
865
+ <div class="text-box">
866
+ <h3>النص المصدر</h3>
867
+ <div>
868
+ `;
869
+
870
+ // تقسيم النص المصدر إلى أسطر مع أرقام الأسطر
871
+ const sourceLines = sourceHighlighted.split('\n');
872
+ sourceLines.forEach((line, index) => {
873
+ reportHTML += `<div class="line-item"><span class="line-number">${index + 1}:</span> <span class="line-text">${line}</span></div>`;
874
+ });
875
+
876
+ reportHTML += `
877
+ </div>
878
+ </div>
879
+ <div class="text-box">
880
+ <h3>النص الهدف</h3>
881
+ <div>
882
+ `;
883
+
884
+ // تقسيم النص الهدف إلى أسطر مع أرقام الأسطر
885
+ const targetLines = targetHighlighted.split('\n');
886
+ targetLines.forEach((line, index) => {
887
+ reportHTML += `<div class="line-item"><span class="line-number">${index + 1}:</span> <span class="line-text">${line}</span></div>`;
888
+ });
889
+
890
+ reportHTML += `
891
+ </div>
892
+ </div>
893
+ </div>
894
+
895
+ <div class="footer">
896
+ <p>© ${new Date().getFullYear()} شركة موندو لينجوا - جميع الحقوق محفوظة</p>
897
+ </div>
898
+ </body>
899
+ </html>
900
+ `;
901
+
902
+ return reportHTML;
903
+ }
904
+
905
+ // دالة تنزيل التقرير
906
+ function downloadReport() {
907
+ // التحقق من وجود نتائج تحليل
908
+ if (!analysisResults.sourceText || !analysisResults.targetText) {
909
+ alert('لا توجد نتائج تحليل متاحة للتنزيل');
910
+ return;
911
+ }
912
+
913
+ // إنشاء محتوى التقرير
914
+ const reportHTML = generateHTMLReport();
915
+
916
+ // إنشاء Blob من HTML
917
+ const blob = new Blob([reportHTML], { type: 'text/html' });
918
+
919
+ // إنشاء رابط التنزيل
920
+ const url = URL.createObjectURL(blob);
921
+ const a = document.createElement('a');
922
+ a.href = url;
923
+ a.download = `تقرير_تحليل_النصوص_${new Date().toISOString().slice(0, 10)}.html`;
924
+
925
+ // إضافة الرابط للصفحة وتنفيذ النقر عليه ثم إزالته
926
+ document.body.appendChild(a);
927
+ a.click();
928
+ document.body.removeChild(a);
929
+
930
+ // تحرير الموارد
931
+ URL.revokeObjectURL(url);
932
+ }
933
+
934
+ // إضافة مستمع حدث لزر تنزيل التقرير
935
+ document.getElementById('downloadReportBtn').addEventListener('click', downloadReport);
936
+ </script>
937
+ </body>
938
+ </html>