joermd commited on
Commit
9e5459b
·
verified ·
1 Parent(s): 58eb977

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +122 -238
index.html CHANGED
@@ -5,154 +5,46 @@
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>تطبيق مراجعة النصوص</title>
7
  <style>
8
- body {
9
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
10
- line-height: 1.6;
11
- margin: 0;
12
- padding: 20px;
13
- background-color: #f5f5f5;
14
- color: #333;
15
- }
16
- .container {
17
- max-width: 1200px;
18
- margin: 0 auto;
19
- background: white;
20
- padding: 20px;
21
- border-radius: 8px;
22
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
23
- }
24
- h1 {
25
- color: #2c3e50;
26
- text-align: center;
27
- margin-bottom: 30px;
28
- }
29
- .text-areas {
30
- display: flex;
31
- flex-direction: row;
32
- gap: 20px;
33
- margin-bottom: 20px;
34
- }
35
- .text-column {
36
- flex: 1;
37
- display: flex;
38
- flex-direction: column;
39
- }
40
- label {
41
- font-weight: bold;
42
- margin-bottom: 5px;
43
- color: #2c3e50;
44
- }
45
- textarea {
46
- height: 300px;
47
- padding: 10px;
48
- border: 1px solid #ddd;
49
- border-radius: 4px;
50
- resize: vertical;
51
- font-size: 16px;
52
- font-family: inherit;
53
- }
54
- button {
55
- background-color: #3498db;
56
- color: white;
57
- border: none;
58
- padding: 10px 20px;
59
- border-radius: 4px;
60
- cursor: pointer;
61
- font-size: 16px;
62
- transition: background-color 0.3s;
63
- }
64
- button:hover {
65
- background-color: #2980b9;
66
- }
67
- .result {
68
- margin-top: 30px;
69
- padding: 20px;
70
  border: 1px solid #ddd;
71
  border-radius: 4px;
72
- background-color: #f9f9f9;
73
- }
74
- .result h2 {
75
- color: #2c3e50;
76
- margin-top: 0;
77
- }
78
- .spinner {
79
- display: none;
80
- margin: 20px auto;
81
- width: 50px;
82
- height: 50px;
83
- border: 5px solid #f3f3f3;
84
- border-top: 5px solid #3498db;
85
- border-radius: 50%;
86
- animation: spin 1s linear infinite;
87
- }
88
- @keyframes spin {
89
- 0% { transform: rotate(0deg); }
90
- 100% { transform: rotate(360deg); }
91
- }
92
- .diff-highlight {
93
- display: inline;
94
- padding: 2px 0;
95
- }
96
- .diff-added {
97
- background-color: #c8e6c9;
98
- text-decoration: none;
99
  }
100
- .diff-removed {
101
- background-color: #ffcdd2;
102
- text-decoration: line-through;
103
- }
104
- .diff-changed {
105
- background-color: #fff9c4;
106
- text-decoration: none;
107
- }
108
- .error-text {
109
- background-color: #ffcdd2;
110
- color: #c62828;
111
- padding: 0 3px;
112
  border-radius: 3px;
113
- font-weight: bold;
114
- }
115
- .api-key-section {
116
- margin-bottom: 20px;
117
  }
118
- .error-message {
119
- color: #e74c3c;
120
- margin-top: 10px;
121
- }
122
- .side-by-side {
123
- display: flex;
124
- gap: 20px;
125
  margin-top: 20px;
126
- }
127
- .preview-column {
128
- flex: 1;
129
  padding: 15px;
130
- background-color: #f8f8f8;
 
131
  border-radius: 4px;
132
- border: 1px solid #ddd;
133
  }
134
- .preview-heading {
135
- margin-top: 0;
136
- padding-bottom: 10px;
137
- border-bottom: 1px solid #ddd;
138
  }
139
- .explanation-section {
140
- margin-top: 30px;
141
- padding: 15px;
142
- background-color: #e8f4fd;
143
- border-radius: 4px;
144
- border: 1px solid #cce5ff;
145
  }
