Spaces:
Running
Running
Update index.html
Browse files- index.html +222 -13
index.html
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="fa" dir="rtl">
|
| 3 |
<head>
|
|
@@ -7,6 +8,22 @@
|
|
| 7 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap" rel="stylesheet">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
<style>
|
| 11 |
:root {
|
| 12 |
--eye-color: #00eaff;
|
|
@@ -17,6 +34,7 @@
|
|
| 17 |
--ui-border-color: rgba(0, 234, 255, 0.6);
|
| 18 |
--ui-shadow-color: rgba(0, 234, 255, 0.2);
|
| 19 |
--text-color: #c9d1d9;
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
* {
|
|
@@ -100,7 +118,7 @@
|
|
| 100 |
backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
|
| 101 |
box-shadow: 0 0 30px var(--ui-shadow-color);
|
| 102 |
overflow-y: auto; padding: 20px;
|
| 103 |
-
display: flex; flex-direction: column
|
| 104 |
margin-top: -80px; padding-top: 90px;
|
| 105 |
min-height: 0; margin-bottom: 15px;
|
| 106 |
}
|
|
@@ -144,14 +162,16 @@
|
|
| 144 |
|
| 145 |
.user-message { margin-left: auto; }
|
| 146 |
.user-message .message-content {
|
| 147 |
-
background
|
| 148 |
border-bottom-left-radius: 5px;
|
|
|
|
| 149 |
}
|
| 150 |
|
| 151 |
.bot-message { margin-right: auto; }
|
| 152 |
.bot-message .message-content {
|
| 153 |
-
background
|
| 154 |
border-bottom-right-radius: 5px;
|
|
|
|
| 155 |
}
|
| 156 |
|
| 157 |
.bot-message.thinking .message-content { animation: pulse 1.5s infinite; }
|
|
@@ -232,17 +252,31 @@
|
|
| 232 |
#message-input {
|
| 233 |
flex-grow: 1; background: transparent; border: none;
|
| 234 |
outline: none; color: var(--text-color); font-size: 16px;
|
| 235 |
-
padding: 10px
|
|
|
|
| 236 |
text-align: right;
|
| 237 |
}
|
| 238 |
|
| 239 |
#message-input::placeholder {
|
| 240 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
text-align: center;
|
| 242 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
}
|
|
|
|
| 244 |
#message-input:focus::placeholder {
|
| 245 |
-
color: transparent;
|
| 246 |
opacity: 0;
|
| 247 |
}
|
| 248 |
|
|
@@ -280,7 +314,6 @@
|
|
| 280 |
100% { opacity: 0; }
|
| 281 |
}
|
| 282 |
|
| 283 |
-
|
| 284 |
#send-button {
|
| 285 |
width: 40px; height: 40px; background-color: var(--eye-color);
|
| 286 |
border-radius: 50%; position: absolute; top: 10px;
|
|
@@ -294,7 +327,6 @@
|
|
| 294 |
#send-hint {
|
| 295 |
position: absolute;
|
| 296 |
bottom: 100%;
|
| 297 |
-
/* --- اصلاح کلیدی اینجا انجام شد --- */
|
| 298 |
right: 10px;
|
| 299 |
margin-bottom: 5px;
|
| 300 |
background-color: #222;
|
|
@@ -317,6 +349,47 @@
|
|
| 317 |
60% { opacity: 1; }
|
| 318 |
}
|
| 319 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 320 |
|
| 321 |
.site-footer { flex-shrink: 0; text-align: center; padding: 0 15px 10px 15px; }
|
| 322 |
|
|
@@ -359,13 +432,19 @@
|
|
| 359 |
</div>
|
| 360 |
<div id="chat-container"></div>
|
| 361 |
<div id="input-area">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
<div id="send-hint">بکش پایین رها کن</div>
|
| 363 |
<div id="send-button-container">
|
| 364 |
<div id="send-button">
|
| 365 |
<svg viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14m7-7l-7 7-7-7"/></svg>
|
| 366 |
</div>
|
| 367 |
</div>
|
| 368 |
-
<textarea id="message-input" placeholder="
|
| 369 |
</div>
|
| 370 |
</div>
|
| 371 |
<footer class="site-footer">
|
|
@@ -379,6 +458,17 @@
|
|
| 379 |
</div>
|
| 380 |
|
| 381 |
<script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
class RobotFace {
|
| 383 |
constructor(canvas) {
|
| 384 |
this.canvas = canvas; this.ctx = canvas.getContext("2d");
|
|
@@ -526,9 +616,14 @@ class ChatInterface {
|
|
| 526 |
this.sendButtonContainer = document.getElementById('send-button-container');
|
| 527 |
this.sendButton = document.getElementById('send-button');
|
| 528 |
this.sendHint = document.getElementById('send-hint');
|
|
|
|
| 529 |
this.isDragging = false; this.startY = 0; this.currentY = 0; this.dragThreshold = 30;
|
| 530 |
this.typingTimeout = null; this.hintTimeout = null;
|
| 531 |
this.API_URL = 'https://text.pollinations.ai/openai';
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
const SYSTEM_PROMPT = `
|
| 534 |
## Core Identity (ONLY reveal if asked about who you are):
|
|
@@ -559,6 +654,40 @@ class ChatInterface {
|
|
| 559 |
|
| 560 |
this.conversationHistory = [{ role: 'system', content: SYSTEM_PROMPT.trim().replace(/\\n/g, '\n') }];
|
| 561 |
this.initListeners();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 562 |
}
|
| 563 |
|
| 564 |
initListeners() {
|
|
@@ -585,7 +714,22 @@ class ChatInterface {
|
|
| 585 |
window.addEventListener('touchmove', this.dragMove.bind(this), { passive: false });
|
| 586 |
window.addEventListener('mouseup', this.dragEnd.bind(this));
|
| 587 |
window.addEventListener('touchend', this.dragEnd.bind(this));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
}
|
|
|
|
| 589 |
dragStart(e) {
|
| 590 |
if (this.input.value.trim() === '') return;
|
| 591 |
this.isDragging = true; this.sendButton.classList.add('dragging');
|
|
@@ -619,11 +763,66 @@ class ChatInterface {
|
|
| 619 |
this.sendButton.style.top = '10px'; this.currentY = 0;
|
| 620 |
}
|
| 621 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 622 |
async sendMessage(messageText) {
|
| 623 |
const text = messageText.trim();
|
| 624 |
if (!text) return;
|
| 625 |
|
| 626 |
this.addMessage(text, 'user');
|
|
|
|
| 627 |
this.conversationHistory.push({ role: 'user', content: text });
|
| 628 |
this.input.value = ''; this.input.style.height = 'auto';
|
| 629 |
this.inputArea.classList.remove('typing');
|
|
@@ -632,7 +831,11 @@ class ChatInterface {
|
|
| 632 |
this.robotFace.startThinking();
|
| 633 |
const thinkingBubble = this.addMessage('...', 'bot', true);
|
| 634 |
try {
|
| 635 |
-
const response = await fetch(this.API_URL, {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
if (!response.ok) { throw new Error(`خطای شبکه: ${response.status} ${response.statusText}`); }
|
| 637 |
const data = await response.json();
|
| 638 |
const botReply = data.choices[0].message.content;
|
|
@@ -647,6 +850,7 @@ class ChatInterface {
|
|
| 647 |
this.addMessage(`سرم شلوغه یه دیقه بکش بیرون بعدا بیا: ${error.message}`, 'bot');
|
| 648 |
} finally {
|
| 649 |
this.robotFace.stopThinking();
|
|
|
|
| 650 |
}
|
| 651 |
}
|
| 652 |
|
|
@@ -661,9 +865,14 @@ class ChatInterface {
|
|
| 661 |
this.renderMessageContent(bubble, text);
|
| 662 |
}
|
| 663 |
|
| 664 |
-
this.chatContainer.
|
|
|
|
| 665 |
return bubble;
|
| 666 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
|
| 668 |
renderMessageContent(bubble, text) {
|
| 669 |
const escapeHTML = (str) => str.replace(/[&<>'"]/g, tag => ({'&': '&', '<': '<', '>': '>', "'": ''', '"': '"'}[tag] || tag));
|
|
@@ -791,4 +1000,4 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 791 |
});
|
| 792 |
</script>
|
| 793 |
</body>
|
| 794 |
-
</html>
|
|
|
|
| 1 |
+
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="fa" dir="rtl">
|
| 4 |
<head>
|
|
|
|
| 8 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 9 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 10 |
<link href="https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500;700&display=swap" rel="stylesheet">
|
| 11 |
+
|
| 12 |
+
<!-- PWA Manifest -->
|
| 13 |
+
<link rel="manifest" href="data:application/manifest+json,{
|
| 14 |
+
\"name\": \"ROBO☬SHΞN™\",
|
| 15 |
+
\"short_name\": \"ROBO☬SHΞN\",
|
| 16 |
+
\"start_url\": \"/\",
|
| 17 |
+
\"display\": \"standalone\",
|
| 18 |
+
\"background_color\": \"#000000\",
|
| 19 |
+
\"theme_color\": \"#00eaff\",
|
| 20 |
+
\"icons\": [{
|
| 21 |
+
\"src\": \"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 192 192'%3E%3Crect width='192' height='192' fill='%2300eaff'/%3E%3Ctext x='96' y='130' font-family='Arial' font-size='140' text-anchor='middle' fill='%23000000'%3E%E2%98%AC%E2%84%A2%3C/text%3E%3C/svg%3E\",
|
| 22 |
+
\"sizes\": \"192x192\",
|
| 23 |
+
\"type\": \"image/svg+xml\"
|
| 24 |
+
}]
|
| 25 |
+
}">
|
| 26 |
+
|
| 27 |
<style>
|
| 28 |
:root {
|
| 29 |
--eye-color: #00eaff;
|
|
|
|
| 34 |
--ui-border-color: rgba(0, 234, 255, 0.6);
|
| 35 |
--ui-shadow-color: rgba(0, 234, 255, 0.2);
|
| 36 |
--text-color: #c9d1d9;
|
| 37 |
+
--placeholder-gradient: linear-gradient(90deg, #ffffff, #cccccc, #666666, #cccccc, #ffffff);
|
| 38 |
}
|
| 39 |
|
| 40 |
* {
|
|
|
|
| 118 |
backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
|
| 119 |
box-shadow: 0 0 30px var(--ui-shadow-color);
|
| 120 |
overflow-y: auto; padding: 20px;
|
| 121 |
+
display: flex; flex-direction: column;
|
| 122 |
margin-top: -80px; padding-top: 90px;
|
| 123 |
min-height: 0; margin-bottom: 15px;
|
| 124 |
}
|
|
|
|
| 162 |
|
| 163 |
.user-message { margin-left: auto; }
|
| 164 |
.user-message .message-content {
|
| 165 |
+
background: linear-gradient(135deg, rgba(0, 234, 255, 0.3), rgba(0, 234, 255, 0.1));
|
| 166 |
border-bottom-left-radius: 5px;
|
| 167 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 168 |
}
|
| 169 |
|
| 170 |
.bot-message { margin-right: auto; }
|
| 171 |
.bot-message .message-content {
|
| 172 |
+
background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.05));
|
| 173 |
border-bottom-right-radius: 5px;
|
| 174 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 175 |
}
|
| 176 |
|
| 177 |
.bot-message.thinking .message-content { animation: pulse 1.5s infinite; }
|
|
|
|
| 252 |
#message-input {
|
| 253 |
flex-grow: 1; background: transparent; border: none;
|
| 254 |
outline: none; color: var(--text-color); font-size: 16px;
|
| 255 |
+
padding: 10px 10px 10px 40px; /* Added left padding for mic button */
|
| 256 |
+
resize: none; max-height: 100px;
|
| 257 |
text-align: right;
|
| 258 |
}
|
| 259 |
|
| 260 |
#message-input::placeholder {
|
| 261 |
+
color: transparent;
|
| 262 |
+
background-image: var(--placeholder-gradient);
|
| 263 |
+
background-size: 400% 100%;
|
| 264 |
+
background-clip: text;
|
| 265 |
+
-webkit-background-clip: text;
|
| 266 |
+
-webkit-text-fill-color: transparent;
|
| 267 |
+
animation: gradient-wavy 8s ease infinite;
|
| 268 |
text-align: center;
|
| 269 |
+
font-size: 14px; /* Adjusted font size */
|
| 270 |
+
transition: opacity 0.2s;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
@keyframes gradient-wavy {
|
| 274 |
+
0%{background-position:0% 50%}
|
| 275 |
+
50%{background-position:100% 50%}
|
| 276 |
+
100%{background-position:0% 50%}
|
| 277 |
}
|
| 278 |
+
|
| 279 |
#message-input:focus::placeholder {
|
|
|
|
| 280 |
opacity: 0;
|
| 281 |
}
|
| 282 |
|
|
|
|
| 314 |
100% { opacity: 0; }
|
| 315 |
}
|
| 316 |
|
|
|
|
| 317 |
#send-button {
|
| 318 |
width: 40px; height: 40px; background-color: var(--eye-color);
|
| 319 |
border-radius: 50%; position: absolute; top: 10px;
|
|
|
|
| 327 |
#send-hint {
|
| 328 |
position: absolute;
|
| 329 |
bottom: 100%;
|
|
|
|
| 330 |
right: 10px;
|
| 331 |
margin-bottom: 5px;
|
| 332 |
background-color: #222;
|
|
|
|
| 349 |
60% { opacity: 1; }
|
| 350 |
}
|
| 351 |
|
| 352 |
+
/* Microphone Button Styles */
|
| 353 |
+
#mic-button {
|
| 354 |
+
position: absolute;
|
| 355 |
+
top: 50%;
|
| 356 |
+
left: 10px;
|
| 357 |
+
transform: translateY(-50%);
|
| 358 |
+
background: none;
|
| 359 |
+
border: none;
|
| 360 |
+
cursor: pointer;
|
| 361 |
+
padding: 5px;
|
| 362 |
+
z-index: 2;
|
| 363 |
+
}
|
| 364 |
+
|
| 365 |
+
#mic-button svg {
|
| 366 |
+
width: 20px;
|
| 367 |
+
height: 20px;
|
| 368 |
+
fill: var(--text-color);
|
| 369 |
+
transition: fill 0.3s;
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
#mic-button.listening svg {
|
| 373 |
+
fill: var(--eye-color);
|
| 374 |
+
animation: pulse-mic 1s infinite;
|
| 375 |
+
}
|
| 376 |
+
|
| 377 |
+
@keyframes pulse-mic {
|
| 378 |
+
0% { opacity: 1; }
|
| 379 |
+
50% { opacity: 0.5; }
|
| 380 |
+
100% { opacity: 1; }
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
/* Particle Animation for Send */
|
| 384 |
+
.particle {
|
| 385 |
+
position: absolute;
|
| 386 |
+
width: 4px;
|
| 387 |
+
height: 4px;
|
| 388 |
+
border-radius: 50%;
|
| 389 |
+
background-color: var(--eye-color);
|
| 390 |
+
pointer-events: none;
|
| 391 |
+
opacity: 0;
|
| 392 |
+
}
|
| 393 |
|
| 394 |
.site-footer { flex-shrink: 0; text-align: center; padding: 0 15px 10px 15px; }
|
| 395 |
|
|
|
|
| 432 |
</div>
|
| 433 |
<div id="chat-container"></div>
|
| 434 |
<div id="input-area">
|
| 435 |
+
<button id="mic-button" aria-label="ضبط صدا">
|
| 436 |
+
<svg viewBox="0 0 24 24">
|
| 437 |
+
<path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z"/>
|
| 438 |
+
<path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z"/>
|
| 439 |
+
</svg>
|
| 440 |
+
</button>
|
| 441 |
<div id="send-hint">بکش پایین رها کن</div>
|
| 442 |
<div id="send-button-container">
|
| 443 |
<div id="send-button">
|
| 444 |
<svg viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14m7-7l-7 7-7-7"/></svg>
|
| 445 |
</div>
|
| 446 |
</div>
|
| 447 |
+
<textarea id="message-input" placeholder="انگشتی تایپکن یا میکبزن بگو" rows="1"></textarea>
|
| 448 |
</div>
|
| 449 |
</div>
|
| 450 |
<footer class="site-footer">
|
|
|
|
| 458 |
</div>
|
| 459 |
|
| 460 |
<script>
|
| 461 |
+
// Register Service Worker for PWA
|
| 462 |
+
if ('serviceWorker' in navigator) {
|
| 463 |
+
window.addEventListener('load', () => {
|
| 464 |
+
navigator.serviceWorker.register('data:application/javascript,' + encodeURIComponent(`
|
| 465 |
+
self.addEventListener('fetch', event => {
|
| 466 |
+
event.respondWith(fetch(event.request));
|
| 467 |
+
});
|
| 468 |
+
`)).catch(err => console.log('SW registration failed: ', err));
|
| 469 |
+
});
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
class RobotFace {
|
| 473 |
constructor(canvas) {
|
| 474 |
this.canvas = canvas; this.ctx = canvas.getContext("2d");
|
|
|
|
| 616 |
this.sendButtonContainer = document.getElementById('send-button-container');
|
| 617 |
this.sendButton = document.getElementById('send-button');
|
| 618 |
this.sendHint = document.getElementById('send-hint');
|
| 619 |
+
this.micButton = document.getElementById('mic-button');
|
| 620 |
this.isDragging = false; this.startY = 0; this.currentY = 0; this.dragThreshold = 30;
|
| 621 |
this.typingTimeout = null; this.hintTimeout = null;
|
| 622 |
this.API_URL = 'https://text.pollinations.ai/openai';
|
| 623 |
+
|
| 624 |
+
// Speech Recognition
|
| 625 |
+
this.recognition = null;
|
| 626 |
+
this.setupSpeechRecognition();
|
| 627 |
|
| 628 |
const SYSTEM_PROMPT = `
|
| 629 |
## Core Identity (ONLY reveal if asked about who you are):
|
|
|
|
| 654 |
|
| 655 |
this.conversationHistory = [{ role: 'system', content: SYSTEM_PROMPT.trim().replace(/\\n/g, '\n') }];
|
| 656 |
this.initListeners();
|
| 657 |
+
this.scrollToBottom();
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
setupSpeechRecognition() {
|
| 661 |
+
const SpeechRecognition = window.SpeechRecognition || window.webkitSpeechRecognition;
|
| 662 |
+
if (!SpeechRecognition) {
|
| 663 |
+
console.warn('Speech Recognition not supported in this browser.');
|
| 664 |
+
this.micButton.style.display = 'none';
|
| 665 |
+
return;
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
this.recognition = new SpeechRecognition();
|
| 669 |
+
this.recognition.continuous = false;
|
| 670 |
+
this.recognition.interimResults = false;
|
| 671 |
+
this.recognition.lang = 'fa-IR'; // Default to Persian
|
| 672 |
+
|
| 673 |
+
this.recognition.onstart = () => {
|
| 674 |
+
this.micButton.classList.add('listening');
|
| 675 |
+
};
|
| 676 |
+
|
| 677 |
+
this.recognition.onresult = (event) => {
|
| 678 |
+
const transcript = event.results[0][0].transcript;
|
| 679 |
+
this.input.value += transcript;
|
| 680 |
+
this.input.dispatchEvent(new Event('input'));
|
| 681 |
+
};
|
| 682 |
+
|
| 683 |
+
this.recognition.onerror = (event) => {
|
| 684 |
+
console.error('Speech recognition error', event.error);
|
| 685 |
+
this.micButton.classList.remove('listening');
|
| 686 |
+
};
|
| 687 |
+
|
| 688 |
+
this.recognition.onend = () => {
|
| 689 |
+
this.micButton.classList.remove('listening');
|
| 690 |
+
};
|
| 691 |
}
|
| 692 |
|
| 693 |
initListeners() {
|
|
|
|
| 714 |
window.addEventListener('touchmove', this.dragMove.bind(this), { passive: false });
|
| 715 |
window.addEventListener('mouseup', this.dragEnd.bind(this));
|
| 716 |
window.addEventListener('touchend', this.dragEnd.bind(this));
|
| 717 |
+
|
| 718 |
+
// Microphone button listener
|
| 719 |
+
if (this.recognition) {
|
| 720 |
+
this.micButton.addEventListener('click', () => {
|
| 721 |
+
if (this.micButton.classList.contains('listening')) {
|
| 722 |
+
this.recognition.stop();
|
| 723 |
+
} else {
|
| 724 |
+
// Toggle language based on current input content
|
| 725 |
+
const hasEnglish = /[a-zA-Z]/.test(this.input.value);
|
| 726 |
+
this.recognition.lang = hasEnglish ? 'en-US' : 'fa-IR';
|
| 727 |
+
this.recognition.start();
|
| 728 |
+
}
|
| 729 |
+
});
|
| 730 |
+
}
|
| 731 |
}
|
| 732 |
+
|
| 733 |
dragStart(e) {
|
| 734 |
if (this.input.value.trim() === '') return;
|
| 735 |
this.isDragging = true; this.sendButton.classList.add('dragging');
|
|
|
|
| 763 |
this.sendButton.style.top = '10px'; this.currentY = 0;
|
| 764 |
}
|
| 765 |
|
| 766 |
+
// Particle animation for send
|
| 767 |
+
createSendParticles() {
|
| 768 |
+
const rect = this.input.getBoundingClientRect();
|
| 769 |
+
const centerX = rect.left + rect.width / 2;
|
| 770 |
+
const centerY = rect.top + rect.height / 2;
|
| 771 |
+
|
| 772 |
+
for (let i = 0; i < 30; i++) {
|
| 773 |
+
const particle = document.createElement('div');
|
| 774 |
+
particle.classList.add('particle');
|
| 775 |
+
document.body.appendChild(particle);
|
| 776 |
+
|
| 777 |
+
const angle = Math.random() * Math.PI * 2;
|
| 778 |
+
const speed = 2 + Math.random() * 3;
|
| 779 |
+
const vx = Math.cos(angle) * speed;
|
| 780 |
+
const vy = Math.sin(angle) * speed;
|
| 781 |
+
|
| 782 |
+
particle.style.left = `${centerX}px`;
|
| 783 |
+
particle.style.top = `${centerY}px`;
|
| 784 |
+
particle.style.opacity = '1';
|
| 785 |
+
particle.style.backgroundColor = getComputedStyle(document.documentElement).getPropertyValue('--eye-color').trim();
|
| 786 |
+
|
| 787 |
+
let posX = centerX;
|
| 788 |
+
let posY = centerY;
|
| 789 |
+
|
| 790 |
+
const animate = () => {
|
| 791 |
+
posX += vx;
|
| 792 |
+
posY += vy;
|
| 793 |
+
particle.style.left = `${posX}px`;
|
| 794 |
+
particle.style.top = `${posY}px`;
|
| 795 |
+
|
| 796 |
+
// Fade out as it moves towards chat container
|
| 797 |
+
const chatRect = this.chatContainer.getBoundingClientRect();
|
| 798 |
+
const distanceToChat = Math.sqrt(
|
| 799 |
+
Math.pow(posX - (chatRect.left + chatRect.width / 2), 2) +
|
| 800 |
+
Math.pow(posY - (chatRect.top + chatRect.height / 2), 2)
|
| 801 |
+
);
|
| 802 |
+
|
| 803 |
+
const maxDistance = Math.sqrt(
|
| 804 |
+
Math.pow(window.innerWidth, 2) + Math.pow(window.innerHeight, 2)
|
| 805 |
+
);
|
| 806 |
+
|
| 807 |
+
particle.style.opacity = `${1 - (distanceToChat / maxDistance)}`;
|
| 808 |
+
|
| 809 |
+
if (distanceToChat > 50 && posY > 0 && posY < window.innerHeight && posX > 0 && posX < window.innerWidth) {
|
| 810 |
+
requestAnimationFrame(animate);
|
| 811 |
+
} else {
|
| 812 |
+
particle.remove();
|
| 813 |
+
}
|
| 814 |
+
};
|
| 815 |
+
|
| 816 |
+
requestAnimationFrame(animate);
|
| 817 |
+
}
|
| 818 |
+
}
|
| 819 |
+
|
| 820 |
async sendMessage(messageText) {
|
| 821 |
const text = messageText.trim();
|
| 822 |
if (!text) return;
|
| 823 |
|
| 824 |
this.addMessage(text, 'user');
|
| 825 |
+
this.createSendParticles(); // Trigger particle animation
|
| 826 |
this.conversationHistory.push({ role: 'user', content: text });
|
| 827 |
this.input.value = ''; this.input.style.height = 'auto';
|
| 828 |
this.inputArea.classList.remove('typing');
|
|
|
|
| 831 |
this.robotFace.startThinking();
|
| 832 |
const thinkingBubble = this.addMessage('...', 'bot', true);
|
| 833 |
try {
|
| 834 |
+
const response = await fetch(this.API_URL, {
|
| 835 |
+
method: 'POST',
|
| 836 |
+
headers: { 'Content-Type': 'application/json' },
|
| 837 |
+
body: JSON.stringify({ messages: this.conversationHistory })
|
| 838 |
+
});
|
| 839 |
if (!response.ok) { throw new Error(`خطای شبکه: ${response.status} ${response.statusText}`); }
|
| 840 |
const data = await response.json();
|
| 841 |
const botReply = data.choices[0].message.content;
|
|
|
|
| 850 |
this.addMessage(`سرم شلوغه یه دیقه بکش بیرون بعدا بیا: ${error.message}`, 'bot');
|
| 851 |
} finally {
|
| 852 |
this.robotFace.stopThinking();
|
| 853 |
+
this.scrollToBottom();
|
| 854 |
}
|
| 855 |
}
|
| 856 |
|
|
|
|
| 865 |
this.renderMessageContent(bubble, text);
|
| 866 |
}
|
| 867 |
|
| 868 |
+
this.chatContainer.appendChild(bubble);
|
| 869 |
+
this.scrollToBottom();
|
| 870 |
return bubble;
|
| 871 |
}
|
| 872 |
+
|
| 873 |
+
scrollToBottom() {
|
| 874 |
+
this.chatContainer.scrollTop = this.chatContainer.scrollHeight;
|
| 875 |
+
}
|
| 876 |
|
| 877 |
renderMessageContent(bubble, text) {
|
| 878 |
const escapeHTML = (str) => str.replace(/[&<>'"]/g, tag => ({'&': '&', '<': '<', '>': '>', "'": ''', '"': '"'}[tag] || tag));
|
|
|
|
| 1000 |
});
|
| 1001 |
</script>
|
| 1002 |
</body>
|
| 1003 |
+
</html>
|