Update static/index.html
Browse files- static/index.html +378 -487
static/index.html
CHANGED
@@ -1,533 +1,424 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<!-- Coding By CodingNepal - www.codingnepalweb.com -->
|
3 |
<html lang="en" dir="ltr">
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
|
12 |
-
* {
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
}
|
18 |
-
:root {
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
}
|
28 |
-
.light-mode {
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
}
|
38 |
-
body {
|
39 |
-
|
40 |
-
}
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
}
|
48 |
-
|
49 |
-
|
50 |
-
}
|
51 |
-
:where(.chat-container, textarea)::-webkit-scrollbar-track {
|
52 |
-
background: var(--incoming-chat-bg);
|
53 |
-
border-radius: 25px;
|
54 |
-
}
|
55 |
-
:where(.chat-container, textarea)::-webkit-scrollbar-thumb {
|
56 |
-
background: var(--icon-color);
|
57 |
-
border-radius: 25px;
|
58 |
-
}
|
59 |
-
.default-text {
|
60 |
-
display: flex;
|
61 |
-
align-items: center;
|
62 |
-
justify-content: center;
|
63 |
-
flex-direction: column;
|
64 |
-
height: 70vh;
|
65 |
-
padding: 0 10px;
|
66 |
-
text-align: center;
|
67 |
-
color: var(--text-color);
|
68 |
-
}
|
69 |
-
.default-text h1 {
|
70 |
-
font-size: 3.3rem;
|
71 |
-
}
|
72 |
-
.default-text p {
|
73 |
-
margin-top: 10px;
|
74 |
-
font-size: 1.1rem;
|
75 |
-
}
|
76 |
-
.chat-container .chat {
|
77 |
-
padding: 25px 10px;
|
78 |
-
display: flex;
|
79 |
-
justify-content: center;
|
80 |
-
color: var(--text-color);
|
81 |
-
}
|
82 |
-
.chat-container .chat.outgoing {
|
83 |
-
background: var(--outgoing-chat-bg);
|
84 |
-
border: 1px solid var(--outgoing-chat-border);
|
85 |
-
}
|
86 |
-
.chat-container .chat.incoming {
|
87 |
-
background: var(--incoming-chat-bg);
|
88 |
-
border: 1px solid var(--incoming-chat-border);
|
89 |
-
}
|
90 |
-
.chat .chat-content {
|
91 |
-
display: flex;
|
92 |
-
max-width: 1200px;
|
93 |
-
width: 100%;
|
94 |
-
align-items: flex-start;
|
95 |
-
justify-content: space-between;
|
96 |
-
}
|
97 |
-
span.material-symbols-rounded {
|
98 |
-
user-select: none;
|
99 |
-
cursor: pointer;
|
100 |
-
}
|
101 |
-
.chat .chat-content span {
|
102 |
-
cursor: pointer;
|
103 |
-
font-size: 1.3rem;
|
104 |
-
color: var(--icon-color);
|
105 |
-
visibility: hidden;
|
106 |
-
}
|
107 |
-
.chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
108 |
-
visibility: visible;
|
109 |
-
}
|
110 |
-
.chat .chat-details {
|
111 |
-
display: flex;
|
112 |
-
align-items: center;
|
113 |
-
}
|
114 |
-
.chat .chat-details img {
|
115 |
-
width: 35px;
|
116 |
-
height: 35px;
|
117 |
-
align-self: flex-start;
|
118 |
-
object-fit: cover;
|
119 |
-
border-radius: 2px;
|
120 |
-
}
|
121 |
-
.chat .chat-details p {
|
122 |
-
white-space: pre-wrap;
|
123 |
-
font-size: 1.05rem;
|
124 |
-
padding: 0 50px 0 25px;
|
125 |
-
color: var(--text-color);
|
126 |
-
word-break: break-word;
|
127 |
-
}
|
128 |
-
.chat .chat-details p.error {
|
129 |
-
color: #e55865;
|
130 |
-
}
|
131 |
-
.chat .typing-animation {
|
132 |
-
padding-left: 25px;
|
133 |
-
display: inline-flex;
|
134 |
-
}
|
135 |
-
.typing-animation .typing-dot {
|
136 |
-
height: 7px;
|
137 |
-
width: 7px;
|
138 |
-
border-radius: 50%;
|
139 |
-
margin: 0 3px;
|
140 |
-
opacity: 0.7;
|
141 |
-
background: var(--text-color);
|
142 |
-
animation: animateDots 1.5s var(--delay) ease-in-out infinite;
|
143 |
-
}
|
144 |
-
.typing-animation .typing-dot:first-child {
|
145 |
-
margin-left: 0;
|
146 |
-
}
|
147 |
-
@keyframes animateDots {
|
148 |
-
0%,
|
149 |
-
44% {
|
150 |
-
transform: translateY(0px);
|
151 |
-
}
|
152 |
-
28% {
|
153 |
-
opacity: 0.4;
|
154 |
-
transform: translateY(-6px);
|
155 |
-
}
|
156 |
-
44% {
|
157 |
-
opacity: 0.2;
|
158 |
-
}
|
159 |
-
}
|
160 |
-
|
161 |
-
/* Typing container styling */
|
162 |
-
.typing-container {
|
163 |
-
position: fixed;
|
164 |
-
bottom: 0;
|
165 |
-
width: 100%;
|
166 |
-
display: flex;
|
167 |
-
padding: 20px 10px;
|
168 |
-
justify-content: center;
|
169 |
-
background: var(--outgoing-chat-bg);
|
170 |
-
border-top: 1px solid var(--incoming-chat-border);
|
171 |
-
}
|
172 |
-
.typing-container .typing-content {
|
173 |
-
display: flex;
|
174 |
-
max-width: 950px;
|
175 |
-
width: 100%;
|
176 |
-
align-items: flex-end;
|
177 |
-
}
|
178 |
-
.typing-container .typing-textarea {
|
179 |
-
width: 100%;
|
180 |
-
display: flex;
|
181 |
-
position: relative;
|
182 |
-
}
|
183 |
-
.typing-textarea textarea {
|
184 |
-
resize: none;
|
185 |
-
height: 55px;
|
186 |
-
width: 100%;
|
187 |
-
border: none;
|
188 |
-
padding: 15px 45px 15px 20px;
|
189 |
-
color: var(--text-color);
|
190 |
-
font-size: 1rem;
|
191 |
-
border-radius: 4px;
|
192 |
-
max-height: 250px;
|
193 |
-
overflow-y: auto;
|
194 |
-
background: var(--incoming-chat-bg);
|
195 |
-
outline: 1px solid var(--incoming-chat-border);
|
196 |
-
}
|
197 |
-
.typing-textarea textarea::placeholder {
|
198 |
-
color: var(--placeholder-color);
|
199 |
-
}
|
200 |
-
.typing-content span {
|
201 |
-
width: 55px;
|
202 |
-
height: 55px;
|
203 |
-
display: flex;
|
204 |
-
border-radius: 4px;
|
205 |
-
font-size: 1.35rem;
|
206 |
-
align-items: center;
|
207 |
-
justify-content: center;
|
208 |
-
color: var(--icon-color);
|
209 |
-
}
|
210 |
-
.typing-textarea span {
|
211 |
-
position: absolute;
|
212 |
-
right: 0;
|
213 |
-
bottom: 0;
|
214 |
-
visibility: hidden;
|
215 |
-
}
|
216 |
-
.typing-textarea textarea:valid ~ span {
|
217 |
-
visibility: visible;
|
218 |
-
}
|
219 |
-
.typing-controls {
|
220 |
-
display: flex;
|
221 |
-
}
|
222 |
-
.typing-controls span {
|
223 |
-
margin-left: 7px;
|
224 |
-
font-size: 1.4rem;
|
225 |
-
background: var(--incoming-chat-bg);
|
226 |
-
outline: 1px solid var(--incoming-chat-border);
|
227 |
-
}
|
228 |
-
.typing-controls span:hover {
|
229 |
-
background: var(--icon-hover-bg);
|
230 |
-
}
|
231 |
-
|
232 |
-
/* Reponsive Media Query */
|
233 |
-
@media screen and (max-width: 600px) {
|
234 |
-
.default-text h1 {
|
235 |
-
font-size: 2.3rem;
|
236 |
-
}
|
237 |
-
:where(.default-text p, textarea, .chat p) {
|
238 |
-
font-size: 0.95rem!important;
|
239 |
-
}
|
240 |
-
.chat-container .chat {
|
241 |
-
padding: 20px 10px;
|
242 |
-
}
|
243 |
-
.chat-container .chat img {
|
244 |
-
height: 32px;
|
245 |
-
width: 32px;
|
246 |
-
}
|
247 |
-
.chat-container .chat p {
|
248 |
-
padding: 0 20px;
|
249 |
-
}
|
250 |
-
.chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
251 |
-
visibility: visible;
|
252 |
-
}
|
253 |
-
.typing-container {
|
254 |
-
padding: 15px 10px;
|
255 |
-
}
|
256 |
-
.typing-textarea textarea {
|
257 |
-
height: 45px;
|
258 |
-
padding: 10px 40px 10px 10px;
|
259 |
-
}
|
260 |
-
.typing-content span {
|
261 |
-
height: 45px;
|
262 |
-
width: 45px;
|
263 |
-
margin-left: 5px;
|
264 |
-
}
|
265 |
-
span.material-symbols-rounded {
|
266 |
-
font-size: 1.25rem!important;
|
267 |
-
}
|
268 |
-
}
|
269 |
-
/* New CSS style for "Text Copied" message */
|
270 |
-
.copied-message {
|
271 |
-
font-size: 0.5rem;
|
272 |
-
}
|
273 |
-
.message-box {
|
274 |
-
height: calc(50vh - 5rem);
|
275 |
overflow-y: auto;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
}
|
277 |
-
|
278 |
-
|
|
|
|
|
|
|
|
|
279 |
position: fixed;
|
280 |
bottom: 0;
|
281 |
-
height: 5rem;
|
282 |
width: 100%;
|
283 |
display: flex;
|
284 |
-
|
285 |
justify-content: center;
|
286 |
-
|
287 |
-
|
288 |
}
|
289 |
-
.
|
290 |
-
background-color: #494b59;
|
291 |
-
border-radius: 5px;
|
292 |
-
width: 60vw;
|
293 |
-
padding: 10px;
|
294 |
display: flex;
|
295 |
-
|
296 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
}
|
298 |
-
.
|
|
|
|
|
299 |
width: 100%;
|
300 |
-
padding: 5px;
|
301 |
border: none;
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
|
|
|
|
|
|
|
|
306 |
}
|
307 |
-
.
|
308 |
-
color:
|
309 |
}
|
310 |
-
.
|
|
|
|
|
311 |
display: flex;
|
|
|
|
|
312 |
align-items: center;
|
313 |
justify-content: center;
|
314 |
-
|
315 |
-
border: none;
|
316 |
-
color: #fff;
|
317 |
-
cursor: pointer;
|
318 |
}
|
319 |
-
.
|
320 |
-
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
322 |
}
|
323 |
-
|
324 |
display: flex;
|
325 |
-
gap: 20px;
|
326 |
-
padding: 25px;
|
327 |
-
color: #fff;
|
328 |
-
font-size: 15px;
|
329 |
-
font-weight: 300;
|
330 |
}
|
331 |
-
.
|
332 |
-
|
333 |
-
|
|
|
|
|
|
|
|
|
|
|
334 |
}
|
335 |
-
|
336 |
-
|
|
|
|
|
337 |
}
|
338 |
-
.
|
339 |
-
|
340 |
-
}
|
341 |
-
.
|
342 |
-
|
343 |
-
}
|
344 |
-
|
345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
346 |
</style>
|
347 |
</head>
|
348 |
<body>
|
349 |
-
<div class="
|
350 |
-
<
|
351 |
-
|
352 |
-
|
353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
</div>
|
355 |
-
|
356 |
-
|
357 |
-
<div class="chat-container"></div>
|
358 |
-
|
359 |
-
<!-- Typing container -->
|
360 |
-
<div class="typing-container">
|
361 |
-
<div class="typing-content">
|
362 |
-
<div class="typing-textarea">
|
363 |
-
<textarea id="chat-input" spellcheck="false" placeholder="Enter a prompt here" required></textarea>
|
364 |
-
<span id="send-btn" class="material-symbols-rounded">send</span>
|
365 |
-
</div>
|
366 |
-
<div class="typing-controls">
|
367 |
-
<span id="theme-btn" class="material-symbols-rounded">light_mode</span>
|
368 |
-
<span id="delete-btn" class="material-symbols-rounded">delete</span>
|
369 |
-
|
370 |
-
</div>
|
371 |
</div>
|
372 |
</div>
|
373 |
</div>
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
const
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
436 |
}
|
437 |
|
438 |
-
|
439 |
-
|
440 |
-
const userHtml = `<div class="chat-content">
|
441 |
-
<div class="chat-details">
|
442 |
-
<img src="img/user.jpg">
|
443 |
-
<p>${userMessage}</p>
|
444 |
-
</div>
|
445 |
-
</div>`;
|
446 |
|
447 |
-
|
448 |
-
|
449 |
-
chatContainer.appendChild(outgoingChatDiv);
|
450 |
-
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
451 |
|
452 |
-
|
|
|
|
|
453 |
|
454 |
-
|
455 |
-
|
456 |
-
<img src="img/chatbot.jpg"><span class="new">...</span>
|
457 |
-
<p contenteditable="false" class="copy-text">${botResponse}</p>
|
458 |
-
</div>
|
459 |
-
<span class="material-symbols-rounded copy-icon">content_copy</span>
|
460 |
-
</div>`;
|
461 |
|
462 |
-
|
463 |
-
chatContainer.appendChild(incomingChatDiv);
|
464 |
-
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
465 |
|
466 |
-
|
467 |
-
|
468 |
-
localStorage.setItem("all-chats", chatContainer.innerHTML);
|
469 |
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
copyIcon.addEventListener("click", () => {
|
474 |
-
const textToCopy = copyIcon.previousElementSibling.textContent;
|
475 |
-
navigator.clipboard.writeText(textToCopy);
|
476 |
-
copyIcon.textContent = "Copied";
|
477 |
-
copyIcon.classList.add("copied-text"); // Add the class for smaller text
|
478 |
-
|
479 |
-
setTimeout(() => {
|
480 |
-
copyIcon.textContent = "content_copy";
|
481 |
-
}, 1000);
|
482 |
-
});
|
483 |
-
});
|
484 |
-
}
|
485 |
|
486 |
-
|
487 |
-
|
488 |
-
const userMessage = chatInput.value.trim();
|
489 |
-
if (!userMessage) return;
|
490 |
|
491 |
-
|
492 |
-
|
|
|
|
|
493 |
|
494 |
-
|
|
|
|
|
|
|
495 |
}
|
|
|
496 |
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
deleteButton.addEventListener("click", () => {
|
501 |
-
localStorage.removeItem("all-chats");
|
502 |
-
loadDataFromLocalStorage();
|
503 |
-
});
|
504 |
-
|
505 |
-
themeButton.addEventListener("click", () => {
|
506 |
-
document.body.classList.toggle("light-mode");
|
507 |
-
localStorage.setItem("themeColor", themeButton.innerText);
|
508 |
-
themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
|
509 |
-
});
|
510 |
-
|
511 |
-
// Initial input height calculation
|
512 |
-
const initialInputHeight = chatInput.scrollHeight;
|
513 |
-
|
514 |
-
chatInput.addEventListener("input", () => {
|
515 |
-
chatInput.style.height = `${initialInputHeight}px`;
|
516 |
-
chatInput.style.height = `${chatInput.scrollHeight}px`;
|
517 |
-
});
|
518 |
-
|
519 |
-
chatInput.addEventListener("keydown", (e) => {
|
520 |
-
if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
|
521 |
-
e.preventDefault();
|
522 |
-
handleOutgoingChat();
|
523 |
-
}
|
524 |
-
});
|
525 |
-
|
526 |
-
// Load data from localStorage on page load
|
527 |
-
loadDataFromLocalStorage();
|
528 |
-
</script>
|
529 |
-
</body>
|
530 |
</html>
|
531 |
-
|
532 |
-
|
533 |
-
|
|
|
1 |
<!DOCTYPE html>
|
|
|
2 |
<html lang="en" dir="ltr">
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<!-- Google Fonts Link For Icons -->
|
7 |
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
|
8 |
+
<style>
|
9 |
+
/* Import Google font - Poppins */
|
10 |
+
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap');
|
11 |
+
* {
|
12 |
+
margin: 0;
|
13 |
+
padding: 0;
|
14 |
+
box-sizing: border-box;
|
15 |
+
font-family: "Poppins", sans-serif;
|
16 |
+
}
|
17 |
+
:root {
|
18 |
+
--text-color: #FFFFFF;
|
19 |
+
--icon-color: #ACACBE;
|
20 |
+
--icon-hover-bg: #5b5e71;
|
21 |
+
--placeholder-color: #dcdcdc;
|
22 |
+
--outgoing-chat-bg: #343541;
|
23 |
+
--incoming-chat-bg: #444654;
|
24 |
+
--outgoing-chat-border: #343541;
|
25 |
+
--incoming-chat-border: #444654;
|
26 |
+
}
|
27 |
+
.light-mode {
|
28 |
+
--text-color: #343541;
|
29 |
+
--icon-color: #a9a9bc;
|
30 |
+
--icon-hover-bg: #f1f1f3;
|
31 |
+
--placeholder-color: #6c6c6c;
|
32 |
+
--outgoing-chat-bg: #FFFFFF;
|
33 |
+
--incoming-chat-bg: #F7F7F8;
|
34 |
+
--outgoing-chat-border: #FFFFFF;
|
35 |
+
--incoming-chat-border: #D9D9E3;
|
36 |
+
}
|
37 |
+
body {
|
38 |
+
background: var(--outgoing-chat-bg);
|
39 |
+
}
|
40 |
+
.top-bar {
|
41 |
+
background: var(--outgoing-chat-bg);
|
42 |
+
border-bottom: 1px solid var(--incoming-chat-border);
|
43 |
+
padding: 10px;
|
44 |
+
text-align: center;
|
45 |
+
color: var(--text-color);
|
46 |
+
}
|
47 |
+
/* Chats container styling */
|
48 |
+
.chat-container {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
overflow-y: auto;
|
50 |
+
max-height: 100vh;
|
51 |
+
padding-bottom: 150px;
|
52 |
+
}
|
53 |
+
:where(.chat-container, textarea)::-webkit-scrollbar {
|
54 |
+
width: 6px;
|
55 |
+
}
|
56 |
+
:where(.chat-container, textarea)::-webkit-scrollbar-track {
|
57 |
+
background: var(--incoming-chat-bg);
|
58 |
+
border-radius: 25px;
|
59 |
+
}
|
60 |
+
:where(.chat-container, textarea)::-webkit-scrollbar-thumb {
|
61 |
+
background: var(--icon-color);
|
62 |
+
border-radius: 25px;
|
63 |
+
}
|
64 |
+
.default-text {
|
65 |
+
display: flex;
|
66 |
+
align-items: center;
|
67 |
+
justify-content: center;
|
68 |
+
flex-direction: column;
|
69 |
+
height: 70vh;
|
70 |
+
padding: 0 10px;
|
71 |
+
text-align: center;
|
72 |
+
color: var(--text-color);
|
73 |
+
}
|
74 |
+
.default-text h1 {
|
75 |
+
font-size: 3.3rem;
|
76 |
+
}
|
77 |
+
.default-text p {
|
78 |
+
margin-top: 10px;
|
79 |
+
font-size: 1.1rem;
|
80 |
+
}
|
81 |
+
.chat-container .chat {
|
82 |
+
padding: 25px 10px;
|
83 |
+
display: flex;
|
84 |
+
justify-content: center;
|
85 |
+
color: var(--text-color);
|
86 |
+
position: relative;
|
87 |
+
}
|
88 |
+
.chat-container .chat.outgoing {
|
89 |
+
background: var(--outgoing-chat-bg);
|
90 |
+
border: 1px solid var(--outgoing-chat-border);
|
91 |
+
}
|
92 |
+
.chat-container .chat.incoming {
|
93 |
+
background: var(--incoming-chat-bg);
|
94 |
+
border: 1px solid var(--incoming-chat-border);
|
95 |
+
}
|
96 |
+
.chat .chat-content {
|
97 |
+
display: flex;
|
98 |
+
max-width: 1200px;
|
99 |
+
width: 100%;
|
100 |
+
align-items: flex-start;
|
101 |
+
justify-content: space-between;
|
102 |
+
}
|
103 |
+
span.material-symbols-rounded {
|
104 |
+
user-select: none;
|
105 |
+
cursor: pointer;
|
106 |
+
}
|
107 |
+
.chat .chat-content span {
|
108 |
+
cursor: pointer;
|
109 |
+
font-size: 1.3rem;
|
110 |
+
color: var(--icon-color);
|
111 |
+
visibility: hidden;
|
112 |
+
}
|
113 |
+
.chat:hover .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
114 |
+
visibility: visible;
|
115 |
+
}
|
116 |
+
.chat .chat-details {
|
117 |
+
display: flex;
|
118 |
+
align-items: center;
|
119 |
+
}
|
120 |
+
.chat .chat-details img {
|
121 |
+
width: 35px;
|
122 |
+
height: 35px;
|
123 |
+
align-self: flex-start;
|
124 |
+
object-fit: cover;
|
125 |
+
border-radius: 2px;
|
126 |
+
}
|
127 |
+
.chat .chat-details p {
|
128 |
+
white-space: pre-wrap;
|
129 |
+
font-size: 1.05rem;
|
130 |
+
padding: 0 50px 0 25px;
|
131 |
+
color: var(--text-color);
|
132 |
+
word-break: break-word;
|
133 |
+
}
|
134 |
+
.chat .chat-details p.error {
|
135 |
+
color: #e55865;
|
136 |
+
}
|
137 |
+
.chat .typing-animation {
|
138 |
+
padding-left: 25px;
|
139 |
+
display: inline-flex;
|
140 |
+
}
|
141 |
+
.typing-animation .typing-dot {
|
142 |
+
height: 7px;
|
143 |
+
width: 7px;
|
144 |
+
border-radius: 50%;
|
145 |
+
margin: 0 3px;
|
146 |
+
opacity: 0.7;
|
147 |
+
background: var(--text-color);
|
148 |
+
animation: animateDots 1.5s var(--delay) ease-in-out infinite;
|
149 |
+
}
|
150 |
+
.typing-animation .typing-dot:first-child {
|
151 |
+
margin-left: 0;
|
152 |
+
}
|
153 |
+
@keyframes animateDots {
|
154 |
+
0%,
|
155 |
+
44% {
|
156 |
+
transform: translateY(0px);
|
157 |
+
}
|
158 |
+
28% {
|
159 |
+
opacity: 0.4;
|
160 |
+
transform: translateY(-6px);
|
161 |
}
|
162 |
+
44% {
|
163 |
+
opacity: 0.2;
|
164 |
+
}
|
165 |
+
}
|
166 |
+
/* Typing container styling */
|
167 |
+
.typing-container {
|
168 |
position: fixed;
|
169 |
bottom: 0;
|
|
|
170 |
width: 100%;
|
171 |
display: flex;
|
172 |
+
padding: 20px 10px;
|
173 |
justify-content: center;
|
174 |
+
background: var(--outgoing-chat-bg);
|
175 |
+
border-top: 1px solid var(--incoming-chat-border);
|
176 |
}
|
177 |
+
.typing-container .typing-content {
|
|
|
|
|
|
|
|
|
178 |
display: flex;
|
179 |
+
max-width: 950px;
|
180 |
+
width: 100%;
|
181 |
+
align-items: flex-end;
|
182 |
+
}
|
183 |
+
.typing-container .typing-textarea {
|
184 |
+
width: 100%;
|
185 |
+
display: flex;
|
186 |
+
position: relative;
|
187 |
}
|
188 |
+
.typing-textarea textarea {
|
189 |
+
resize: none;
|
190 |
+
height: 55px;
|
191 |
width: 100%;
|
|
|
192 |
border: none;
|
193 |
+
padding: 15px 45px 15px 20px;
|
194 |
+
color: var(--text-color);
|
195 |
+
font-size: 1rem;
|
196 |
+
border-radius: 4px;
|
197 |
+
max-height: 250px;
|
198 |
+
overflow-y: auto;
|
199 |
+
background: var(--incoming-chat-bg);
|
200 |
+
outline: 1px solid var(--incoming-chat-border);
|
201 |
}
|
202 |
+
.typing-textarea textarea::placeholder {
|
203 |
+
color: var(--placeholder-color);
|
204 |
}
|
205 |
+
.typing-content span {
|
206 |
+
width: 55px;
|
207 |
+
height: 55px;
|
208 |
display: flex;
|
209 |
+
border-radius: 4px;
|
210 |
+
font-size: 1.35rem;
|
211 |
align-items: center;
|
212 |
justify-content: center;
|
213 |
+
color: var(--icon-color);
|
|
|
|
|
|
|
214 |
}
|
215 |
+
.typing-textarea span {
|
216 |
+
position: absolute;
|
217 |
+
right: 0;
|
218 |
+
bottom: 0;
|
219 |
+
visibility: hidden;
|
220 |
+
}
|
221 |
+
.typing-textarea textarea:valid ~ span {
|
222 |
+
visibility: visible;
|
223 |
}
|
224 |
+
.typing-controls {
|
225 |
display: flex;
|
|
|
|
|
|
|
|
|
|
|
226 |
}
|
227 |
+
.typing-controls span {
|
228 |
+
margin-left: 7px;
|
229 |
+
font-size: 1.4rem;
|
230 |
+
background: var(--incoming-chat-bg);
|
231 |
+
outline: 1px solid var(--incoming-chat-border);
|
232 |
+
}
|
233 |
+
.typing-controls span:hover {
|
234 |
+
background: var(--icon-hover-bg);
|
235 |
}
|
236 |
+
/* Reponsive Media Query */
|
237 |
+
@media screen and (max-width: 600px) {
|
238 |
+
.default-text h1 {
|
239 |
+
font-size: 2.3rem;
|
240 |
}
|
241 |
+
:where(.default-text p, textarea, .chat p) {
|
242 |
+
font-size: 0.95rem!important;
|
243 |
+
}
|
244 |
+
.chat-container .chat {
|
245 |
+
padding: 20px 10px;
|
246 |
+
}
|
247 |
+
.chat-container .chat img {
|
248 |
+
height: 32px;
|
249 |
+
width: 32px;
|
250 |
+
}
|
251 |
+
.chat-container .chat p {
|
252 |
+
padding: 0 20px;
|
253 |
+
}
|
254 |
+
.chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
255 |
+
visibility: visible;
|
256 |
+
}
|
257 |
+
.typing-container {
|
258 |
+
padding: 15px 10px;
|
259 |
+
}
|
260 |
+
.typing-container .typing-content {
|
261 |
+
max-width: 100%;
|
262 |
+
}
|
263 |
+
.typing-controls span {
|
264 |
+
margin-left: 5px;
|
265 |
+
font-size: 1.2rem;
|
266 |
+
}
|
267 |
+
.typing-textarea textarea {
|
268 |
+
padding: 14px 45px 14px 15px;
|
269 |
+
font-size: 0.95rem;
|
270 |
+
}
|
271 |
+
}
|
272 |
</style>
|
273 |
</head>
|
274 |
<body>
|
275 |
+
<div class="top-bar">
|
276 |
+
<h1>Chat Application</h1>
|
277 |
+
</div>
|
278 |
+
<div class="chat-container">
|
279 |
+
<div class="default-text">
|
280 |
+
<h1>ChatGPT</h1>
|
281 |
+
<p>Start a conversation with the AI assistant.</p>
|
282 |
+
</div>
|
283 |
+
</div>
|
284 |
+
<div class="typing-container">
|
285 |
+
<div class="typing-content">
|
286 |
+
<div class="typing-textarea">
|
287 |
+
<textarea spellcheck="false" placeholder="Type your message.."></textarea>
|
288 |
+
<span class="material-symbols-rounded">send</span>
|
289 |
</div>
|
290 |
+
<div class="typing-controls">
|
291 |
+
<span class="material-symbols-rounded">dark_mode</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
</div>
|
293 |
</div>
|
294 |
</div>
|
295 |
+
<script>
|
296 |
+
const textarea = document.querySelector("textarea"),
|
297 |
+
chatContainer = document.querySelector(".chat-container"),
|
298 |
+
sendChatBtn = document.querySelector("span.material-symbols-rounded"),
|
299 |
+
toggleIcon = document.querySelector(".typing-controls span"),
|
300 |
+
defaultText = document.querySelector(".default-text");
|
301 |
+
|
302 |
+
let userMessage = null;
|
303 |
+
|
304 |
+
toggleIcon.onclick = () => {
|
305 |
+
document.body.classList.toggle("light-mode");
|
306 |
+
};
|
307 |
+
|
308 |
+
const createTypingAnimation = () => {
|
309 |
+
const html = `
|
310 |
+
<div class="chat-content">
|
311 |
+
<div class="chat-details">
|
312 |
+
<img src="bot.png" alt="">
|
313 |
+
<div class="typing-animation">
|
314 |
+
<div class="typing-dot" style="--delay: 0s"></div>
|
315 |
+
<div class="typing-dot" style="--delay: 0.15s"></div>
|
316 |
+
<div class="typing-dot" style="--delay: 0.3s"></div>
|
317 |
+
</div>
|
318 |
+
</div>
|
319 |
+
</div>`;
|
320 |
+
const incomingChat = document.createElement("div");
|
321 |
+
incomingChat.classList.add("chat", "incoming");
|
322 |
+
incomingChat.innerHTML = html;
|
323 |
+
return incomingChat;
|
324 |
+
};
|
325 |
+
|
326 |
+
const generateResponse = (chatElement) => {
|
327 |
+
const API_URL = "https://api.openai.com/v1/engines/davinci-codex/completions";
|
328 |
+
const API_KEY = "YOUR_OPENAI_API_KEY";
|
329 |
+
|
330 |
+
const requestOptions = {
|
331 |
+
method: "POST",
|
332 |
+
headers: {
|
333 |
+
"Content-Type": "application/json",
|
334 |
+
"Authorization": `Bearer ${API_KEY}`
|
335 |
+
},
|
336 |
+
body: JSON.stringify({
|
337 |
+
prompt: userMessage,
|
338 |
+
max_tokens: 1000
|
339 |
+
})
|
340 |
+
};
|
341 |
+
|
342 |
+
fetch(API_URL, requestOptions).then(res => res.json()).then(data => {
|
343 |
+
chatElement.querySelector(".typing-animation").remove();
|
344 |
+
const pElement = document.createElement("p");
|
345 |
+
pElement.textContent = data.choices[0].text.trim();
|
346 |
+
chatElement.querySelector(".chat-details").appendChild(pElement);
|
347 |
+
}).catch(() => {
|
348 |
+
chatElement.querySelector(".typing-animation").remove();
|
349 |
+
const pElement = document.createElement("p");
|
350 |
+
pElement.classList.add("error");
|
351 |
+
pElement.textContent = "Oops! Something went wrong. Please try again.";
|
352 |
+
chatElement.querySelector(".chat-details").appendChild(pElement);
|
353 |
+
}).finally(() => chatContainer.scrollTo(0, chatContainer.scrollHeight));
|
354 |
+
};
|
355 |
+
|
356 |
+
const copyMessage = (element) => {
|
357 |
+
navigator.clipboard.writeText(element.innerText);
|
358 |
+
};
|
359 |
+
|
360 |
+
const createChatElement = (message, className) => {
|
361 |
+
const chatElement = document.createElement("div");
|
362 |
+
chatElement.classList.add("chat", className);
|
363 |
+
|
364 |
+
const html = `
|
365 |
+
<div class="chat-content">
|
366 |
+
<div class="chat-details">
|
367 |
+
<img src="${className === "outgoing" ? "user.png" : "bot.png"}" alt="">
|
368 |
+
<p>${message}</p>
|
369 |
+
</div>
|
370 |
+
<span class="material-symbols-rounded">content_copy</span>
|
371 |
+
${className === "outgoing" ? '<span class="material-symbols-rounded">edit</span>' : ''}
|
372 |
+
</div>`;
|
373 |
+
chatElement.innerHTML = html;
|
374 |
+
|
375 |
+
if (className === "outgoing") {
|
376 |
+
const editIcon = chatElement.querySelector(".material-symbols-rounded:nth-child(3)");
|
377 |
+
editIcon.addEventListener("click", () => {
|
378 |
+
textarea.value = message;
|
379 |
+
chatElement.remove();
|
380 |
+
textarea.focus();
|
381 |
+
});
|
382 |
}
|
383 |
|
384 |
+
const copyIcon = chatElement.querySelector(".material-symbols-rounded:nth-child(2)");
|
385 |
+
copyIcon.addEventListener("click", () => copyMessage(chatElement.querySelector("p")));
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
|
387 |
+
return chatElement;
|
388 |
+
};
|
|
|
|
|
389 |
|
390 |
+
const handleChat = () => {
|
391 |
+
userMessage = textarea.value.trim();
|
392 |
+
if (!userMessage) return;
|
393 |
|
394 |
+
textarea.value = "";
|
395 |
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
|
|
|
|
|
|
|
|
|
|
396 |
|
397 |
+
if (!chatContainer.querySelector(".chat")) defaultText.style.display = "none";
|
|
|
|
|
398 |
|
399 |
+
chatContainer.appendChild(createChatElement(userMessage, "outgoing"));
|
400 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
|
|
401 |
|
402 |
+
const incomingChat = createTypingAnimation();
|
403 |
+
chatContainer.appendChild(incomingChat);
|
404 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
405 |
|
406 |
+
generateResponse(incomingChat);
|
407 |
+
};
|
|
|
|
|
408 |
|
409 |
+
textarea.addEventListener("input", () => {
|
410 |
+
textarea.style.height = "auto";
|
411 |
+
textarea.style.height = `${textarea.scrollHeight}px`;
|
412 |
+
});
|
413 |
|
414 |
+
textarea.addEventListener("keydown", (e) => {
|
415 |
+
if (e.key === "Enter" && !e.shiftKey) {
|
416 |
+
e.preventDefault();
|
417 |
+
handleChat();
|
418 |
}
|
419 |
+
});
|
420 |
|
421 |
+
sendChatBtn.addEventListener("click", handleChat);
|
422 |
+
</script>
|
423 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
</html>
|
|
|
|
|
|