File size: 8,867 Bytes
5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 ef5fdbc 5a3db39 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Glow Chatbot</title>
<style>
:root {
--neon-color: #0ff;
--bg-color: #0a0a0a;
--text-color: rgba(255,255,255,0.9);
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
background: var(--bg-color);
font-family: 'Courier New', monospace;
color: var(--text-color);
touch-action: manipulation;
height: 100vh;
overflow: hidden;
}
.chat-container {
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
background: radial-gradient(circle at center, #1a1a1a 0%, #0a0a0a 100%);
}
.chat-header {
padding: 1rem;
text-align: center;
background: rgba(0,0,0,0.3);
border-bottom: 2px solid var(--neon-color);
box-shadow: 0 0 15px var(--neon-color);
position: relative;
z-index: 2;
}
.chat-messages {
flex: 1;
overflow-y: auto;
padding: 1rem;
display: flex;
flex-direction: column;
gap: 15px;
-webkit-overflow-scrolling: touch;
}
.message {
max-width: 85%;
padding: 12px 18px;
border-radius: 20px;
position: relative;
animation: messageAppear 0.3s ease;
word-break: break-word;
line-height: 1.4;
}
.user-message {
background: linear-gradient(145deg, #006666, #009999);
align-self: flex-end;
color: white;
border: 1px solid var(--neon-color);
box-shadow: 0 0 10px var(--neon-color);
}
.bot-message {
background: linear-gradient(145deg, #1a1a1a, #2a2a2a);
align-self: flex-start;
border: 1px solid #444;
box-shadow: 0 0 10px rgba(0,255,255,0.2);
}
.input-container {
display: flex;
padding: 1rem;
gap: 10px;
background: rgba(0,0,0,0.5);
border-top: 1px solid var(--neon-color);
position: relative;
z-index: 2;
}
input[type="text"] {
flex: 1;
padding: 15px;
border: none;
border-radius: 25px;
background: rgba(255,255,255,0.1);
color: var(--neon-color);
font-size: 16px;
text-shadow: 0 0 5px var(--neon-color);
caret-color: var(--neon-color);
}
input::placeholder {
color: #4d4d4d;
font-style: italic;
}
button {
background: linear-gradient(145deg, #006666, #009999);
border: none;
padding: 0 25px;
border-radius: 25px;
color: white;
font-weight: bold;
cursor: pointer;
transition: all 0.3s ease;
min-width: 50px;
}
button:active {
transform: scale(0.95);
filter: brightness(1.2);
}
.typing-indicator {
display: inline-flex;
padding: 10px 15px;
background: rgba(0,0,0,0.5);
border-radius: 15px;
gap: 5px;
align-items: center;
}
.typing-dot {
width: 8px;
height: 8px;
background: var(--neon-color);
border-radius: 50%;
animation: typing 1.4s infinite ease-in-out;
}
@keyframes messageAppear {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@keyframes typing {
0%, 100% {
transform: translateY(0);
opacity: 0.5;
}
50% {
transform: translateY(-5px);
opacity: 1;
}
}
/* Scrollbar Styling */
::-webkit-scrollbar {
width: 5px;
}
::-webkit-scrollbar-track {
background: rgba(0,0,0,0.2);
}
::-webkit-scrollbar-thumb {
background: var(--neon-color);
border-radius: 5px;
}
@media (max-width: 480px) {
.message {
max-width: 90%;
padding: 10px 15px;
font-size: 14px;
}
input[type="text"] {
padding: 12px;
font-size: 14px;
}
button {
padding: 0 20px;
font-size: 14px;
}
.typing-dot {
width: 6px;
height: 6px;
}
}
</style>
</head>
<body>
<div class="chat-container">
<div class="chat-header">
<h1 style="color: var(--neon-color); text-shadow: 0 0 10px var(--neon-color); margin: 0;">GLOW CHAT</h1>
</div>
<div class="chat-messages" id="chatMessages">
<!-- Pesan akan muncul di sini -->
</div>
<div class="input-container">
<input type="text" id="userInput" placeholder="Ketik pesan..." autocomplete="off">
<button onclick="sendMessage()">➤</button>
</div>
</div>
<script>
const chatMessages = document.getElementById('chatMessages');
const userInput = document.getElementById('userInput');
let isBotTyping = false;
function createTypingIndicator() {
const container = document.createElement('div');
container.className = 'message bot-message typing-indicator';
for(let i = 0; i < 3; i++) {
const dot = document.createElement('div');
dot.className = 'typing-dot';
dot.style.animationDelay = `${i * 0.2}s`;
container.appendChild(dot);
}
return container;
}
async function sendMessage() {
const message = userInput.value.trim();
if (!message || isBotTyping) return;
// Tambahkan pesan pengguna
const userDiv = document.createElement('div');
userDiv.className = 'message user-message';
userDiv.textContent = message;
chatMessages.appendChild(userDiv);
userInput.value = '';
scrollToBottom();
// Tampilkan typing indicator
isBotTyping = true;
const typingIndicator = createTypingIndicator();
chatMessages.appendChild(typingIndicator);
scrollToBottom();
try {
const response = await fetch('http://localhost:3000/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
const data = await response.json();
// Hapus typing indicator dan tampilkan balasan
typingIndicator.remove();
const botDiv = document.createElement('div');
botDiv.className = 'message bot-message';
botDiv.textContent = data.reply;
chatMessages.appendChild(botDiv);
scrollToBottom();
} catch (error) {
typingIndicator.remove();
const errorDiv = document.createElement('div');
errorDiv.className = 'message bot-message';
errorDiv.textContent = '⚠️ Gagal terhubung ke server';
chatMessages.appendChild(errorDiv);
scrollToBottom();
} finally {
isBotTyping = false;
}
}
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
// Handle keyboard events
userInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault();
sendMessage();
}
});
// Auto-focus input saat halaman dimuat
window.addEventListener('load', () => {
userInput.focus();
});
</script>
</body>
</html> |