Update script.js
Browse files
script.js
CHANGED
|
@@ -433,7 +433,7 @@ function speakMantra(mantraText, repeatCount) {
|
|
| 433 |
utterance.lang = 'sa-IN'; // Sanskrit
|
| 434 |
utterance.rate = 0.8; // Slow speech for mantras
|
| 435 |
utterance.pitch = 1.0; // Natural pitch
|
| 436 |
-
|
| 437 |
utterance.onend = function() {
|
| 438 |
if (repeatCount > 1) {
|
| 439 |
repeatCount--;
|
|
@@ -463,20 +463,22 @@ function repeatMantra() {
|
|
| 463 |
let isFirstMessage = true; // Flag to track if it's the first message
|
| 464 |
|
| 465 |
// Function to speak the mantra
|
| 466 |
-
function
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
utterance.onend = function() {
|
| 473 |
-
if (repeatCount > 1) {
|
| 474 |
-
repeatCount--;
|
| 475 |
-
speechSynthesis.speak(utterance);
|
| 476 |
}
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
}
|
| 481 |
|
| 482 |
// function activateVoice() {
|
|
|
|
| 433 |
utterance.lang = 'sa-IN'; // Sanskrit
|
| 434 |
utterance.rate = 0.8; // Slow speech for mantras
|
| 435 |
utterance.pitch = 1.0; // Natural pitch
|
| 436 |
+
|
| 437 |
utterance.onend = function() {
|
| 438 |
if (repeatCount > 1) {
|
| 439 |
repeatCount--;
|
|
|
|
| 463 |
let isFirstMessage = true; // Flag to track if it's the first message
|
| 464 |
|
| 465 |
// Function to speak the mantra
|
| 466 |
+
function appendMessage(text, className) {
|
| 467 |
+
// Remove the default message when the user sends the first message
|
| 468 |
+
if (isFirstMessage) {
|
| 469 |
+
const welcomeMessage = document.querySelector('.welcome-message');
|
| 470 |
+
if (welcomeMessage) {
|
| 471 |
+
welcomeMessage.remove();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 472 |
}
|
| 473 |
+
isFirstMessage = false;
|
| 474 |
+
}
|
| 475 |
+
const messageElement = document.createElement('div');
|
| 476 |
+
messageElement.classList.add('user-message', className);
|
| 477 |
+
|
| 478 |
+
// Use innerHTML to allow formatted content (e.g., bold, italic, line breaks)
|
| 479 |
+
messageElement.innerHTML = text;
|
| 480 |
+
chatBody.appendChild(messageElement);
|
| 481 |
+
chatBody.scrollTop = chatBody.scrollHeight; // Auto scroll to the latest message
|
| 482 |
}
|
| 483 |
|
| 484 |
// function activateVoice() {
|