Update index.html
Browse files- index.html +334 -175
index.html
CHANGED
@@ -5,7 +5,6 @@
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Speedy Chat</title>
|
7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
8 |
-
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
|
9 |
<style>
|
10 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@100;200;300;400;500;600;700&display=swap');
|
11 |
@import url('https://fonts.googleapis.com/css2?family=Noto+Kufi+Arabic:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
@@ -51,52 +50,128 @@
|
|
51 |
|
52 |
.dark-mode .bot-message {
|
53 |
background-color: #363636;
|
|
|
54 |
}
|
55 |
|
56 |
-
.
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
}
|
61 |
|
62 |
-
.
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
border-radius: 0.375rem;
|
65 |
-
font-size: 0.875rem;
|
66 |
-
display: flex;
|
67 |
-
align-items: center;
|
68 |
-
gap: 0.25rem;
|
69 |
transition: all 0.2s;
|
|
|
|
|
|
|
|
|
70 |
color: #6B7280;
|
|
|
71 |
}
|
72 |
|
73 |
-
.
|
74 |
-
background-color: #
|
75 |
}
|
76 |
|
77 |
-
.
|
78 |
-
|
|
|
|
|
|
|
|
|
79 |
}
|
80 |
|
81 |
-
.stop-
|
82 |
-
|
83 |
-
|
84 |
-
color: white;
|
85 |
-
padding: 0.5rem 1rem;
|
86 |
-
border-radius: 0.375rem;
|
87 |
-
font-weight: 500;
|
88 |
-
transition: all 0.2s;
|
89 |
}
|
90 |
|
91 |
-
.
|
92 |
-
|
|
|
|
|
93 |
}
|
94 |
|
95 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
</style>
|
97 |
</head>
|
98 |
<body class="text-lg light-mode">
|
99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
<main class="pt-24 pb-24">
|
102 |
<div class="max-w-3xl mx-auto px-4">
|
@@ -120,179 +195,263 @@
|
|
120 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
121 |
</svg>
|
122 |
</button>
|
123 |
-
<
|
124 |
-
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
</div>
|
128 |
</div>
|
129 |
</div>
|
130 |
</footer>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
-
|
133 |
-
|
|
|
|
|
|
|
134 |
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
</
|
152 |
-
<div class="message-actions justify-end">
|
153 |
-
<button class="message-action-button">
|
154 |
-
<i class="far fa-thumbs-up"></i>
|
155 |
-
أعجبني
|
156 |
-
</button>
|
157 |
-
<button class="message-action-button">
|
158 |
-
<i class="far fa-thumbs-down"></i>
|
159 |
-
لم يعجبني
|
160 |
-
</button>
|
161 |
-
</div>
|
162 |
</div>
|
163 |
-
|
164 |
-
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
<button class="message-action-button copy-message">
|
181 |
-
<i class="far fa-copy"></i>
|
182 |
نسخ
|
183 |
</button>
|
184 |
-
<button class="
|
185 |
-
<
|
|
|
|
|
186 |
إعادة التوليد
|
187 |
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
</div>
|
189 |
</div>
|
190 |
-
|
191 |
-
|
|
|
|
|
192 |
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
let actualMessage = message;
|
207 |
-
|
208 |
-
if (currentStyle === 'short') {
|
209 |
-
actualMessage = 'اعطني رد باختصار وسرعة: ' + message;
|
210 |
-
} else if (currentStyle === 'long') {
|
211 |
-
actualMessage = 'اعطني رد مفصل وموسع: ' + message;
|
212 |
-
}
|
213 |
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
human: actualMessage,
|
233 |
-
assistant: data.response
|
234 |
-
});
|
235 |
-
} catch (error) {
|
236 |
-
document.getElementById(messageId).textContent = 'عذراً، حدث خطأ في المعالجة.';
|
237 |
-
} finally {
|
238 |
-
isGenerating = false;
|
239 |
-
stopGenerating.style.display = 'none';
|
240 |
-
}
|
241 |
-
scrollToBottom();
|
242 |
-
}
|
243 |
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
257 |
});
|
258 |
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
|
|
|
|
263 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
264 |
|
265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
|
|
|
|
272 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
|
|
|
|
278 |
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
|
|
|
|
|
|
|
|
|
|
291 |
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
</body>
|
298 |
</html>
|
|
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
<title>Speedy Chat</title>
|
7 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/tailwind.min.css" rel="stylesheet">
|
|
|
8 |
<style>
|
9 |
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@100;200;300;400;500;600;700&display=swap');
|
10 |
@import url('https://fonts.googleapis.com/css2?family=Noto+Kufi+Arabic:wght@100;200;300;400;500;600;700;800;900&display=swap');
|
|
|
50 |
|
51 |
.dark-mode .bot-message {
|
52 |
background-color: #363636;
|
53 |
+
color: #e5e5e5;
|
54 |
}
|
55 |
|
56 |
+
.dark-mode .action-button {
|
57 |
+
color: #e5e5e5;
|
58 |
+
background-color: #404040;
|
59 |
+
}
|
60 |
+
|
61 |
+
.message-input:focus {
|
62 |
+
outline: none;
|
63 |
+
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
|
64 |
}
|
65 |
|
66 |
+
.welcome-text {
|
67 |
+
font-family: 'Noto Kufi Arabic', sans-serif;
|
68 |
+
font-size: 2rem;
|
69 |
+
font-weight: 700;
|
70 |
+
text-align: center;
|
71 |
+
margin: 1.5rem 0;
|
72 |
+
letter-spacing: -0.02em;
|
73 |
+
}
|
74 |
+
|
75 |
+
.message {
|
76 |
+
opacity: 0;
|
77 |
+
transform: translateY(20px);
|
78 |
+
animation: fadeIn 0.3s ease forwards;
|
79 |
+
}
|
80 |
+
|
81 |
+
.message p {
|
82 |
+
font-size: 1.05rem;
|
83 |
+
line-height: 1.7;
|
84 |
+
}
|
85 |
+
|
86 |
+
.bot-avatar {
|
87 |
+
width: 40px;
|
88 |
+
height: 40px;
|
89 |
+
border-radius: 50%;
|
90 |
+
object-fit: cover;
|
91 |
+
}
|
92 |
+
|
93 |
+
.action-button {
|
94 |
+
padding: 0.5rem;
|
95 |
border-radius: 0.375rem;
|
|
|
|
|
|
|
|
|
96 |
transition: all 0.2s;
|
97 |
+
display: inline-flex;
|
98 |
+
align-items: center;
|
99 |
+
gap: 0.5rem;
|
100 |
+
font-size: 0.875rem;
|
101 |
color: #6B7280;
|
102 |
+
background-color: #F3F4F6;
|
103 |
}
|
104 |
|
105 |
+
.action-button:hover {
|
106 |
+
background-color: #E5E7EB;
|
107 |
}
|
108 |
|
109 |
+
.style-select {
|
110 |
+
appearance: none;
|
111 |
+
background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
|
112 |
+
background-repeat: no-repeat;
|
113 |
+
background-position: left 0.5rem center;
|
114 |
+
background-size: 1em;
|
115 |
}
|
116 |
|
117 |
+
.stop-generation {
|
118 |
+
background-color: #EF4444 !important;
|
119 |
+
color: white !important;
|
|
|
|
|
|
|
|
|
|
|
120 |
}
|
121 |
|
122 |
+
.message-actions {
|
123 |
+
display: flex;
|
124 |
+
gap: 0.5rem;
|
125 |
+
margin-top: 0.5rem;
|
126 |
}
|
127 |
|
128 |
+
@media (max-width: 640px) {
|
129 |
+
.style-select {
|
130 |
+
width: 40px;
|
131 |
+
overflow: hidden;
|
132 |
+
white-space: nowrap;
|
133 |
+
padding-right: 0;
|
134 |
+
background-position: center;
|
135 |
+
}
|
136 |
+
|
137 |
+
.style-select option {
|
138 |
+
padding: 8px;
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
@keyframes typeIn {
|
143 |
+
to {
|
144 |
+
opacity: 1;
|
145 |
+
transform: translateY(0);
|
146 |
+
}
|
147 |
+
}
|
148 |
+
|
149 |
+
@keyframes fadeIn {
|
150 |
+
to {
|
151 |
+
opacity: 1;
|
152 |
+
transform: translateY(0);
|
153 |
+
}
|
154 |
+
}
|
155 |
</style>
|
156 |
</head>
|
157 |
<body class="text-lg light-mode">
|
158 |
+
<header class="fixed top-0 left-0 right-0 bg-white border-b border-gray-100 z-50 shadow-sm">
|
159 |
+
<div class="flex items-center px-4 py-2">
|
160 |
+
<div class="flex items-center flex-1">
|
161 |
+
<span class="text-2xl font-bold text-indigo-600">Speedy</span>
|
162 |
+
</div>
|
163 |
+
<button id="darkModeToggle" class="text-gray-500 hover:bg-gray-50 p-2 rounded-full transition-colors mr-2">
|
164 |
+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
165 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"></path>
|
166 |
+
</svg>
|
167 |
+
</button>
|
168 |
+
<button id="clearChat" class="text-gray-500 hover:bg-gray-50 p-2 rounded-full transition-colors">
|
169 |
+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
170 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
|
171 |
+
</svg>
|
172 |
+
</button>
|
173 |
+
</div>
|
174 |
+
</header>
|
175 |
|
176 |
<main class="pt-24 pb-24">
|
177 |
<div class="max-w-3xl mx-auto px-4">
|
|
|
195 |
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
196 |
</svg>
|
197 |
</button>
|
198 |
+
<a href="https://joermd-test11.static.hf.space" target="_blank" id="micButton" class="bg-green-500 hover:bg-green-600 text-white rounded-full p-2 transition-colors">
|
199 |
+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
200 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 11a7 7 0 01-7 7m0 0a7 7 0 01-7-7m7 7v4m0 0H8m4 0h4m-4-8a3 3 0 01-3-3V5a3 3 0 116 0v6a3 3 0 01-3 3z"></path>
|
201 |
+
</svg>
|
202 |
+
</a>
|
203 |
+
<select id="styleSelect" class="style-select bg-gray-50 border border-gray-200 text-gray-600 text-sm rounded-lg pl-8 pr-2 py-2 focus:outline-none focus:ring-2 focus:ring-indigo-200">
|
204 |
+
<option value="short">⚡ ردود قصيرة</option>
|
205 |
+
<option value="normal" selected>◯ عادي</option>
|
206 |
+
<option value="long">↔ ردود مفصلة</option>
|
207 |
+
</select>
|
208 |
</div>
|
209 |
</div>
|
210 |
</div>
|
211 |
</footer>
|
212 |
+
<script>
|
213 |
+
const API_URL = 'https://xdran65ok359ef-7777.proxy.runpod.net/proxy/8000/chat';
|
214 |
+
const messagesContainer = document.getElementById('messagesContainer');
|
215 |
+
const messageInput = document.getElementById('messageInput');
|
216 |
+
const sendButton = document.getElementById('sendMessage');
|
217 |
+
const clearButton = document.getElementById('clearChat');
|
218 |
+
const styleSelect = document.getElementById('styleSelect');
|
219 |
+
const darkModeToggle = document.getElementById('darkModeToggle');
|
220 |
+
let chatHistory = [];
|
221 |
+
let currentStyle = 'normal';
|
222 |
+
let currentController = null;
|
223 |
|
224 |
+
// Dark mode toggle
|
225 |
+
darkModeToggle.addEventListener('click', () => {
|
226 |
+
document.body.classList.toggle('dark-mode');
|
227 |
+
document.body.classList.toggle('light-mode');
|
228 |
+
});
|
229 |
|
230 |
+
styleSelect.addEventListener('change', (e) => {
|
231 |
+
currentStyle = e.target.value;
|
232 |
+
});
|
233 |
+
|
234 |
+
function createUserMessage(text) {
|
235 |
+
let prefix = '';
|
236 |
+
if (currentStyle === 'short') {
|
237 |
+
prefix = 'اعطني رد باختصار وسرعة: ';
|
238 |
+
} else if (currentStyle === 'long') {
|
239 |
+
prefix = 'اعطني رد مفصل وموسع: ';
|
240 |
+
}
|
241 |
+
|
242 |
+
return `
|
243 |
+
<div class="message flex justify-end mb-4">
|
244 |
+
<div class="max-w-[80%]">
|
245 |
+
<div class="bg-indigo-500 text-white rounded-lg p-4 shadow-sm">
|
246 |
+
<p class="text-lg">${text}</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
</div>
|
248 |
+
</div>
|
249 |
+
</div>
|
250 |
+
`;
|
251 |
+
}
|
252 |
|
253 |
+
function createBotMessage(text, messageId) {
|
254 |
+
return `
|
255 |
+
<div class="message flex justify-start mb-4">
|
256 |
+
<div class="flex-shrink-0 mt-1">
|
257 |
+
<img src="https://ufastpro.com/wp-content/uploads/2024/12/3.png" alt="Bot Avatar" class="bot-avatar">
|
258 |
+
</div>
|
259 |
+
<div class="max-w-[80%] mr-3">
|
260 |
+
<div class="bot-message bg-white rounded-lg p-4 shadow-sm">
|
261 |
+
<p id="${messageId}" class="text-gray-700"></p>
|
262 |
+
<div class="message-actions">
|
263 |
+
<button class="action-button copy-button" data-message-id="${messageId}">
|
264 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
265 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"></path>
|
266 |
+
</svg>
|
|
|
|
|
267 |
نسخ
|
268 |
</button>
|
269 |
+
<button class="action-button regenerate-button" data-message-id="${messageId}">
|
270 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
271 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"></path>
|
272 |
+
</svg>
|
273 |
إعادة التوليد
|
274 |
</button>
|
275 |
+
<button class="action-button like-button" data-message-id="${messageId}">
|
276 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
277 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 10h4.764a2 2 0 011.789 2.894l-3.5 7A2 2 0 0115.263 21h-4.017c-.163 0-.326-.02-.485-.06L7 20m7-10V5a2 2 0 00-2-2h-.095c-.5 0-.905.405-.905.905 0 .714-.211 1.412-.608 2.006L7 11v9m7-10h-2M7 20H5a2 2 0 01-2-2v-6a2 2 0 012-2h2.5"></path>
|
278 |
+
</svg>
|
279 |
+
أعجبني
|
280 |
+
</button>
|
281 |
+
<button class="action-button dislike-button" data-message-id="${messageId}">
|
282 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
283 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 14H5.236a2 2 0 01-1.789-2.894l3.5-7A2 2 0 018.736 3h4.018c.163 0 .326.02.485.06L17 4m-7 10v5a2 2 0 002 2h.095c.5 0 .905-.405.905-.905 0-.714.211-1.412.608-2.006L17 13V4m-7 10h2m5 0v2a2 2 0 01-2 2h-2.5"></path>
|
284 |
+
</svg>
|
285 |
+
لم يعجبني
|
286 |
+
</button>
|
287 |
</div>
|
288 |
</div>
|
289 |
+
</div>
|
290 |
+
</div>
|
291 |
+
`;
|
292 |
+
}
|
293 |
|
294 |
+
async function typeText(elementId, text) {
|
295 |
+
const element = document.getElementById(elementId);
|
296 |
+
element.innerHTML = '';
|
297 |
+
const words = text.split(' ');
|
298 |
+
|
299 |
+
for (let i = 0; i < words.length; i++) {
|
300 |
+
const span = document.createElement('span');
|
301 |
+
span.textContent = words[i] + ' ';
|
302 |
+
span.className = 'typing-animation';
|
303 |
+
element.appendChild(span);
|
304 |
+
await new Promise(resolve => setTimeout(resolve, 50));
|
305 |
+
}
|
306 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
307 |
|
308 |
+
function toggleSendButton(isGenerating) {
|
309 |
+
const sendButton = document.getElementById('sendMessage');
|
310 |
+
if (isGenerating) {
|
311 |
+
sendButton.classList.add('stop-generation');
|
312 |
+
sendButton.innerHTML = `
|
313 |
+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
314 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
|
315 |
+
</svg>
|
316 |
+
`;
|
317 |
+
} else {
|
318 |
+
sendButton.classList.remove('stop-generation');
|
319 |
+
sendButton.innerHTML = `
|
320 |
+
<svg class="w-6 h-6 transform rotate-90" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
321 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18"></path>
|
322 |
+
</svg>
|
323 |
+
`;
|
324 |
+
}
|
325 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
326 |
|
327 |
+
async function sendMessage() {
|
328 |
+
const message = messageInput.value.trim();
|
329 |
+
if (!message) return;
|
330 |
+
|
331 |
+
if (currentController) {
|
332 |
+
currentController.abort();
|
333 |
+
currentController = null;
|
334 |
+
toggleSendButton(false);
|
335 |
+
return;
|
336 |
+
}
|
337 |
+
|
338 |
+
messageInput.value = '';
|
339 |
+
adjustTextareaHeight();
|
340 |
+
|
341 |
+
const messageId = 'msg-' + Date.now();
|
342 |
+
let actualMessage = message;
|
343 |
+
|
344 |
+
if (currentStyle === 'short') {
|
345 |
+
actualMessage = 'اعطني رد باختصار وسرعة: ' + message;
|
346 |
+
} else if (currentStyle === 'long') {
|
347 |
+
actualMessage = 'اعطني رد مفصل وموسع: ' + message;
|
348 |
+
}
|
349 |
+
|
350 |
+
messagesContainer.insertAdjacentHTML('beforeend', createUserMessage(message));
|
351 |
+
messagesContainer.insertAdjacentHTML('beforeend', createBotMessage('', messageId));
|
352 |
+
scrollToBottom();
|
353 |
+
|
354 |
+
try {
|
355 |
+
currentController = new AbortController();
|
356 |
+
toggleSendButton(true);
|
357 |
+
|
358 |
+
const response = await fetch(API_URL, {
|
359 |
+
method: 'POST',
|
360 |
+
headers: { 'Content-Type': 'application/json' },
|
361 |
+
body: JSON.stringify({
|
362 |
+
message: actualMessage,
|
363 |
+
history: chatHistory
|
364 |
+
}),
|
365 |
+
signal: currentController.signal
|
366 |
});
|
367 |
|
368 |
+
const data = await response.json();
|
369 |
+
await typeText(messageId, data.response);
|
370 |
+
|
371 |
+
chatHistory.push({
|
372 |
+
human: actualMessage,
|
373 |
+
assistant: data.response
|
374 |
});
|
375 |
+
} catch (error) {
|
376 |
+
if (error.name === 'AbortError') {
|
377 |
+
document.getElementById(messageId).textContent = 'تم إيقاف التوليد.';
|
378 |
+
} else {
|
379 |
+
document.getElementById(messageId).textContent = 'عذراً، حدث خطأ في المعالجة.';
|
380 |
+
}
|
381 |
+
} finally {
|
382 |
+
currentController = null;
|
383 |
+
toggleSendButton(false);
|
384 |
+
}
|
385 |
+
scrollToBottom();
|
386 |
+
}
|
387 |
|
388 |
+
// Event Listeners for Message Actions
|
389 |
+
document.addEventListener('click', async (e) => {
|
390 |
+
if (e.target.closest('.copy-button')) {
|
391 |
+
const messageId = e.target.closest('.copy-button').dataset.messageId;
|
392 |
+
const text = document.getElementById(messageId).textContent;
|
393 |
+
await navigator.clipboard.writeText(text);
|
394 |
+
e.target.closest('.copy-button').textContent = 'تم النسخ!';
|
395 |
+
setTimeout(() => {
|
396 |
+
e.target.closest('.copy-button').innerHTML = `
|
397 |
+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
398 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3"></path>
|
399 |
+
</svg>
|
400 |
+
نسخ
|
401 |
+
`;
|
402 |
+
}, 2000);
|
403 |
+
}
|
404 |
|
405 |
+
if (e.target.closest('.regenerate-button')) {
|
406 |
+
const messageId = e.target.closest('.regenerate-button').dataset.messageId;
|
407 |
+
// إعادة إرسال آخر رسالة في المحادثة
|
408 |
+
if (chatHistory.length > 0) {
|
409 |
+
const lastMessage = chatHistory[chatHistory.length - 1].human;
|
410 |
+
messageInput.value = lastMessage;
|
411 |
+
sendMessage();
|
412 |
}
|
413 |
+
}
|
414 |
+
|
415 |
+
if (e.target.closest('.like-button')) {
|
416 |
+
const button = e.target.closest('.like-button');
|
417 |
+
button.classList.toggle('text-green-500');
|
418 |
+
}
|
419 |
+
|
420 |
+
if (e.target.closest('.dislike-button')) {
|
421 |
+
const button = e.target.closest('.dislike-button');
|
422 |
+
button.classList.toggle('text-red-500');
|
423 |
+
}
|
424 |
+
});
|
425 |
|
426 |
+
function scrollToBottom() {
|
427 |
+
window.scrollTo({
|
428 |
+
top: document.documentElement.scrollHeight,
|
429 |
+
behavior: 'smooth'
|
430 |
+
});
|
431 |
+
}
|
432 |
|
433 |
+
function adjustTextareaHeight() {
|
434 |
+
messageInput.style.height = 'auto';
|
435 |
+
messageInput.style.height = messageInput.scrollHeight + 'px';
|
436 |
+
}
|
437 |
+
|
438 |
+
sendButton.addEventListener('click', sendMessage);
|
439 |
+
messageInput.addEventListener('keypress', (e) => {
|
440 |
+
if (e.key === 'Enter' && !e.shiftKey) {
|
441 |
+
e.preventDefault();
|
442 |
+
sendMessage();
|
443 |
+
}
|
444 |
+
});
|
445 |
+
messageInput.addEventListener('input', adjustTextareaHeight);
|
446 |
+
clearButton.addEventListener('click', () => {
|
447 |
+
messagesContainer.innerHTML = '';
|
448 |
+
chatHistory = [];
|
449 |
+
});
|
450 |
|
451 |
+
// Initial welcome message
|
452 |
+
const initialMessageId = 'msg-initial';
|
453 |
+
messagesContainer.insertAdjacentHTML('beforeend', createBotMessage('', initialMessageId));
|
454 |
+
typeText(initialMessageId, 'مرحباً! كيف يمكنني مساعدتك اليوم؟');
|
455 |
+
</script>
|
456 |
</body>
|
457 |
</html>
|