-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
41 lines (38 loc) · 1.31 KB
/
script.js
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
const messagelogs = document.querySelector(".chatlogs");
const button = document.querySelector("#button_send");
const create_message = (msg) => {
const msgcreate = document.createElement("div");
msgcreate.innerHTML = `<div class="chat self">
<div class="user-photo"><img src="img/avatar.png"></div>
<p class="chat-message">${msg.toString()}</p>
</div>`;
messagelogs.appendChild(msgcreate);
(async () => {
await fetch(`https://ai-bot-website.notsaksh.repl.co/api?message=${msg}`)
.then(async function(response) { return response.json(); })
.then(function(json) {
console.log(json.message);
const bot_message = document.createElement("div");
bot_message.innerHTML = `<div class="chat friend">
<div class="user-photo"><img src="img/avatar.png"></div>
<p class="chat-message">${json.message.toString()}</p>
</div>`;
messagelogs.appendChild(bot_message);
});
})()
}
button.addEventListener("click", function() {
send()
})
document.querySelector('#msgcontent').addEventListener('keypress', function (e) {
if (e.key === 'Enter') {
send()
}
});
function send() {
const msgdiv = document.getElementById("msgcontent");
const msgcontent = document.getElementById("msgcontent").value;
if(msgcontent == "") return;
create_message(msgcontent);
msgdiv.value = "";
}