-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
187 lines (163 loc) · 5.26 KB
/
index.html
File metadata and controls
187 lines (163 loc) · 5.26 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
document.addEventListener('DOMContentLoaded', () => {
// Create styles
const style = document.createElement('style');
style.textContent = `
body, html {
margin: 0;
padding: 0;
font-family: 'Arial', sans-serif;
height: 100%;
background-color: #f4f7f6;
}
.chatbot-button {
position: fixed;
bottom: 20px;
right: 20px;
width: 60px;
height: 60px;
border-radius: 50%;
background-color: #007bff;
color: #fff;
border: none;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
cursor: pointer;
font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
}
.chatbot-iframe {
display: none;
position: fixed;
bottom: 90px;
right: 20px;
width: 300px;
height: 400px;
border: none;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
border-radius: 8px;
}
.chatbot-container {
position: fixed;
bottom: 90px;
right: 20px;
width: 300px;
height: 400px;
border: none;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
border-radius: 8px;
background-color: white;
display: none;
flex-direction: column;
}
.chatbot-header {
padding: 10px;
background-color: #007bff;
color: white;
text-align: center;
border-top-left-radius: 8px;
border-top-right-radius: 8px;
}
.chatbox {
flex: 1;
padding: 10px;
overflow-y: auto;
}
.input-container {
display: flex;
justify-content: space-between;
padding: 10px;
background-color: #fff;
border-top: 1px solid #ddd;
}
.input-container input {
flex: 1;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
margin-right: 10px;
}
.input-container button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 4px;
cursor: pointer;
}
.input-container button:hover {
background-color: #0056b3;
}
.chat-message {
padding: 10px;
margin: 10px;
border-radius: 4px;
}
.chat-message.user {
background-color: #007bff;
color: #fff;
align-self: flex-end;
}
`;
document.head.appendChild(style);
// Create chatbot button
const chatbotButton = document.createElement('button');
chatbotButton.className = 'chatbot-button';
chatbotButton.innerHTML = '💬';
chatbotButton.onclick = toggleChatbot;
document.body.appendChild(chatbotButton);
// Create chatbot container
const chatbotContainer = document.createElement('div');
chatbotContainer.className = 'chatbot-container';
document.body.appendChild(chatbotContainer);
// Create chatbot header
const chatbotHeader = document.createElement('div');
chatbotHeader.className = 'chatbot-header';
chatbotHeader.textContent = 'AI Chatbot';
chatbotContainer.appendChild(chatbotHeader);
// Create chatbox
const chatbox = document.createElement('div');
chatbox.className = 'chatbox';
chatbox.id = 'chatbox';
chatbotContainer.appendChild(chatbox);
// Create input container
const inputContainer = document.createElement('div');
inputContainer.className = 'input-container';
chatbotContainer.appendChild(inputContainer);
// Create input field
const userInput = document.createElement('input');
userInput.type = 'text';
userInput.id = 'userInput';
userInput.placeholder = 'Type a message...!';
userInput.onkeypress = handleKeyPress;
inputContainer.appendChild(userInput);
// Create send button
const sendButton = document.createElement('button');
sendButton.textContent = 'Send';
sendButton.onclick = sendMessage;
inputContainer.appendChild(sendButton);
// Toggle chatbot visibility
function toggleChatbot() {
chatbotContainer.style.display = chatbotContainer.style.display === 'none' ? 'flex' : 'none';
}
// Send message function
window.sendMessage = function() {
const userInput = document.getElementById('userInput').value;
if (userInput.trim() === '') return;
// Display user message
const userMessage = document.createElement('div');
userMessage.className = 'chat-message user';
userMessage.textContent = userInput;
chatbox.appendChild(userMessage);
// Clear input
document.getElementById('userInput').value = '';
// Scroll to the bottom of the chatbox
chatbox.scrollTop = chatbox.scrollHeight;
};
// Handle key press event
window.handleKeyPress = function(event) {
if (event.key === 'Enter') {
sendMessage();
}
};
});