forked from Definehack/Define25
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
231 lines (219 loc) · 7.31 KB
/
index.html
File metadata and controls
231 lines (219 loc) · 7.31 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>FinTech FAQ Chatbot</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 600px;
margin: 20px auto;
background: #121212;
color: white;
}
#chatbox {
height: 400px;
overflow-y: auto;
padding: 15px;
background: #191919;
border-radius: 5px;
}
.message {
margin: 10px 0;
padding: 8px;
border-radius: 3px;
word-wrap: break-word;
line-height: 1.5;
}
.user {
background: #121212;
color: #ffffff;
text-align: right;
border: 1px solid #333;
}
.bot {
background: #121212;
text-align: left;
border: 1px solid #333;
overflow: hidden;
}
.bot b { /* Style for bold text */
font-weight: bold;
color: #ffffff; /* Ensure visibility on dark background */
}
/* Expanding animation for the bot message container */
@keyframes expandBox {
from { max-height: 0; }
to { max-height: 1000px; }
}
.bot.animating {
animation: expandBox 1s ease-out forwards;
max-height: 0;
}
.bot span.numbered {
display: block;
margin-left: 20px;
}
.input-container {
margin-top: 15px;
display: flex;
gap: 10px;
}
#input {
flex: 1;
padding: 8px;
border-radius: 4px;
background: #232323;
color: white;
}
button {
padding: 8px 15px;
background: #8662C2;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
button:hover { background: #6739B7; }
/* Loading Animation (Three Bouncing Dots) */
.loading-animation {
display: flex;
align-items: center;
justify-content: flex-start;
margin: 10px 0;
padding: 8px;
background: #121212;
color: #ffffff;
border-radius: 3px;
border: 1px solid #333;
}
.dots-container {
display: flex;
gap: 4px;
}
.dot {
width: 8px;
height: 8px;
background-color: #ffffff;
border-radius: 50%;
animation: bounce 1.4s infinite ease-in-out both;
}
.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes bounce {
0%, 80%, 100% { transform: scale(0); }
40% { transform: scale(1); }
}
/* Line-by-line text reveal animation */
.bot .line {
opacity: 0;
transform: translateY(10px);
animation: reveal 0.5s forwards;
display: block;
white-space: pre-wrap;
}
@keyframes reveal {
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<h1>FinBot</h1>
<div id="chatbox"></div>
<div class="input-container">
<input type="text" id="input" placeholder="Ask a finance question...">
<button onclick="sendMessage()">Send</button>
</div>
<script>
const chatbox = document.getElementById('chatbox');
const input = document.getElementById('input');
let loadingAnimation = null;
function addUserMessage(message) {
const div = document.createElement('div');
div.className = 'message user';
div.textContent = message;
chatbox.appendChild(div);
chatbox.scrollTop = chatbox.scrollHeight;
}
function showLoadingAnimation() {
loadingAnimation = document.createElement('div');
loadingAnimation.className = 'loading-animation';
const dotsContainer = document.createElement('div');
dotsContainer.className = 'dots-container';
for (let i = 0; i < 3; i++) {
const dot = document.createElement('div');
dot.className = 'dot';
dotsContainer.appendChild(dot);
}
loadingAnimation.appendChild(dotsContainer);
chatbox.appendChild(loadingAnimation);
chatbox.scrollTop = chatbox.scrollHeight;
}
function hideLoadingAnimation() {
if (loadingAnimation && loadingAnimation.parentNode) {
loadingAnimation.parentNode.removeChild(loadingAnimation);
loadingAnimation = null;
}
}
function addBotMessageAnimated(message) {
hideLoadingAnimation();
const div = document.createElement('div');
div.className = 'message bot animating';
const lines = message.split('\n');
const lineCount = lines.length;
const totalDuration = 0.2 * lineCount + 0.5;
div.style.animationDuration = `${totalDuration}s`;
lines.forEach((line, index) => {
const span = document.createElement('span');
span.className = 'line';
span.style.animationDelay = `${index * 0.2}s`;
if (/^\d+\.\s/.test(line)) {
span.classList.add('numbered');
}
span.innerHTML = line; // Use innerHTML to render <b> tags
div.appendChild(span);
});
chatbox.appendChild(div);
const scrollInterval = setInterval(() => {
chatbox.scrollTop = chatbox.scrollHeight;
}, 100);
setTimeout(() => {
clearInterval(scrollInterval);
chatbox.scrollTop = chatbox.scrollHeight;
}, totalDuration * 1000 + 100);
}
async function sendMessage() {
const message = input.value.trim();
if (!message) return;
addUserMessage(`You: ${message}`);
input.value = '';
input.disabled = true;
showLoadingAnimation();
try {
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message })
});
if (!response.ok) throw new Error('Network response was not ok');
const data = await response.json();
addBotMessageAnimated(data.response);
} catch (error) {
addBotMessageAnimated('FinBot:\nSorry, something went wrong!');
console.error('Client Error:', error);
} finally {
input.disabled = false;
input.focus();
}
}
input.addEventListener('keypress', (e) => {
if (e.key === 'Enter') sendMessage();
});
// Initial greeting
setTimeout(() => {
addBotMessageAnimated('FinBot:\nHello! I can help with finance questions.\nTry asking about stocks, investing, or interest!');
}, 500);
</script>
</body>
</html>