-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchat-demo.html
More file actions
297 lines (253 loc) · 8.61 KB
/
chat-demo.html
File metadata and controls
297 lines (253 loc) · 8.61 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Demo</title>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap" rel="stylesheet">
<style>
body {
margin: 0;
background-color: #1f2325;
font-family: 'Poppins', sans-serif;
color: #d6deeb;
display: flex;
flex-direction: column;
height: 100vh;
overflow: hidden;
}
#chat-container {
flex: 1;
padding: 20px;
display: flex;
flex-direction: column;
gap: 15px;
overflow-y: auto;
scroll-behavior: smooth;
}
.message {
display: flex;
flex-direction: row;
max-width: 85%;
opacity: 0;
transform: translateY(10px);
animation: fadeIn 0.3s forwards;
gap: 8px;
}
@keyframes fadeIn {
to {
opacity: 1;
transform: translateY(0);
}
}
.message.user {
align-self: flex-end;
align-items: flex-end;
}
.message.others {
align-self: flex-start;
align-items: flex-end;
}
.avatar {
width: 30px;
min-width: 30px;
height: 30px;
border-radius: 50%;
background-color: #333;
/* margin-bottom: 5px; */
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
font-weight: bold;
color: #fff;
}
.avatar.user {
background-color: #00dc68;
color: #1f2325;
}
.avatar.helper1 {
background-color: #f78c6c;
}
.avatar.helper2 {
background-color: #82aaff;
}
.bubble {
padding: 10px 15px;
border-radius: 12px;
font-size: 14px;
line-height: 1.4;
position: relative;
word-wrap: break-word;
}
.message.user .bubble {
background-color: #00dc68;
color: #003719;
border-bottom-right-radius: 2px;
}
.message.others .bubble {
background-color: #2c3033;
color: #d6deeb;
border-bottom-left-radius: 2px;
}
.bubble a {
color: #82aaff;
text-decoration: underline;
}
.message.user .bubble a {
color: #003719;
font-weight: 600;
}
/* Code Block Styling */
.code-block {
background-color: #111;
padding: 8px;
border-radius: 6px;
font-family: 'Consolas', 'Monaco', monospace;
font-size: 12px;
margin-top: 5px;
color: #d6deeb;
white-space: pre-wrap;
border: 1px solid #444;
}
.message.user .code-block {
background-color: #003719;
/* Dark green bg for code in user bubble */
color: #a3f7bf;
border-color: #005c2a;
}
.syntax-kw {
color: #c792ea;
}
.syntax-str {
color: #ecc48d;
}
.syntax-fn {
color: #82aaff;
}
.syntax-comment {
color: #637777;
font-style: italic;
}
/* Scrollbar */
::-webkit-scrollbar {
width: 8px;
}
::-webkit-scrollbar-track {
background: #1f2325;
}
::-webkit-scrollbar-thumb {
background: #333;
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: #444;
}
</style>
</head>
<body>
<div id="chat-container"></div>
<script>
const container = document.getElementById('chat-container');
const messages = [
{
type: 'user',
name: 'Markus',
content: 'Hey, I tried this code but it doesn\'t work:',
code: `import gint\ngint.dclear(gint.C_WHITE)\ngint.dtext("Hello", 10, 10, gint.C_BLACK)\n# Nothing happens on screen :/`
},
{
type: 'others',
id: 'helper1',
name: 'Dante',
content: 'You forgot <code>gint.dupdate()</code>! The screen buffer isn\'t flushed to the display automatically.',
delay: 2000
},
{
type: 'others',
id: 'helper3',
name: 'John',
content: 'Check this: <a href="https://classpaddev.github.io/wiki/python/reference/gint/#dupdate---none" target="_blank">gint.dupdate() Reference</a>',
delay: 3500
},
{
type: 'others',
id: 'helper2',
name: 'Phoebe',
content: 'Yeah, drawing operations only update VRAM. You need to push it to the screen. See: <a href="https://classpaddev.github.io/wiki/python/examples/rectangle/#wait-what-is-a-pixel" target="_blank">Wait, what is a pixel?</a>',
delay: 5500
},
{
type: 'user',
name: 'Me',
content: 'Ah, I see! Thanks guys, it works now.',
delay: 8000
}
];
// Render Logic
function createMessageElement(msg) {
const wrapper = document.createElement('div');
wrapper.className = `message ${msg.type}`;
const avatar = document.createElement('div');
avatar.className = `avatar ${msg.type === 'user' ? 'user' : msg.id}`;
avatar.innerText = msg.name[0];
const contentDiv = document.createElement('div');
contentDiv.style.display = 'flex';
contentDiv.style.flexDirection = 'column';
contentDiv.style.maxWidth = '100%';
if (msg.type === 'others') {
// Name label
const nameLabel = document.createElement('span');
nameLabel.style.fontSize = '11px';
nameLabel.style.color = '#888';
nameLabel.style.marginLeft = '10px';
nameLabel.style.marginBottom = '2px';
nameLabel.innerText = msg.name;
contentDiv.appendChild(nameLabel);
}
const bubble = document.createElement('div');
bubble.className = 'bubble';
bubble.innerHTML = msg.content;
if (msg.code) {
const codeBlock = document.createElement('div');
codeBlock.className = 'code-block';
// Simple syntax highlighting
codeBlock.innerHTML = msg.code
// .replace(/import|gint/g, '<span class="syntax-kw">$&</span>')
// .replace(/"(.*?)"/g, '<span class="syntax-str">"$1"</span>')
// .replace(/dclear|dtext/g, '<span class="syntax-fn">$&</span>')
// .replace(/#.*/g, '<span class="syntax-comment">$&</span>');
bubble.appendChild(codeBlock);
}
contentDiv.appendChild(bubble);
if (msg.type === 'others') {
wrapper.appendChild(avatar);
wrapper.appendChild(contentDiv);
} else {
wrapper.appendChild(contentDiv);
wrapper.appendChild(avatar);
}
return wrapper;
}
function startSequence() {
container.innerHTML = '';
messages.forEach((msg, index) => {
// Use the 'delay' property as the timestamp for when this message should appear
// Defaulting to a cascade if not precise (but we set precise delays in array)
const appearTime = msg.delay !== undefined ? msg.delay : index * 2000;
setTimeout(() => {
const el = createMessageElement(msg);
container.appendChild(el);
container.scrollTop = container.scrollHeight; // Auto scroll
// If it's the last message, schedule reset
if (index === messages.length - 1) {
setTimeout(startSequence, 60000); // Reset after 60s
}
}, appearTime);
});
}
// Start
startSequence();
</script>
</body>
</html>