(sender, message, isMarkdown)
| 39 | |
| 40 | //// CHATTY CHAT CHAT STUFF!!!! |
| 41 | function appendMessage(sender, message, isMarkdown) { |
| 42 | const chatContainer = document.getElementById('bot-message') |
| 43 | const messageDiv = document.createElement('div') |
| 44 | messageDiv.classList.add('message') |
| 45 | // Optionally set z-index here if necessary |
| 46 | messageDiv.style.position = 'relative'; |
| 47 | |
| 48 | if (sender === 'User') { |
| 49 | const userContentContainer = document.createElement('div') |
| 50 | userContentContainer.classList.add('user-content-container') |
| 51 | const userIcon = document.createElement('div') |
| 52 | userIcon.classList.add('user-icon') |
| 53 | userIcon.style.marginTop = '10px' |
| 54 | |
| 55 | const userBubble = document.createElement('div') |
| 56 | userBubble.classList.add('user-bubble') |
| 57 | userBubble.innerHTML = `<strong>${message}</strong>` |
| 58 | |
| 59 | userContentContainer.appendChild(userIcon) |
| 60 | userContentContainer.appendChild(userBubble) |
| 61 | messageDiv.appendChild(userContentContainer) |
| 62 | } else if (sender === 'Bot') { |
| 63 | const botIcon = document.createElement('div') |
| 64 | botIcon.classList.add('bot-icon') |
| 65 | botIcon.style.marginTop = '10px' |
| 66 | |
| 67 | const botContentContainer = document.createElement('div') |
| 68 | botContentContainer.classList.add('bot-content-container') |
| 69 | botContentContainer.appendChild(botIcon) |
| 70 | |
| 71 | const botBubble = document.createElement('div') |
| 72 | botBubble.classList.add('bot-bubble') |
| 73 | if (isMarkdown) { |
| 74 | botBubble.innerHTML = marked(message); |
| 75 | // Check if MathJax is loaded and then typeset |
| 76 | if (window.MathJax) { |
| 77 | MathJax.typesetPromise([botBubble]).then(() => { |
| 78 | console.log("MathJax has finished processing!"); |
| 79 | }).catch((err) => console.error('MathJax processing error:', err)); |
| 80 | } else { |
| 81 | console.log("MathJax is not available to process the content."); |
| 82 | } |
| 83 | } else { |
| 84 | botBubble.innerText = message; |
| 85 | } |
| 86 | |
| 87 | const ttsButton = document.createElement('button') |
| 88 | ttsButton.classList.add('tts-button') |
| 89 | ttsButton.style.position = 'relative'; |
| 90 | ttsButton.style.zIndex = '1000'; // Set sufficiently high within context |
| 91 | |
| 92 | const speakerIcon = document.createElementNS( |
| 93 | 'http://www.w3.org/2000/svg', |
| 94 | 'svg' |
| 95 | ); |
| 96 | speakerIcon.setAttribute('class', 'tts-icon'); |
| 97 | speakerIcon.setAttribute('viewBox', '0 0 24 24'); |
| 98 | speakerIcon.style.width = '16px'; |
no test coverage detected