Update static/index.html
Browse files- static/index.html +131 -83
static/index.html
CHANGED
@@ -27,6 +27,7 @@
|
|
27 |
--outgoing-chat-border: #343541;
|
28 |
--incoming-chat-border: #444654;
|
29 |
}
|
|
|
30 |
.light-mode {
|
31 |
--text-color: #343541;
|
32 |
--icon-color: #a9a9bc;
|
@@ -37,6 +38,7 @@
|
|
37 |
--outgoing-chat-border: #FFFFFF;
|
38 |
--incoming-chat-border: #D9D9E3;
|
39 |
}
|
|
|
40 |
body {
|
41 |
background: var(--outgoing-chat-bg);
|
42 |
}
|
@@ -47,17 +49,21 @@ body {
|
|
47 |
max-height: 100vh;
|
48 |
padding-bottom: 150px;
|
49 |
}
|
|
|
50 |
:where(.chat-container, textarea)::-webkit-scrollbar {
|
51 |
width: 6px;
|
52 |
}
|
|
|
53 |
:where(.chat-container, textarea)::-webkit-scrollbar-track {
|
54 |
background: var(--incoming-chat-bg);
|
55 |
border-radius: 25px;
|
56 |
}
|
|
|
57 |
:where(.chat-container, textarea)::-webkit-scrollbar-thumb {
|
58 |
background: var(--icon-color);
|
59 |
border-radius: 25px;
|
60 |
}
|
|
|
61 |
.default-text {
|
62 |
display: flex;
|
63 |
align-items: center;
|
@@ -68,27 +74,33 @@ body {
|
|
68 |
text-align: center;
|
69 |
color: var(--text-color);
|
70 |
}
|
|
|
71 |
.default-text h1 {
|
72 |
font-size: 3.3rem;
|
73 |
}
|
|
|
74 |
.default-text p {
|
75 |
margin-top: 10px;
|
76 |
font-size: 1.1rem;
|
77 |
}
|
|
|
78 |
.chat-container .chat {
|
79 |
padding: 25px 10px;
|
80 |
display: flex;
|
81 |
justify-content: center;
|
82 |
color: var(--text-color);
|
83 |
}
|
|
|
84 |
.chat-container .chat.outgoing {
|
85 |
background: var(--outgoing-chat-bg);
|
86 |
border: 1px solid var(--outgoing-chat-border);
|
87 |
}
|
|
|
88 |
.chat-container .chat.incoming {
|
89 |
background: var(--incoming-chat-bg);
|
90 |
border: 1px solid var(--incoming-chat-border);
|
91 |
}
|
|
|
92 |
.chat .chat-content {
|
93 |
display: flex;
|
94 |
max-width: 1200px;
|
@@ -96,25 +108,31 @@ body {
|
|
96 |
align-items: flex-start;
|
97 |
justify-content: space-between;
|
98 |
}
|
|
|
99 |
.chat .chat-content span {
|
100 |
cursor: pointer;
|
101 |
font-size: 1.3rem;
|
102 |
color: var(--icon-color);
|
103 |
}
|
|
|
104 |
.chat .chat-content .icons {
|
105 |
display: flex;
|
106 |
visibility: hidden;
|
107 |
}
|
|
|
108 |
.chat:hover .chat-content .icons {
|
109 |
visibility: visible;
|
110 |
}
|
|
|
111 |
.chat .chat-content span:not(:last-child) {
|
112 |
margin-right: 10px;
|
113 |
}
|
|
|
114 |
.chat .chat-details {
|
115 |
display: flex;
|
116 |
align-items: center;
|
117 |
}
|
|
|
118 |
.chat .chat-details img {
|
119 |
width: 35px;
|
120 |
height: 35px;
|
@@ -122,6 +140,7 @@ body {
|
|
122 |
object-fit: cover;
|
123 |
border-radius: 2px;
|
124 |
}
|
|
|
125 |
.chat .chat-details p {
|
126 |
white-space: pre-wrap;
|
127 |
font-size: 1.05rem;
|
@@ -129,10 +148,12 @@ body {
|
|
129 |
color: var(--text-color);
|
130 |
word-break: break-word;
|
131 |
}
|
|
|
132 |
.chat .typing-animation {
|
133 |
padding-left: 25px;
|
134 |
display: inline-flex;
|
135 |
}
|
|
|
136 |
.typing-animation .typing-dot {
|
137 |
height: 7px;
|
138 |
width: 7px;
|
@@ -142,24 +163,29 @@ body {
|
|
142 |
background: var(--text-color);
|
143 |
animation: animateDots 1.5s var(--delay) ease-in-out infinite;
|
144 |
}
|
|
|
145 |
.typing-animation .typing-dot:first-child {
|
146 |
margin-left: 0;
|
147 |
}
|
|
|
148 |
@keyframes animateDots {
|
149 |
0%,
|
150 |
44% {
|
151 |
transform: translateY(0px);
|
152 |
}
|
|
|
153 |
28% {
|
154 |
opacity: 0.4;
|
155 |
transform: translateY(-6px);
|
156 |
}
|
|
|
157 |
44% {
|
158 |
opacity: 0.2;
|
159 |
}
|
160 |
}
|
161 |
|
162 |
/* Typing container styling */
|
|
|
163 |
.typing-container {
|
164 |
position: fixed;
|
165 |
bottom: 0;
|
@@ -170,17 +196,20 @@ body {
|
|
170 |
background: var(--outgoing-chat-bg);
|
171 |
border-top: 1px solid var(--incoming-chat-border);
|
172 |
}
|
|
|
173 |
.typing-container .typing-content {
|
174 |
display: flex;
|
175 |
max-width: 950px;
|
176 |
width: 100%;
|
177 |
align-items: flex-end;
|
178 |
}
|
|
|
179 |
.typing-container .typing-textarea {
|
180 |
width: 100%;
|
181 |
display: flex;
|
182 |
position: relative;
|
183 |
}
|
|
|
184 |
.typing-textarea textarea {
|
185 |
resize: none;
|
186 |
height: 55px;
|
@@ -195,9 +224,11 @@ body {
|
|
195 |
background: var(--incoming-chat-bg);
|
196 |
outline: 1px solid var(--incoming-chat-border);
|
197 |
}
|
|
|
198 |
.typing-textarea textarea::placeholder {
|
199 |
color: var(--placeholder-color);
|
200 |
}
|
|
|
201 |
.typing-content span {
|
202 |
width: 55px;
|
203 |
height: 55px;
|
@@ -208,63 +239,78 @@ body {
|
|
208 |
justify-content: center;
|
209 |
color: var(--icon-color);
|
210 |
}
|
|
|
211 |
.typing-textarea span {
|
212 |
position: absolute;
|
213 |
right: 0;
|
214 |
bottom: 0;
|
215 |
visibility: hidden;
|
216 |
}
|
|
|
217 |
.typing-textarea textarea:valid ~ span {
|
218 |
visibility: visible;
|
219 |
}
|
|
|
220 |
.typing-controls {
|
221 |
display: flex;
|
222 |
}
|
|
|
223 |
.typing-controls span {
|
224 |
margin-left: 7px;
|
225 |
font-size: 1.4rem;
|
226 |
background: var(--incoming-chat-bg);
|
227 |
outline: 1px solid var(--incoming-chat-border);
|
228 |
}
|
|
|
229 |
.typing-controls span:hover {
|
230 |
background: var(--icon-hover-bg);
|
231 |
}
|
232 |
|
233 |
/* Reponsive Media Query */
|
|
|
234 |
@media screen and (max-width: 600px) {
|
235 |
.default-text h1 {
|
236 |
font-size: 2.3rem;
|
237 |
}
|
|
|
238 |
:where(.default-text p, textarea, .chat p) {
|
239 |
-
font-size: 0.95rem!important;
|
240 |
}
|
|
|
241 |
.chat-container .chat {
|
242 |
padding: 20px 10px;
|
243 |
}
|
|
|
244 |
.chat-container .chat img {
|
245 |
height: 32px;
|
246 |
width: 32px;
|
247 |
}
|
|
|
248 |
.chat-container .chat p {
|
249 |
padding: 0 20px;
|
250 |
}
|
|
|
251 |
.chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
252 |
visibility: visible;
|
253 |
}
|
|
|
254 |
.typing-container {
|
255 |
padding: 15px 10px;
|
256 |
}
|
|
|
257 |
.typing-textarea textarea {
|
258 |
height: 45px;
|
259 |
padding: 10px 40px 10px 10px;
|
260 |
}
|
|
|
261 |
.typing-content span {
|
262 |
height: 45px;
|
263 |
width: 45px;
|
264 |
margin-left: 5px;
|
265 |
}
|
|
|
266 |
span.material-symbols-rounded {
|
267 |
-
font-size: 1.25rem!important;
|
268 |
}
|
269 |
}
|
270 |
</style>
|
@@ -283,8 +329,10 @@ body {
|
|
283 |
<div class="typing-controls">
|
284 |
<span id="theme-btn" class="material-symbols-rounded">light_mode</span>
|
285 |
<span id="delete-btn" class="material-symbols-rounded">delete</span>
|
|
|
286 |
</div>
|
287 |
</div>
|
|
|
288 |
<script>
|
289 |
// Selecting DOM elements
|
290 |
const chatInput = document.querySelector("#chat-input");
|
@@ -301,70 +349,70 @@ let chatHistory = [];
|
|
301 |
|
302 |
// Load data from localStorage on page load
|
303 |
const loadDataFromLocalStorage = () => {
|
304 |
-
|
305 |
|
306 |
-
|
307 |
-
|
308 |
|
309 |
-
|
310 |
-
|
311 |
}
|
312 |
|
313 |
// Function to create a chat message element
|
314 |
const createChatElement = (content, className) => {
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
}
|
320 |
|
321 |
// Function to fetch bot response from API
|
322 |
const getChatResponse = async (message) => {
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
}
|
342 |
-
|
343 |
-
const data = await response.json();
|
344 |
-
return data.response;
|
345 |
-
} catch (error) {
|
346 |
-
console.error("Error fetching data:", error);
|
347 |
-
return "Oops! Something went wrong while fetching the response.";
|
348 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
}
|
350 |
|
351 |
// Function to display user message and bot response
|
352 |
const showResponse = async (userMessage) => {
|
353 |
-
|
354 |
<div class="chat-details">
|
355 |
<img src="img/user.jpg">
|
356 |
<p>${userMessage}</p>
|
357 |
</div>
|
358 |
</div>`;
|
359 |
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
|
365 |
-
|
366 |
|
367 |
-
|
368 |
<div class="chat-details">
|
369 |
<img src="img/chatbot.jpg">
|
370 |
<p>${botResponse}</p>
|
@@ -376,50 +424,50 @@ const showResponse = async (userMessage) => {
|
|
376 |
</div>
|
377 |
</div>`;
|
378 |
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
}
|
387 |
|
388 |
// Event listener for sending messages
|
389 |
const handleOutgoingChat = () => {
|
390 |
-
|
391 |
-
|
392 |
|
393 |
-
|
394 |
-
|
395 |
|
396 |
-
|
397 |
}
|
398 |
|
399 |
// Event listeners
|
400 |
sendButton.addEventListener("click", handleOutgoingChat);
|
401 |
|
402 |
deleteButton.addEventListener("click", () => {
|
403 |
-
|
404 |
-
|
405 |
});
|
406 |
|
407 |
themeButton.addEventListener("click", () => {
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
});
|
412 |
|
413 |
chatInput.addEventListener("input", () => {
|
414 |
-
|
415 |
-
|
416 |
});
|
417 |
|
418 |
chatInput.addEventListener("keydown", (e) => {
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
});
|
424 |
|
425 |
// Initial input height calculation
|
@@ -429,32 +477,32 @@ const initialInputHeight = chatInput.scrollHeight;
|
|
429 |
loadDataFromLocalStorage();
|
430 |
|
431 |
// Function to copy bot response to clipboard
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
}
|
437 |
|
438 |
// Function to regenerate bot response
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
element.parentElement.querySelector("p").textContent = newBotResponse;
|
|
|
444 |
}
|
445 |
|
446 |
// Function to undo bot response
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
|
455 |
-
|
456 |
-
|
457 |
}
|
458 |
-
|
459 |
</body>
|
460 |
-
</html>
|
|
|
27 |
--outgoing-chat-border: #343541;
|
28 |
--incoming-chat-border: #444654;
|
29 |
}
|
30 |
+
|
31 |
.light-mode {
|
32 |
--text-color: #343541;
|
33 |
--icon-color: #a9a9bc;
|
|
|
38 |
--outgoing-chat-border: #FFFFFF;
|
39 |
--incoming-chat-border: #D9D9E3;
|
40 |
}
|
41 |
+
|
42 |
body {
|
43 |
background: var(--outgoing-chat-bg);
|
44 |
}
|
|
|
49 |
max-height: 100vh;
|
50 |
padding-bottom: 150px;
|
51 |
}
|
52 |
+
|
53 |
:where(.chat-container, textarea)::-webkit-scrollbar {
|
54 |
width: 6px;
|
55 |
}
|
56 |
+
|
57 |
:where(.chat-container, textarea)::-webkit-scrollbar-track {
|
58 |
background: var(--incoming-chat-bg);
|
59 |
border-radius: 25px;
|
60 |
}
|
61 |
+
|
62 |
:where(.chat-container, textarea)::-webkit-scrollbar-thumb {
|
63 |
background: var(--icon-color);
|
64 |
border-radius: 25px;
|
65 |
}
|
66 |
+
|
67 |
.default-text {
|
68 |
display: flex;
|
69 |
align-items: center;
|
|
|
74 |
text-align: center;
|
75 |
color: var(--text-color);
|
76 |
}
|
77 |
+
|
78 |
.default-text h1 {
|
79 |
font-size: 3.3rem;
|
80 |
}
|
81 |
+
|
82 |
.default-text p {
|
83 |
margin-top: 10px;
|
84 |
font-size: 1.1rem;
|
85 |
}
|
86 |
+
|
87 |
.chat-container .chat {
|
88 |
padding: 25px 10px;
|
89 |
display: flex;
|
90 |
justify-content: center;
|
91 |
color: var(--text-color);
|
92 |
}
|
93 |
+
|
94 |
.chat-container .chat.outgoing {
|
95 |
background: var(--outgoing-chat-bg);
|
96 |
border: 1px solid var(--outgoing-chat-border);
|
97 |
}
|
98 |
+
|
99 |
.chat-container .chat.incoming {
|
100 |
background: var(--incoming-chat-bg);
|
101 |
border: 1px solid var(--incoming-chat-border);
|
102 |
}
|
103 |
+
|
104 |
.chat .chat-content {
|
105 |
display: flex;
|
106 |
max-width: 1200px;
|
|
|
108 |
align-items: flex-start;
|
109 |
justify-content: space-between;
|
110 |
}
|
111 |
+
|
112 |
.chat .chat-content span {
|
113 |
cursor: pointer;
|
114 |
font-size: 1.3rem;
|
115 |
color: var(--icon-color);
|
116 |
}
|
117 |
+
|
118 |
.chat .chat-content .icons {
|
119 |
display: flex;
|
120 |
visibility: hidden;
|
121 |
}
|
122 |
+
|
123 |
.chat:hover .chat-content .icons {
|
124 |
visibility: visible;
|
125 |
}
|
126 |
+
|
127 |
.chat .chat-content span:not(:last-child) {
|
128 |
margin-right: 10px;
|
129 |
}
|
130 |
+
|
131 |
.chat .chat-details {
|
132 |
display: flex;
|
133 |
align-items: center;
|
134 |
}
|
135 |
+
|
136 |
.chat .chat-details img {
|
137 |
width: 35px;
|
138 |
height: 35px;
|
|
|
140 |
object-fit: cover;
|
141 |
border-radius: 2px;
|
142 |
}
|
143 |
+
|
144 |
.chat .chat-details p {
|
145 |
white-space: pre-wrap;
|
146 |
font-size: 1.05rem;
|
|
|
148 |
color: var(--text-color);
|
149 |
word-break: break-word;
|
150 |
}
|
151 |
+
|
152 |
.chat .typing-animation {
|
153 |
padding-left: 25px;
|
154 |
display: inline-flex;
|
155 |
}
|
156 |
+
|
157 |
.typing-animation .typing-dot {
|
158 |
height: 7px;
|
159 |
width: 7px;
|
|
|
163 |
background: var(--text-color);
|
164 |
animation: animateDots 1.5s var(--delay) ease-in-out infinite;
|
165 |
}
|
166 |
+
|
167 |
.typing-animation .typing-dot:first-child {
|
168 |
margin-left: 0;
|
169 |
}
|
170 |
+
|
171 |
@keyframes animateDots {
|
172 |
0%,
|
173 |
44% {
|
174 |
transform: translateY(0px);
|
175 |
}
|
176 |
+
|
177 |
28% {
|
178 |
opacity: 0.4;
|
179 |
transform: translateY(-6px);
|
180 |
}
|
181 |
+
|
182 |
44% {
|
183 |
opacity: 0.2;
|
184 |
}
|
185 |
}
|
186 |
|
187 |
/* Typing container styling */
|
188 |
+
|
189 |
.typing-container {
|
190 |
position: fixed;
|
191 |
bottom: 0;
|
|
|
196 |
background: var(--outgoing-chat-bg);
|
197 |
border-top: 1px solid var(--incoming-chat-border);
|
198 |
}
|
199 |
+
|
200 |
.typing-container .typing-content {
|
201 |
display: flex;
|
202 |
max-width: 950px;
|
203 |
width: 100%;
|
204 |
align-items: flex-end;
|
205 |
}
|
206 |
+
|
207 |
.typing-container .typing-textarea {
|
208 |
width: 100%;
|
209 |
display: flex;
|
210 |
position: relative;
|
211 |
}
|
212 |
+
|
213 |
.typing-textarea textarea {
|
214 |
resize: none;
|
215 |
height: 55px;
|
|
|
224 |
background: var(--incoming-chat-bg);
|
225 |
outline: 1px solid var(--incoming-chat-border);
|
226 |
}
|
227 |
+
|
228 |
.typing-textarea textarea::placeholder {
|
229 |
color: var(--placeholder-color);
|
230 |
}
|
231 |
+
|
232 |
.typing-content span {
|
233 |
width: 55px;
|
234 |
height: 55px;
|
|
|
239 |
justify-content: center;
|
240 |
color: var(--icon-color);
|
241 |
}
|
242 |
+
|
243 |
.typing-textarea span {
|
244 |
position: absolute;
|
245 |
right: 0;
|
246 |
bottom: 0;
|
247 |
visibility: hidden;
|
248 |
}
|
249 |
+
|
250 |
.typing-textarea textarea:valid ~ span {
|
251 |
visibility: visible;
|
252 |
}
|
253 |
+
|
254 |
.typing-controls {
|
255 |
display: flex;
|
256 |
}
|
257 |
+
|
258 |
.typing-controls span {
|
259 |
margin-left: 7px;
|
260 |
font-size: 1.4rem;
|
261 |
background: var(--incoming-chat-bg);
|
262 |
outline: 1px solid var(--incoming-chat-border);
|
263 |
}
|
264 |
+
|
265 |
.typing-controls span:hover {
|
266 |
background: var(--icon-hover-bg);
|
267 |
}
|
268 |
|
269 |
/* Reponsive Media Query */
|
270 |
+
|
271 |
@media screen and (max-width: 600px) {
|
272 |
.default-text h1 {
|
273 |
font-size: 2.3rem;
|
274 |
}
|
275 |
+
|
276 |
:where(.default-text p, textarea, .chat p) {
|
277 |
+
font-size: 0.95rem !important;
|
278 |
}
|
279 |
+
|
280 |
.chat-container .chat {
|
281 |
padding: 20px 10px;
|
282 |
}
|
283 |
+
|
284 |
.chat-container .chat img {
|
285 |
height: 32px;
|
286 |
width: 32px;
|
287 |
}
|
288 |
+
|
289 |
.chat-container .chat p {
|
290 |
padding: 0 20px;
|
291 |
}
|
292 |
+
|
293 |
.chat .chat-content:not(:has(.typing-animation), :has(.error)) span {
|
294 |
visibility: visible;
|
295 |
}
|
296 |
+
|
297 |
.typing-container {
|
298 |
padding: 15px 10px;
|
299 |
}
|
300 |
+
|
301 |
.typing-textarea textarea {
|
302 |
height: 45px;
|
303 |
padding: 10px 40px 10px 10px;
|
304 |
}
|
305 |
+
|
306 |
.typing-content span {
|
307 |
height: 45px;
|
308 |
width: 45px;
|
309 |
margin-left: 5px;
|
310 |
}
|
311 |
+
|
312 |
span.material-symbols-rounded {
|
313 |
+
font-size: 1.25rem !important;
|
314 |
}
|
315 |
}
|
316 |
</style>
|
|
|
329 |
<div class="typing-controls">
|
330 |
<span id="theme-btn" class="material-symbols-rounded">light_mode</span>
|
331 |
<span id="delete-btn" class="material-symbols-rounded">delete</span>
|
332 |
+
</div>
|
333 |
</div>
|
334 |
</div>
|
335 |
+
|
336 |
<script>
|
337 |
// Selecting DOM elements
|
338 |
const chatInput = document.querySelector("#chat-input");
|
|
|
349 |
|
350 |
// Load data from localStorage on page load
|
351 |
const loadDataFromLocalStorage = () => {
|
352 |
+
const themeColor = localStorage.getItem("themeColor");
|
353 |
|
354 |
+
document.body.classList.toggle("light-mode", themeColor === "light_mode");
|
355 |
+
themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
|
356 |
|
357 |
+
chatContainer.innerHTML = localStorage.getItem("all-chats") || '<div class="default-text"><h1>Welcome</h1><p>Start a conversation by typing a message.</p></div>';
|
358 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
359 |
}
|
360 |
|
361 |
// Function to create a chat message element
|
362 |
const createChatElement = (content, className) => {
|
363 |
+
const chatDiv = document.createElement("div");
|
364 |
+
chatDiv.classList.add("chat", className);
|
365 |
+
chatDiv.innerHTML = content;
|
366 |
+
return chatDiv;
|
367 |
}
|
368 |
|
369 |
// Function to fetch bot response from API
|
370 |
const getChatResponse = async (message) => {
|
371 |
+
try {
|
372 |
+
const response = await fetch(API_URL, {
|
373 |
+
method: "POST",
|
374 |
+
headers: {
|
375 |
+
"Content-Type": "application/x-www-form-urlencoded"
|
376 |
+
},
|
377 |
+
body: new URLSearchParams({
|
378 |
+
prompt: message,
|
379 |
+
history: "[]",
|
380 |
+
temperature: "0.9",
|
381 |
+
max_new_tokens: "512",
|
382 |
+
top_p: "0.95",
|
383 |
+
repetition_penalty: "1.0"
|
384 |
+
})
|
385 |
+
});
|
386 |
+
|
387 |
+
if (!response.ok) {
|
388 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
389 |
}
|
390 |
+
|
391 |
+
const data = await response.json();
|
392 |
+
return data.response;
|
393 |
+
} catch (error) {
|
394 |
+
console.error("Error fetching data:", error);
|
395 |
+
return "Oops! Something went wrong while fetching the response.";
|
396 |
+
}
|
397 |
}
|
398 |
|
399 |
// Function to display user message and bot response
|
400 |
const showResponse = async (userMessage) => {
|
401 |
+
const userHtml = `<div class="chat-content">
|
402 |
<div class="chat-details">
|
403 |
<img src="img/user.jpg">
|
404 |
<p>${userMessage}</p>
|
405 |
</div>
|
406 |
</div>`;
|
407 |
|
408 |
+
const outgoingChatDiv = createChatElement(userHtml, "outgoing");
|
409 |
+
chatContainer.querySelector(".default-text")?.remove();
|
410 |
+
chatContainer.appendChild(outgoingChatDiv);
|
411 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
412 |
|
413 |
+
const botResponse = await getChatResponse(userMessage);
|
414 |
|
415 |
+
const botHtml = `<div class="chat-content">
|
416 |
<div class="chat-details">
|
417 |
<img src="img/chatbot.jpg">
|
418 |
<p>${botResponse}</p>
|
|
|
424 |
</div>
|
425 |
</div>`;
|
426 |
|
427 |
+
const incomingChatDiv = createChatElement(botHtml, "incoming");
|
428 |
+
chatContainer.appendChild(incomingChatDiv);
|
429 |
+
chatContainer.scrollTo(0, chatContainer.scrollHeight);
|
430 |
|
431 |
+
// Update chat history
|
432 |
+
chatHistory.push([userMessage, botResponse]);
|
433 |
+
localStorage.setItem("all-chats", chatContainer.innerHTML);
|
434 |
}
|
435 |
|
436 |
// Event listener for sending messages
|
437 |
const handleOutgoingChat = () => {
|
438 |
+
const userMessage = chatInput.value.trim();
|
439 |
+
if (!userMessage) return;
|
440 |
|
441 |
+
chatInput.value = "";
|
442 |
+
chatInput.style.height = `${initialInputHeight}px`;
|
443 |
|
444 |
+
showResponse(userMessage);
|
445 |
}
|
446 |
|
447 |
// Event listeners
|
448 |
sendButton.addEventListener("click", handleOutgoingChat);
|
449 |
|
450 |
deleteButton.addEventListener("click", () => {
|
451 |
+
localStorage.removeItem("all-chats");
|
452 |
+
loadDataFromLocalStorage();
|
453 |
});
|
454 |
|
455 |
themeButton.addEventListener("click", () => {
|
456 |
+
document.body.classList.toggle("light-mode");
|
457 |
+
localStorage.setItem("themeColor", themeButton.innerText);
|
458 |
+
themeButton.innerText = document.body.classList.contains("light-mode") ? "dark_mode" : "light_mode";
|
459 |
});
|
460 |
|
461 |
chatInput.addEventListener("input", () => {
|
462 |
+
chatInput.style.height = `${initialInputHeight}px`;
|
463 |
+
chatInput.style.height = `${chatInput.scrollHeight}px`;
|
464 |
});
|
465 |
|
466 |
chatInput.addEventListener("keydown", (e) => {
|
467 |
+
if (e.key === "Enter" && !e.shiftKey && window.innerWidth > 800) {
|
468 |
+
e.preventDefault();
|
469 |
+
handleOutgoingChat();
|
470 |
+
}
|
471 |
});
|
472 |
|
473 |
// Initial input height calculation
|
|
|
477 |
loadDataFromLocalStorage();
|
478 |
|
479 |
// Function to copy bot response to clipboard
|
480 |
+
function copyToClipboard(element) {
|
481 |
+
const botResponse = element.parentElement.querySelector("p").textContent;
|
482 |
+
navigator.clipboard.writeText(botResponse);
|
483 |
+
alert("Bot response copied to clipboard!");
|
484 |
}
|
485 |
|
486 |
// Function to regenerate bot response
|
487 |
+
function regenerateResponse(element) {
|
488 |
+
const userMessage = element.parentElement.previousElementSibling.textContent;
|
489 |
+
getChatResponse(userMessage).then(newBotResponse => {
|
|
|
490 |
element.parentElement.querySelector("p").textContent = newBotResponse;
|
491 |
+
});
|
492 |
}
|
493 |
|
494 |
// Function to undo bot response
|
495 |
+
function undoResponse(element) {
|
496 |
+
const botResponse = element.parentElement.querySelector("p");
|
497 |
+
const userMessage = element.parentElement.previousElementSibling.textContent;
|
498 |
|
499 |
+
const newBotResponse = chatHistory[chatHistory.length - 1][1];
|
500 |
+
const index = chatHistory.findIndex(message => message[0] === userMessage);
|
501 |
+
chatHistory.splice(index, 1);
|
502 |
|
503 |
+
botResponse.textContent = newBotResponse;
|
504 |
+
localStorage.setItem("all-chats", chatContainer.innerHTML);
|
505 |
}
|
506 |
+
</script>
|
507 |
</body>
|
508 |
+
</html>
|