Update public/chat.html
Browse files- public/chat.html +44 -34
public/chat.html
CHANGED
|
@@ -73,42 +73,52 @@
|
|
| 73 |
|
| 74 |
// Add a message to the chat box
|
| 75 |
function addMessageToChat(msg) {
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
// Load chat messages
|
| 114 |
async function loadMessages() {
|
|
|
|
| 73 |
|
| 74 |
// Add a message to the chat box
|
| 75 |
function addMessageToChat(msg) {
|
| 76 |
+
const messageDiv = document.createElement('div');
|
| 77 |
+
messageDiv.style = `
|
| 78 |
+
max-width: 70%;
|
| 79 |
+
padding: 10px;
|
| 80 |
+
border-radius: 8px;
|
| 81 |
+
background-color: ${msg.sender === 'You' ? '#4caf50' : '#2c2c2c'};
|
| 82 |
+
color: #ffffff;
|
| 83 |
+
align-self: ${msg.sender === 'You' ? 'flex-end' : 'flex-start'};
|
| 84 |
+
word-wrap: break-word;
|
| 85 |
+
cursor: pointer;
|
| 86 |
+
`;
|
| 87 |
+
|
| 88 |
+
// Add reply thumbnail if applicable
|
| 89 |
+
if (msg.replyTo) {
|
| 90 |
+
const replyDiv = document.createElement('div');
|
| 91 |
+
replyDiv.style = `
|
| 92 |
+
margin-bottom: 8px;
|
| 93 |
+
padding: 5px;
|
| 94 |
+
border-left: 4px solid #888;
|
| 95 |
+
font-size: 0.85rem;
|
| 96 |
+
color: #bbb;
|
| 97 |
+
`;
|
| 98 |
+
replyDiv.textContent = msg.replyTo;
|
| 99 |
+
messageDiv.appendChild(replyDiv);
|
| 100 |
+
}
|
| 101 |
|
| 102 |
+
// Add image if available
|
| 103 |
+
if (msg.imageUrl) {
|
| 104 |
+
const img = document.createElement('img');
|
| 105 |
+
img.src = msg.imageUrl;
|
| 106 |
+
img.alt = 'Image';
|
| 107 |
+
img.style = 'max-width: 100%; border-radius: 8px; margin-top: 10px;';
|
| 108 |
+
messageDiv.appendChild(img);
|
| 109 |
+
}
|
| 110 |
|
| 111 |
+
// Add sender and content
|
| 112 |
+
messageDiv.innerHTML += `<strong>${msg.sender}</strong><br>${msg.content || ''}`;
|
| 113 |
+
messageDiv.addEventListener('click', () => {
|
| 114 |
+
replyTo = msg.content;
|
| 115 |
+
replyPreview.textContent = `Replying to: ${msg.content}`;
|
| 116 |
+
replyPreview.style.display = 'block';
|
| 117 |
+
});
|
| 118 |
+
|
| 119 |
+
chatBox.appendChild(messageDiv);
|
| 120 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
| 121 |
+
}
|
| 122 |
|
| 123 |
// Load chat messages
|
| 124 |
async function loadMessages() {
|