Update index.html
Browse files- index.html +183 -115
index.html
CHANGED
|
@@ -5,46 +5,122 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
<title>تطبيق مراجعة النصوص</title>
|
| 7 |
<style>
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
border: 1px solid #ddd;
|
| 16 |
border-radius: 4px;
|
|
|
|
|
|
|
|
|
|
| 17 |
}
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
| 31 |
border-radius: 4px;
|
|
|
|
| 32 |
}
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
font-weight: bold;
|
| 37 |
}
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
}
|
| 43 |
</style>
|
| 44 |
</head>
|
| 45 |
<body>
|
| 46 |
<div class="container">
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
<div class="text-areas">
|
| 50 |
<div class="text-column">
|
|
@@ -62,33 +138,20 @@
|
|
| 62 |
</div>
|
| 63 |
|
| 64 |
<div id="spinner" class="spinner"></div>
|
| 65 |
-
<div id="errorMessage" class="error-message"></div>
|
| 66 |
|
| 67 |
-
|
| 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,14 +161,14 @@
|
|
| 98 |
const apiKey = document.getElementById('apiKey').value.trim();
|
| 99 |
const errorMessageElement = document.getElementById('errorMessage');
|
| 100 |
const resultElement = document.getElementById('result');
|
| 101 |
-
const
|
| 102 |
-
const
|
|
|
|
| 103 |
const spinner = document.getElementById('spinner');
|
| 104 |
|
| 105 |
-
// Reset UI
|
| 106 |
errorMessageElement.textContent = '';
|
| 107 |
-
|
| 108 |
-
|
| 109 |
|
| 110 |
if (!sourceText || !targetText) {
|
| 111 |
errorMessageElement.textContent = 'الرجاء إدخال كلا النصين للمقارنة';
|
|
@@ -118,22 +181,24 @@
|
|
| 118 |
}
|
| 119 |
|
| 120 |
spinner.style.display = 'block';
|
| 121 |
-
resultElement.style.display = 'none';
|
| 122 |
|
| 123 |
try {
|
|
|
|
| 124 |
const prompt = `
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
2. وضع النصوص المختلفة داخل علامات <<>>
|
| 136 |
-
3. شرح كل اختلاف وسببه
|
| 137 |
`;
|
| 138 |
|
| 139 |
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
|
@@ -145,10 +210,7 @@
|
|
| 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
|
|
@@ -162,13 +224,23 @@
|
|
| 162 |
const data = await response.json();
|
| 163 |
const analysisResult = data.choices[0].message.content;
|
| 164 |
|
| 165 |
-
//
|
| 166 |
-
|
| 167 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,56 +249,52 @@
|
|
| 177 |
}
|
| 178 |
});
|
| 179 |
|
| 180 |
-
function
|
| 181 |
-
|
| 182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
|
| 184 |
-
//
|
| 185 |
-
|
| 186 |
|
| 187 |
-
//
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
diff,
|
| 192 |
-
`<span class="highlight-error"><<${diff}>></span>`
|
| 193 |
-
);
|
| 194 |
-
});
|
| 195 |
-
sourcePreview.innerHTML = highlightedSource;
|
| 196 |
|
| 197 |
-
//
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 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 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
|
|
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
}
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
-
return
|
| 229 |
}
|
| 230 |
</script>
|
| 231 |
</body>
|
| 232 |
-
</html>
|
|
|
|
| 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, .explanation {
|
| 68 |
+
margin-top: 30px;
|
| 69 |
+
padding: 20px;
|
| 70 |
+
border: 1px solid #ddd;
|
| 71 |
border-radius: 4px;
|
| 72 |
+
background-color: #f9f9f9;
|
| 73 |
}
|
| 74 |
+
.result h2, .explanation 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 |
+
}
|
| 99 |
+
.diff-removed {
|
| 100 |
+
background-color: #ffcdd2;
|
| 101 |
+
text-decoration: line-through;
|
| 102 |
+
}
|
| 103 |
+
.diff-changed {
|
| 104 |
+
background-color: #fff9c4;
|
| 105 |
+
border: 1px dashed #f39c12;
|
| 106 |
+
}
|
| 107 |
+
.api-key-section {
|
| 108 |
+
margin-bottom: 20px;
|
| 109 |
+
}
|
| 110 |
+
.error-message {
|
| 111 |
+
color: #e74c3c;
|
| 112 |
+
margin-top: 10px;
|
| 113 |
}
|
| 114 |
</style>
|
| 115 |
</head>
|
| 116 |
<body>
|
| 117 |
<div class="container">
|
| 118 |
+
<h1>تطبيق مراجعة النصوص</h1>
|
| 119 |
+
|
| 120 |
+
<div class="api-key-section">
|
| 121 |
+
<label for="apiKey">مفتاح API (يمكنك تعديله إذا لزم الأمر):</label>
|
| 122 |
+
<input type="text" id="apiKey" value="sk-21a46269cd8e449f8aeb0cc129c36c33" style="width: 100%; padding: 8px; margin-top: 5px;">
|
| 123 |
+
</div>
|
| 124 |
|
| 125 |
<div class="text-areas">
|
| 126 |
<div class="text-column">
|
|
|
|
| 138 |
</div>
|
| 139 |
|
| 140 |
<div id="spinner" class="spinner"></div>
|
|
|
|
| 141 |
|
| 142 |
+
<div id="errorMessage" class="error-message"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
+
<!-- قسم عرض نتائج المقارنة -->
|
| 145 |
<div id="result" class="result" style="display: none;">
|
| 146 |
<h2>نتائج المقارنة:</h2>
|
| 147 |
<div id="comparisonResults"></div>
|
| 148 |
</div>
|
| 149 |
+
|
| 150 |
+
<!-- قسم عرض الشرح إذا وُجد -->
|
| 151 |
+
<div id="explanation" class="explanation" style="display: none;">
|
| 152 |
+
<h2>شرح النتائج:</h2>
|
| 153 |
+
<div id="explanationContent"></div>
|
| 154 |
+
</div>
|
| 155 |
</div>
|
| 156 |
|
| 157 |
<script>
|
|
|
|
| 161 |
const apiKey = document.getElementById('apiKey').value.trim();
|
| 162 |
const errorMessageElement = document.getElementById('errorMessage');
|
| 163 |
const resultElement = document.getElementById('result');
|
| 164 |
+
const comparisonResultsElement = document.getElementById('comparisonResults');
|
| 165 |
+
const explanationElement = document.getElementById('explanation');
|
| 166 |
+
const explanationContentElement = document.getElementById('explanationContent');
|
| 167 |
const spinner = document.getElementById('spinner');
|
| 168 |
|
|
|
|
| 169 |
errorMessageElement.textContent = '';
|
| 170 |
+
resultElement.style.display = 'none';
|
| 171 |
+
explanationElement.style.display = 'none';
|
| 172 |
|
| 173 |
if (!sourceText || !targetText) {
|
| 174 |
errorMessageElement.textContent = 'الرجاء إدخال كلا النصين للمقارنة';
|
|
|
|
| 181 |
}
|
| 182 |
|
| 183 |
spinner.style.display = 'block';
|
|
|
|
| 184 |
|
| 185 |
try {
|
| 186 |
+
// تحديث الطلب ليشمل توجيه للموديل بوضع الاختلافات داخل << >>
|
| 187 |
const prompt = `
|
| 188 |
+
قارن بين النص المصدر والنص الهدف وحدد الاختلافات بينهما، بما في ذلك:
|
| 189 |
+
1. الأرقام المكتوبة بشكل خاطئ
|
| 190 |
+
2. النصوص المفقودة
|
| 191 |
+
3. النصوص الفاسدة أو غير المفهومة
|
| 192 |
+
4. النصوص المختلفة في المعنى
|
| 193 |
|
| 194 |
+
يرجى وضع النصوص المختلفة أو التي بها خطأ داخل علامتي << و >>.
|
| 195 |
+
كما يُرجى إضافة قسم "الشرح:" في نهاية التحليل يوضح أسباب الاختلاف وأهميتها.
|
| 196 |
|
| 197 |
+
النص المصدر:
|
| 198 |
+
${sourceText}
|
| 199 |
|
| 200 |
+
النص الهدف:
|
| 201 |
+
${targetText}
|
|
|
|
|
|
|
| 202 |
`;
|
| 203 |
|
| 204 |
const response = await fetch('https://api.deepseek.com/chat/completions', {
|
|
|
|
| 210 |
body: JSON.stringify({
|
| 211 |
model: 'deepseek-reasoner',
|
| 212 |
messages: [
|
| 213 |
+
{ role: 'system', content: 'أنت مساعد مفيد متخصص في مراجعة النصوص وتحديد الاختلافات بينها بدقة عالية.' },
|
|
|
|
|
|
|
|
|
|
| 214 |
{ role: 'user', content: prompt }
|
| 215 |
],
|
| 216 |
stream: false
|
|
|
|
| 224 |
const data = await response.json();
|
| 225 |
const analysisResult = data.choices[0].message.content;
|
| 226 |
|
| 227 |
+
// فصل التحليل عن قسم الشرح إن وُجد
|
| 228 |
+
let analysisPart = analysisResult;
|
| 229 |
+
let explanationPart = '';
|
| 230 |
+
if (analysisResult.includes('الشرح:')) {
|
| 231 |
+
const splitParts = analysisResult.split('الشرح:');
|
| 232 |
+
analysisPart = splitParts[0];
|
| 233 |
+
explanationPart = splitParts[1];
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
comparisonResultsElement.innerHTML = formatAnalysisResult(analysisPart, sourceText, targetText);
|
| 237 |
+
|
| 238 |
+
if(explanationPart.trim()){
|
| 239 |
+
explanationContentElement.innerHTML = explanationPart.replace(/\n/g, '<br>');
|
| 240 |
+
explanationElement.style.display = 'block';
|
| 241 |
+
}
|
| 242 |
|
| 243 |
resultElement.style.display = 'block';
|
|
|
|
|
|
|
| 244 |
} catch (error) {
|
| 245 |
errorMessageElement.textContent = `حدث خطأ: ${error.message}`;
|
| 246 |
console.error('Error:', error);
|
|
|
|
| 249 |
}
|
| 250 |
});
|
| 251 |
|
| 252 |
+
function formatAnalysisResult(analysisText, sourceText, targetText) {
|
| 253 |
+
// تحويل النص إلى HTML مع إبراز الاختلافات والتظليل:
|
| 254 |
+
let formattedText = analysisText
|
| 255 |
+
.replace(/\n/g, '<br>')
|
| 256 |
+
.replace(/الأرقام المكتوبة بشكل خاطئ:|الأرقام غير الصحيحة:/gi, '<strong style="color: #e74c3c;">الأرقام المكتوبة بشكل خاطئ:</strong>')
|
| 257 |
+
.replace(/النصوص المفقودة:/gi, '<strong style="color: #e74c3c;">النصوص المفقودة:</strong>')
|
| 258 |
+
.replace(/النصوص الفاسدة:|النصوص غير المفهومة:/gi, '<strong style="color: #e74c3c;">النصوص الفاسدة:</strong>')
|
| 259 |
+
.replace(/النصوص المختلفة في المعنى:/gi, '<strong style="color: #e74c3c;">النصوص المختلفة في المعنى:</strong>');
|
| 260 |
|
| 261 |
+
// إبراز النصوص داخل علامتي << >>
|
| 262 |
+
formattedText = formattedText.replace(/<<(.+?)>>/g, '<span class="diff-highlight diff-changed"><<$1>></span>');
|
| 263 |
|
| 264 |
+
// إبراز الاختلافات بناءً على موقعها في النص المصدر أو النص الهدف
|
| 265 |
+
formattedText = formattedText
|
| 266 |
+
.replace(/في النص المصدر: "(.*?)"/g, 'في النص المصدر: "<span class="diff-highlight diff-removed">$1</span>"')
|
| 267 |
+
.replace(/في النص الهدف: "(.*?)"/g, 'في النص الهدف: "<span class="diff-highlight diff-added">$1</span>"');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
+
// إضافة مقارنة سطرية للمعاينة
|
| 270 |
+
const sourceLines = sourceText.split('\n');
|
| 271 |
+
const targetLines = targetText.split('\n');
|
| 272 |
+
const maxLines = Math.max(sourceLines.length, targetLines.length);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
+
let visualComparison = '<h3>المقارنة السطرية:</h3><div style="display: flex; gap: 20px;">';
|
|
|
|
|
|
|
|
|
|
| 275 |
|
| 276 |
+
// عمود النص المصدر
|
| 277 |
+
visualComparison += '<div style="flex: 1;"><h4>النص المصدر:</h4><pre style="background-color: #f8f8f8; padding: 10px; border-radius: 4px; overflow-x: auto;">';
|
| 278 |
+
for (let i = 0; i < maxLines; i++) {
|
| 279 |
+
if (i < sourceLines.length) {
|
| 280 |
+
visualComparison += `<div>${i+1}. ${sourceLines[i] || ''}</div>`;
|
| 281 |
+
}
|
| 282 |
+
}
|
| 283 |
+
visualComparison += '</pre></div>';
|
| 284 |
|
| 285 |
+
// عمود النص الهدف
|
| 286 |
+
visualComparison += '<div style="flex: 1;"><h4>النص الهدف:</h4><pre style="background-color: #f8f8f8; padding: 10px; border-radius: 4px; overflow-x: auto;">';
|
| 287 |
+
for (let i = 0; i < maxLines; i++) {
|
| 288 |
+
if (i < targetLines.length) {
|
| 289 |
+
visualComparison += `<div>${i+1}. ${targetLines[i] || ''}</div>`;
|
| 290 |
+
}
|
| 291 |
}
|
| 292 |
+
visualComparison += '</pre></div>';
|
| 293 |
+
|
| 294 |
+
visualComparison += '</div>';
|
| 295 |
|
| 296 |
+
return formattedText + '<br><br>' + visualComparison;
|
| 297 |
}
|
| 298 |
</script>
|
| 299 |
</body>
|
| 300 |
+
</html>
|