joermd commited on
Commit
344a133
·
verified ·
1 Parent(s): f9e2255

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +42 -34
index.html CHANGED
@@ -255,22 +255,18 @@
255
  (function() {
256
  "use strict";
257
 
 
 
 
258
  /* برومت مختصر:
259
- قم بترجمة النص الهدف إلى لغة النص المصدر، ثم قارن بين النص المصدر والنص الهدف المترجم واخرج النصوص المفقودة فقط.
260
- إذا كانت النصوص متطابقة، اكتب [MATCH].
261
- أضف رسالة مكافأة "مكافأة: لقد نجحت في التحدي!" إذا كانت النتيجة دقيقة، أو رسالة عقوبة "عقوبة: فشلت في التحدي!" إذا كانت هناك أخطاء.
262
-
263
- النص المصدر:
264
- {source}
265
-
266
- النص الهدف:
267
- {target}
268
- */
269
- const ANALYSIS_PROMPT = `أنت نموذج DeepSeek.
270
- قم بترجمة النص الهدف إلى لغة النص المصدر، ثم قارن بين النص المصدر والنص الهدف المترجم واخرج النصوص المفقودة فقط.
271
- إذا كانت النصوص متطابقة، اكتب [MATCH].
272
- أضف "مكافأة: لقد نجحت في التحدي!" إذا كانت النتائج دقيقة، أو "عقوبة: فشلت في التحدي!" إذا كانت هناك أخطاء.
273
-
274
  النص المصدر:
275
  {source}
276
 
@@ -308,7 +304,7 @@
308
  while ((match = missingRegex.exec(analysisOutput)) !== null) {
309
  const phrase = match[1].trim();
310
  if (phrase) {
311
- const replacement = `<span class="highlight-missing">${phrase}</span>`;
312
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
313
  highlightedText = highlightedText.replace(phraseRegex, replacement);
314
  }
@@ -318,7 +314,7 @@
318
  while ((match = numberRegex.exec(analysisOutput)) !== null) {
319
  const phrase = match[1].trim();
320
  if (phrase) {
321
- const replacement = `<span class="highlight-number">${phrase}</span>`;
322
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
323
  highlightedText = highlightedText.replace(phraseRegex, replacement);
324
  }
@@ -328,7 +324,7 @@
328
  while ((match = abbrRegex.exec(analysisOutput)) !== null) {
329
  const phrase = match[1].trim();
330
  if (phrase) {
331
- const replacement = `<span class="highlight-abbreviation">${phrase}</span>`;
332
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
333
  highlightedText = highlightedText.replace(phraseRegex, replacement);
334
  }
@@ -351,7 +347,7 @@
351
  const phrase = match[1].trim();
352
  if (phrase) {
353
  const lineNum = getLineNumber(sourceText, phrase);
354
- explanations.push(`<p>${iconMissing} في السطر ${lineNum}: النص المفقود <span class="highlight-missing">${phrase}</span></p>`);
355
  }
356
  }
357
  // شرح الأرقام والتواريخ
@@ -360,7 +356,7 @@
360
  const phrase = match[1].trim();
361
  if (phrase) {
362
  const lineNum = getLineNumber(sourceText, phrase);
363
- explanations.push(`<p>${iconNumber} في السطر ${lineNum}: الرقم/التاريخ <span class="highlight-number">${phrase}</span></p>`);
364
  }
365
  }
366
  // شرح اختلاف المعنى
@@ -369,7 +365,7 @@
369
  const phrase = match[1].trim();
370
  if (phrase) {
371
  const lineNum = getLineNumber(sourceText, phrase);
372
- explanations.push(`<p>${iconMeaning} في السطر ${lineNum}: اختلاف المعنى <span class="highlight-missing">${phrase}</span></p>`);
373
  }
374
  }
375
  // شرح الاختصارات
@@ -378,16 +374,16 @@
378
  const phrase = match[1].trim();
379
  if (phrase) {
380
  const lineNum = getLineNumber(sourceText, phrase);
381
- explanations.push(`<p>${iconAbbr} في السطر ${lineNum}: الاختصار <span class="highlight-abbreviation">${phrase}</span></p>`);
382
  }
383
  }
384
 
385
  const usedSource = analysisOutput.includes('[USED_SOURCE]');
386
- let sourceNote = usedSource ? `<p><i class="fas fa-book-reader mr-1"></i> تم استخدام مصادر خارجية لشرح الاختصارات والمصطلحات.</p>`
387
  : `<p><i class="fas fa-book mr-1"></i> لم يتم استخدام مصادر خارجية.</p>`;
388
 
389
  if (explanations.length === 0) {
390
- return `<p><i class="fas fa-check-circle mr-2"></i> لا توجد اختلافات ملحوظة بين النصين.</p>` + sourceNote;
391
  }
392
  return explanations.join('') + sourceNote;
393
  };
@@ -430,7 +426,7 @@
430
  return text;
431
  };
432
 
433
- // التعامل مع رفع الملفات وإدخال النصوص
434
  const processFileInput = (inputId, targetTextAreaId, errorMsg) => {
435
  document.getElementById(inputId)?.addEventListener('change', async (event) => {
436
  const file = event.target.files[0];
@@ -490,7 +486,7 @@
490
  link.click();
491
  };
492
 
493
- // إعادة المراجعة: إعادة إخفاء النتائج للسماح بمراجعة جديدة
494
  const reReview = () => {
495
  document.getElementById('resultSection').classList.add('hidden');
496
  document.getElementById('reportSection').classList.add('hidden');
@@ -498,9 +494,10 @@
498
  document.getElementById('sourceTextReview').innerHTML = '';
499
  document.getElementById('targetTextReview').innerHTML = '';
500
  document.getElementById('explanationText').innerHTML = '';
 
501
  };
502
 
503
- // عملية التحليل والمقارنة عند الضغط على زر التحليل
504
  document.getElementById('submitBtn').addEventListener('click', async () => {
505
  const sourceText = document.getElementById('sourceText').value;
506
  const targetText = document.getElementById('targetText').value;
@@ -512,10 +509,8 @@
512
  return;
513
  }
514
 
515
- const sourceWordCount = countWords(sourceText);
516
- const targetWordCount = countWords(targetText);
517
- if (sourceWordCount !== targetWordCount) {
518
- addError(`عدد كلمات النص المصدر (${sourceWordCount}) يختلف عن النص الهدف (${targetWordCount})`, 'warning');
519
  }
520
 
521
  try {
@@ -534,7 +529,7 @@
534
  const payload = {
535
  model: "deepseek-chat",
536
  messages: [
537
- { role: "system", content: "أنت خبير في تحليل ومراجعة النصوص بدقة عالية، وتعرف كيفية ترجمة النص الهدف إلى لغة النص المصدر قبل المقارنة." },
538
  { role: "user", content: prompt }
539
  ],
540
  temperature: 0.3,
@@ -555,9 +550,22 @@
555
  throw new Error('حدث خطأ بالشبكة: ' + response.statusText);
556
  }
557
  const data = await response.json();
558
- const analysisOutput = data.choices[0].message.content.trim();
559
  progressDiv.remove();
560
 
 
 
 
 
 
 
 
 
 
 
 
 
 
561
  if (analysisOutput.includes('[MATCH]')) {
562
  const checkDiv = document.createElement('div');
563
  checkDiv.className = "p-4 rounded-xl bg-green-50 text-green-700 flex items-center";
@@ -565,7 +573,7 @@
565
  document.getElementById('errorsList').appendChild(checkDiv);
566
  document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceText);
567
  document.getElementById('targetTextReview').innerHTML = splitIntoLines(targetText);
568
- document.getElementById('explanationText').innerHTML = `<p class="text-xl">النصوص متطابقة ولا يوجد اختلاف يجب الإشارة إليه.</p>`;
569
  } else {
570
  const sourceHighlighted = applyHighlights(sourceText, analysisOutput);
571
  document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceHighlighted);
 
255
  (function() {
256
  "use strict";
257
 
258
+ // متغير لإعادة المحاولة إذا ظهر "server is busy"
259
+ let retryCount = 0;
260
+
261
  /* برومت مختصر:
262
+ - قم بترجمة النص الهدف إلى لغة النص المصدر.
263
+ - قارن بين النص المصدر والنص الهدف المترجم.
264
+ - ضع الاختلافات أو النصوص المفقودة بين أقواس ().
265
+ - أضف تعريفاً مبسطاً يوضح الفرق بين النصين.
266
+ - إذا كانت النصوص متطابقة، اكتب [MATCH].
267
+ - أضف "مكافأة: لقد نجحت في التحدي!" إذا كانت النتائج دقيقة، أو "عقوبة: فشلت في التحدي!" إذا كان هناك خطأ.
268
+ - إذا ظهر "server is busy"، أعد التحليل.
269
+
 
 
 
 
 
 
 
270
  النص المصدر:
271
  {source}
272
 
 
304
  while ((match = missingRegex.exec(analysisOutput)) !== null) {
305
  const phrase = match[1].trim();
306
  if (phrase) {
307
+ const replacement = `<span class="highlight-missing">(${phrase})</span>`;
308
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
309
  highlightedText = highlightedText.replace(phraseRegex, replacement);
310
  }
 
314
  while ((match = numberRegex.exec(analysisOutput)) !== null) {
315
  const phrase = match[1].trim();
316
  if (phrase) {
317
+ const replacement = `<span class="highlight-number">(${phrase})</span>`;
318
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
319
  highlightedText = highlightedText.replace(phraseRegex, replacement);
320
  }
 
324
  while ((match = abbrRegex.exec(analysisOutput)) !== null) {
325
  const phrase = match[1].trim();
326
  if (phrase) {
327
+ const replacement = `<span class="highlight-abbreviation">(${phrase})</span>`;
328
  const phraseRegex = new RegExp(escapeRegExp(phrase), 'g');
329
  highlightedText = highlightedText.replace(phraseRegex, replacement);
330
  }
 
347
  const phrase = match[1].trim();
348
  if (phrase) {
349
  const lineNum = getLineNumber(sourceText, phrase);
350
+ explanations.push(`<p>${iconMissing} في السطر ${lineNum}: النص المفقود (${phrase})</p>`);
351
  }
352
  }
353
  // شرح الأرقام والتواريخ
 
356
  const phrase = match[1].trim();
357
  if (phrase) {
358
  const lineNum = getLineNumber(sourceText, phrase);
359
+ explanations.push(`<p>${iconNumber} في السطر ${lineNum}: الرقم/التاريخ (${phrase})</p>`);
360
  }
361
  }
362
  // شرح اختلاف المعنى
 
365
  const phrase = match[1].trim();
366
  if (phrase) {
367
  const lineNum = getLineNumber(sourceText, phrase);
368
+ explanations.push(`<p>${iconMeaning} في السطر ${lineNum}: اختلاف المعنى (${phrase})</p>`);
369
  }
370
  }
371
  // شرح الاختصارات
 
374
  const phrase = match[1].trim();
375
  if (phrase) {
376
  const lineNum = getLineNumber(sourceText, phrase);
377
+ explanations.push(`<p>${iconAbbr} في السطر ${lineNum}: الاختصار (${phrase})</p>`);
378
  }
379
  }
380
 
381
  const usedSource = analysisOutput.includes('[USED_SOURCE]');
382
+ let sourceNote = usedSource ? `<p><i class="fas fa-book-reader mr-1"></i> تم استخدام مصادر خارجية.</p>`
383
  : `<p><i class="fas fa-book mr-1"></i> لم يتم استخدام مصادر خارجية.</p>`;
384
 
385
  if (explanations.length === 0) {
386
+ return `<p><i class="fas fa-check-circle mr-2"></i> لا توجد اختلافات ملحوظة.</p>` + sourceNote;
387
  }
388
  return explanations.join('') + sourceNote;
389
  };
 
426
  return text;
427
  };
428
 
429
+ // التعامل مع رفع الملفات
430
  const processFileInput = (inputId, targetTextAreaId, errorMsg) => {
431
  document.getElementById(inputId)?.addEventListener('change', async (event) => {
432
  const file = event.target.files[0];
 
486
  link.click();
487
  };
488
 
489
+ // إعادة المراجعة
490
  const reReview = () => {
491
  document.getElementById('resultSection').classList.add('hidden');
492
  document.getElementById('reportSection').classList.add('hidden');
 
494
  document.getElementById('sourceTextReview').innerHTML = '';
495
  document.getElementById('targetTextReview').innerHTML = '';
496
  document.getElementById('explanationText').innerHTML = '';
497
+ retryCount = 0;
498
  };
499
 
500
+ // عملية التحليل عند الضغط على زر التحليل
501
  document.getElementById('submitBtn').addEventListener('click', async () => {
502
  const sourceText = document.getElementById('sourceText').value;
503
  const targetText = document.getElementById('targetText').value;
 
509
  return;
510
  }
511
 
512
+ if (countWords(sourceText) !== countWords(targetText)) {
513
+ addError(`عدد كلمات النص المصدر يختلف عن النص الهدف`, 'warning');
 
 
514
  }
515
 
516
  try {
 
529
  const payload = {
530
  model: "deepseek-chat",
531
  messages: [
532
+ { role: "system", content: "أنت نموذج DeepSeek؛ ترجم النص الهدف إلى لغة المصدر ثم قارن بينهما واستخرج فقط الاختلافات (النصوص الناقصة) مع وضعها بين أقواس ()." },
533
  { role: "user", content: prompt }
534
  ],
535
  temperature: 0.3,
 
550
  throw new Error('حدث خطأ بالشبكة: ' + response.statusText);
551
  }
552
  const data = await response.json();
553
+ let analysisOutput = data.choices[0].message.content.trim();
554
  progressDiv.remove();
555
 
556
+ // إذا ظهر "server is busy" أعد المحاولة
557
+ if (analysisOutput.toLowerCase().includes("server is busy")) {
558
+ if (retryCount < 3) {
559
+ retryCount++;
560
+ setTimeout(() => {
561
+ document.getElementById('submitBtn').click();
562
+ }, 3000);
563
+ return;
564
+ } else {
565
+ throw new Error("الخادم مشغول. يرجى المحاولة لاحقاً.");
566
+ }
567
+ }
568
+
569
  if (analysisOutput.includes('[MATCH]')) {
570
  const checkDiv = document.createElement('div');
571
  checkDiv.className = "p-4 rounded-xl bg-green-50 text-green-700 flex items-center";
 
573
  document.getElementById('errorsList').appendChild(checkDiv);
574
  document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceText);
575
  document.getElementById('targetTextReview').innerHTML = splitIntoLines(targetText);
576
+ document.getElementById('explanationText').innerHTML = `<p class="text-xl">النصوص متطابقة ولا يوجد اختلاف.</p>`;
577
  } else {
578
  const sourceHighlighted = applyHighlights(sourceText, analysisOutput);
579
  document.getElementById('sourceTextReview').innerHTML = splitIntoLines(sourceHighlighted);