146
  </style>
147
  </head>
148
  <body>
149
  <div class="container">
150
- <h1>تطبيق مراجعة النصوص</h1>
151
-
152
- <div class="api-key-section">
153
- <label for="apiKey">مفتاح API (يمكنك تعديله إذا لزم الأمر):</label>
154
- <input type="text" id="apiKey" value="sk-21a46269cd8e449f8aeb0cc129c36c33" style="width: 100%; padding: 8px; margin-top: 5px;">
155
- </div>
156
 
157
  <div class="text-areas">
158
  <div class="text-column">
@@ -170,29 +62,33 @@
170
  </div>
171
 
172
  <div id="spinner" class="spinner"></div>
173
-
174
  <div id="errorMessage" class="error-message"></div>
175
 
176
- <div id="result" class="result" style="display: none;">
177
- <h2>نتائج المقارنة:</h2>
178
- <div id="comparisonResults"></div>
179
-
180
- <div class="explanation-section">
181
- <h3>شرح الاختلافات:</h3>
182
- <div id="explanationText"></div>
183
- </div>
184
-
185
- <div class="side-by-side">
186
- <div class="preview-column">
187
- <h3 class="preview-heading">النص المصدر مع تحديد الاختلافات:</h3>
188
- <div id="sourcePreview"></div>
189
  </div>
190
- <div class="preview-column">
191
- <h3 class="preview-heading">النص الهدف مع تحديد الاختلافات:</h3>
192
- <div id="targetPreview"></div>
193
  </div>
194
  </div>
195
  </div>
 
 
 
 
 
 
 
 
 
 
 
196
  </div>
197
 
198
  <script>
@@ -202,13 +98,14 @@
202
  const apiKey = document.getElementById('apiKey').value.trim();
203
  const errorMessageElement = document.getElementById('errorMessage');
204
  const resultElement = document.getElementById('result');
205
- const comparisonResultsElement = document.getElementById('comparisonResults');
206
- const explanationTextElement = document.getElementById('explanationText');
207
- const sourcePreviewElement = document.getElementById('sourcePreview');
208
- const targetPreviewElement = document.getElementById('targetPreview');
209
  const spinner = document.getElementById('spinner');
210
 
 
211
  errorMessageElement.textContent = '';
 
 
212
 
