Spaces:
Sleeping
Sleeping
Update static/index.html
Browse files- static/index.html +49 -34
static/index.html
CHANGED
|
@@ -2,53 +2,68 @@
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
-
<title>Chat
|
| 6 |
<script>
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
userMessageElement.textContent = `You: ${message}`;
|
| 21 |
-
messagesContainer.appendChild(userMessageElement);
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
method: 'GET', // Since it's a GET request, consider how to send data if needed
|
| 30 |
-
});
|
| 31 |
-
const data = await response.json();
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</head>
|
| 44 |
-
<body>
|
| 45 |
-
<h1>Chat</h1>
|
| 46 |
-
<div id="
|
| 47 |
-
<
|
|
|
|
| 48 |
</body>
|
| 49 |
</html>
|
| 50 |
|
| 51 |
|
|
|
|
| 52 |
<!-- ################################################################################################## -->
|
| 53 |
<!-- <!DOCTYPE html>
|
| 54 |
<html lang="en">
|
|
|
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
<meta charset="UTF-8">
|
| 5 |
+
<title>Chat Simulation</title>
|
| 6 |
<script>
|
| 7 |
+
async function fetchAuthToken() {
|
| 8 |
+
try {
|
| 9 |
+
const response = await fetch('/custom-auth');
|
| 10 |
+
const data = await response.json();
|
| 11 |
+
document.getElementById('authToken').textContent = `Auth Token: ${data.token}`;
|
| 12 |
+
} catch (error) {
|
| 13 |
+
console.error('Error:', error);
|
| 14 |
+
}
|
| 15 |
+
}
|
| 16 |
|
| 17 |
+
async function sendMessage() {
|
| 18 |
+
const inputElement = document.getElementById('messageInput');
|
| 19 |
+
const message = inputElement.value;
|
| 20 |
+
if (!message.trim()) return; // Ignore empty messages
|
| 21 |
|
| 22 |
+
// Display the user's message
|
| 23 |
+
displayMessage(`You: ${message}`, 'user');
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
// Simulate sending the message and receiving a response
|
| 26 |
+
// Here, you'd replace this with a call to your actual message processing endpoint
|
| 27 |
+
// Since the provided code does not specify an endpoint for sending messages, this is a placeholder
|
| 28 |
+
const simulatedResponse = "This is a simulated response based on your message.";
|
| 29 |
+
displayMessage(`Server: ${simulatedResponse}`, 'server');
|
| 30 |
|
| 31 |
+
// Clear the input field
|
| 32 |
+
inputElement.value = '';
|
| 33 |
+
}
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
function displayMessage(text, sender) {
|
| 36 |
+
const messagesContainer = document.getElementById('messages');
|
| 37 |
+
const messageElement = document.createElement('p');
|
| 38 |
+
messageElement.textContent = text;
|
| 39 |
+
messageElement.className = sender; // Apply different styling based on the sender
|
| 40 |
+
messagesContainer.appendChild(messageElement);
|
|
|
|
|
|
|
| 41 |
}
|
| 42 |
+
|
| 43 |
+
// Event listener for the Enter key in the message input
|
| 44 |
+
document.addEventListener('DOMContentLoaded', function() {
|
| 45 |
+
document.getElementById('messageInput').addEventListener('keydown', function(event) {
|
| 46 |
+
if (event.key === 'Enter') {
|
| 47 |
+
sendMessage();
|
| 48 |
+
}
|
| 49 |
+
});
|
| 50 |
+
});
|
| 51 |
</script>
|
| 52 |
+
<style>
|
| 53 |
+
.user { color: blue; }
|
| 54 |
+
.server { color: green; }
|
| 55 |
+
</style>
|
| 56 |
</head>
|
| 57 |
+
<body onload="fetchAuthToken()">
|
| 58 |
+
<h1>Simple Chat Simulation</h1>
|
| 59 |
+
<div id="authToken"></div>
|
| 60 |
+
<div id="messages" style="height: 200px; overflow-y: auto; border: 1px solid #ccc; padding: 10px; margin-bottom: 10px;"></div>
|
| 61 |
+
<input type="text" id="messageInput" placeholder="Type your message here and press Enter">
|
| 62 |
</body>
|
| 63 |
</html>
|
| 64 |
|
| 65 |
|
| 66 |
+
|
| 67 |
<!-- ################################################################################################## -->
|
| 68 |
<!-- <!DOCTYPE html>
|
| 69 |
<html lang="en">
|