213
  if (!sourceText || !targetText) {
214
  errorMessageElement.textContent = 'الرجاء إدخال كلا النصين للمقارنة';
@@ -225,31 +122,18 @@
225
 
226
  try {
227
  const prompt = `
228
- قارن بين النص المصدر والنص الهدف وحدد الاختلافات بينهما، بما في ذلك:
229
- 1. الأرقام المكتوبة بشكل خاطئ
230
- 2. النصوص المفقودة
231
- 3. النصوص الفاسدة أو غير المفهومة
232
- 4. النصوص المختلفة في المعنى
233
-
234
- مهم جدًا: قم بتحديد النص المختلف أو الذي يحتوي على خطأ بوضعه بين علامتي <<>> في إجابتك.
235
-
236
- قدم تحليلاً مفصلاً للاختلافات وتصنيفها حسب نوع الخطأ.
237
-
238
- بالإضافة لذلك، قم بإعداد نسخة من النص المصدر مع وضع علامة <<>> حول الأجزاء التي تختلف عن النص الهدف أو غير موجودة في النص الهدف.
239
-
240
- كذلك قم بإعداد نسخة من النص الهدف مع وضع علامة <<>> حول الأجزاء التي تختلف عن النص المصدر أو الأجزاء التي تحتوي على أخطاء.
241
-
242
- جاوب على شكل JSON مع المفاتيح التالية:
243
- - analysisResult: تحليل مفصل للاختلافات
244
- - sourceWithMarkers: النص المصدر مع علامات <<>> حول المناطق المختلفة
245
- - targetWithMarkers: النص الهدف مع علامات <<>> حول المناطق المختلفة
246
- - explanation: شرح موجز وواضح للاختلافات الرئيسية
247
-
248
  النص المصدر:
249
  ${sourceText}
250
-
251
  النص الهدف:
252
  ${targetText}
 
 
 
 
 
253
  `;
254
 
255
  const response = await fetch('https://api.deepseek.com/chat/completions', {
@@ -261,7 +145,10 @@
261
  body: JSON.stringify({
262
  model: 'deepseek-reasoner',
263
  messages: [
264
- { role: 'system', content: 'أنت مساعد مفيد متخصص في مراجعة النصوص وتحديد الاختلافات بينها بدقة عالية. يجب أن تضع الاختلافات والأخطاء بين علامتي <<>> في إجابتك وتنظم النتائج بتنسيق JSON كما هو مطلوب.' },
 
 
 
265
  { role: 'user', content: prompt }
266
  ],
267
  stream: false
@@ -273,43 +160,15 @@
273
  }
274
 
275
  const data = await response.json();
276
- const result = data.choices[0].message.content;
277
-
278
- // استخراج JSON من النتيجة
279
- let jsonResult;
280
- try {
281
- // البحث عن JSON داخل النص
282
- const jsonRegex = /{[\s\S]*}/;
283
- const match = result.match(jsonRegex);
284
-
285
- if (match) {
286
- jsonResult = JSON.parse(match[0]);
287
- } else {
288
- // إذا لم يتم العثور على JSON، عامل النص كاملاً كتحليل
289
- jsonResult = {
290
- analysisResult: result,
291
- sourceWithMarkers: sourceText,
292
- targetWithMarkers: targetText,
293
- explanation: "لم يتم توفير شرح منظم."
294
- };
295
- }
296
- } catch (e) {
297
- console.error("خطأ في تحليل JSON:", e);
298
- jsonResult = {
299
- analysisResult: result,
300
- sourceWithMarkers: sourceText,
301
- targetWithMarkers: targetText,
302
- explanation: "لم يتم توفير شرح منظم."
303
- };
304
- }
305
 
306
- // عرض النتائج
307
- comparisonResultsElement.innerHTML = formatAnalysisResult(jsonResult.analysisResult);
308
- explanationTextElement.innerHTML = formatExplanation(jsonResult.explanation);
309
- sourcePreviewElement.innerHTML = formatTextWithMarkers(jsonResult.sourceWithMarkers || sourceText);
310
- targetPreviewElement.innerHTML = formatTextWithMarkers(jsonResult.targetWithMarkers || targetText);
311
 
312
  resultElement.style.display = 'block';
 
 
313
  } catch (error) {
314
  errorMessageElement.textContent = `حدث خطأ: ${error.message}`;
315
  console.error('Error:', error);
@@ -318,31 +177,56 @@
318
  }
319
  });
320
 
321
- function formatAnalysisResult(analysisText) {
322
- // التحويل إلى HTML مع إبراز الاختلافات
323
- let formattedText = analysisText
324
- .replace(/\n/g, '<br>')
325
- .replace(/الأرقام المكتوبة بشكل خاطئ:|الأرقام غير الصحيحة:/gi, '<strong style="color: #e74c3c;">الأرقام المكتوبة بشكل خاطئ:</strong>')
326
- .replace(/النصوص المفقودة:/gi, '<strong style="color: #e74c3c;">النصوص المفقودة:</strong>')
327
- .replace(/النصوص الفاسدة:|النصوص غير المفهومة:/gi, '<strong style="color: #e74c3c;">النصوص الفاسدة:</strong>')
328
- .replace(/النصوص المختلفة في المعنى:/gi, '<strong style="color: #e74c3c;">النصوص المختلفة في المعنى:</strong>');
329
-
330
- // تظليل النصوص بين علامات <<>>
331
- formattedText = formattedText.replace(/<<(.*?)>>/g, '<span class="error-text">$1</span>');
332
-
333
- return formattedText;
334
- }
335
-
336
- function formatExplanation(explanationText) {
337
- // تطبيق نفس التنسيق على شرح الاختلافات
338
- let formattedExplanation = explanationText
339
- .replace(/\n/g, '<br>')
340
- .replace(/<<(.*?)>>/g, '<span class="error-text">$1</span>');
341
-
342
- return formattedExplanation;
343
- }
344
-
345
- function formatTextWithMarkers(markedText) {
346
- // استبدال علامات <<>> بتنسيق HTML للتظليل
347
- return markedText.replace(/<<(.*?)>>/g, '<span class="error-text">$1</span>');
348
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
  <title>تطبيق مراجعة النصوص</title>
7
  <style>
8
+ /* Existing styles remain the same */
9
+
10
+ /* Add new styles for preview and highlighting */
11
+ .preview-section {
12
+ margin-top: 20px;
13
+ padding: 15px;
14
+ background-color: #fff;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  border: 1px solid #ddd;
16
  border-radius: 4px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  }
18
+
19
+ .highlight-error {
20
+ background-color: #ffeb3b;
21
+ padding: 2px 4px;
 
 
 
 
 
 
 
 
22
  border-radius: 3px;
23
+ position: relative;
 
 
 
24
  }
25
+
26
+ .explanation-section {
 
 
 
 
 
27
  margin-top: 20px;
 
 
 
28
  padding: 15px;
29
+ background-color: #f8f9fa;
30
+ border: 1px solid #e9ecef;
31
  border-radius: 4px;
 
32
  }
33
+
34
+ .error-marker {
35
+ color: #e74c3c;
36
+ font-weight: bold;
37
  }
38
+
39
+ .preview-text {
40
+ white-space: pre-wrap;
41
+ line-height: 1.8;
 
 
42
  }
43
  </style>
44
  </head>
45
  <body>
46
  <div class="container">
47
+ <!-- Existing header and API key section remain the same -->
 
 
 
 
 
48
 
49
  <div class="text-areas">
50
  <div class="text-column">
 
62
  </div>
63
 
64
  <div id="spinner" class="spinner"></div>
 
65
  <div id="errorMessage" class="error-message"></div>
66
 
67
+ <!-- Add new preview section -->
68
+ <div id="previewSection" class="preview-section" style="display: none;">
69
+ <h2>معاينة النصوص مع تحديد الاختلافات:</h2>
70
+ <div class="text-areas">
71
+ <div class="text-column">
72
+ <h3>النص المصدر:</h3>
73
+ <div id="sourcePreview" class="preview-text"></div>
 
 
 
 
 
 
74
  </div>
75
+ <div class="text-column">
76
+ <h3>النص الهدف:</h3>
77
+ <div id="targetPreview" class="preview-text"></div>
78
  </div>
79
  </div>
80
  </div>
81
+
82
+ <!-- Add explanation section -->
83
+ <div id="explanationSection" class="explanation-section" style="display: none;">
84
+ <h2>شرح الاختلافات:</h2>
85
+ <div id="explanationContent"></div>
86
+ </div>
87
+
88
+ <div id="result" class="result" style="display: none;">
89
+ <h2>نتائج المقارنة:</h2>
90
+ <div id="comparisonResults"></div>
91
+ </div>
92
  </div>
93
 
94
  <script>
 
98
  const apiKey = document.getElementById('apiKey').value.trim();
99
  const errorMessageElement = document.getElementById('errorMessage');
100
  const resultElement = document.getElementById('result');
101
+ const previewSection = document.getElementById('previewSection');
102
+ const explanationSection = document.getElementById('explanationSection');
 
 
103
  const spinner = document.getElementById('spinner');
104
 
105
+ // Reset UI
106
  errorMessageElement.textContent = '';
107
+ previewSection.style.display = 'none';
108
+ explanationSection.style.display = 'none';
109
 
110
  if (!sourceText || !targetText) {
111
  errorMessageElement.textContent = 'الرجاء إدخال كلا النصين للمقارنة';
 
122
 
123
  try {
124
  const prompt = `
125
+ قارن بين النص المصدر والنص الهدف وحدد الاختلافات بينهما. ضع النصوص المختلفة داخل علامات <<>> وقم بشرح الاختلافات:
126
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  النص المصدر:
128
  ${sourceText}
129
+
130
  النص الهدف:
131
  ${targetText}
132
+
133
+ المطلوب:
134
+ 1. تحديد النصوص المختلفة بين المصدر والهدف
135
+ 2. وضع النصوص المختلفة داخل علامات <<>>
136
+ 3. شرح كل اختلاف وسببه
137
  `;
138
 
139
  const response = await fetch('https://api.deepseek.com/chat/completions', {
 
145
  body: JSON.stringify({
146
  model: 'deepseek-reasoner',
147
  messages: [
148
+ {
149
+ role: 'system',
150
+ content: 'أنت مساعد متخصص في مراجعة النصوص وتحديد الاختلافات بدقة عالية. قم بتحديد الاختلافات ووضعها بين علامات <<>>'
151
+ },
152
  { role: 'user', content: prompt }
153
  ],
154
  stream: false
 
160
  }
161
 
162
  const data = await response.json();
163
+ const analysisResult = data.choices[0].message.content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
+ // تحديث المعاينة والشرح
166
+ updatePreview(sourceText, targetText, analysisResult);
167
+ updateExplanation(analysisResult);
 
 
168
 
169
  resultElement.style.display = 'block';
170
+ previewSection.style.display = 'block';
171
+ explanationSection.style.display = 'block';
172
  } catch (error) {
173
  errorMessageElement.textContent = `حدث خطأ: ${error.message}`;
174
  console.error('Error:', error);
 
177
  }
178
  });
179
 
180
+ function updatePreview(sourceText, targetText, analysisResult) {
181
+ const sourcePreview = document.getElementById('sourcePreview');
182
+ const targetPreview = document.getElementById('targetPreview');
183
+
184
+ // استخراج النصوص المختلفة من نتيجة التحليل
185
+ const differences = extractDifferences(analysisResult);
186
+
187
+ // تحديث معاينة النص المصدر
188
+ let highlightedSource = sourceText;
189
+ differences.forEach(diff => {
190
+ highlightedSource = highlightedSource.replace(
191
+ diff,
192
+ `<span class="highlight-error"><<${diff}>></span>`
193
+ );
194
+ });
195
+ sourcePreview.innerHTML = highlightedSource;
196
+
197
+ // تحديث معاينة النص الهدف
198
+ let highlightedTarget = targetText;
199
+ differences.forEach(diff => {
200
+ highlightedTarget = highlightedTarget.replace(
201
+ diff,
202
+ `<span class="highlight-error"><<${diff}>></span>`
203
+ );
204
+ });
205
+ targetPreview.innerHTML = highlightedTarget;
206
+ }
207
+
208
+ function updateExplanation(analysisResult) {
209
+ const explanationContent = document.getElementById('explanationContent');
210
+
211
+ // تنسيق شرح الاختلافات
212
+ const formattedExplanation = analysisResult
213
+ .replace(/<<(.*?)>>/g, '<span class="error-marker"><<$1>></span>')
214
+ .replace(/\n/g, '<br>');
215
+
216
+ explanationContent.innerHTML = formattedExplanation;
217
+ }
218
+
219
+ function extractDifferences(analysisResult) {
220
+ const differences = [];
221
+ const regex = /<<(.*?)>>/g;
222
+ let match;
223
+
224
+ while ((match = regex.exec(analysisResult)) !== null) {
225
+ differences.push(match[1]);
226
+ }
227
+
228
+ return differences;
229
+ }
230
+ </script>
231
+ </body>
232
+ </html>