document.getElementById("message-form").addEventListener("submit", function(event) {
event.preventDefault();
var message = document.getElementById("message-input").value;
chrome.runtime.sendMessage({msg: "sendMessage", message: message}, function(response) {
console.log(response.response);
msg_html = '
'
msg_html += message
msg_html += '
'
document.getElementById("messages").innerHTML += msg_html;
let chatWindow = document.getElementById("chat-container");
chatWindow.scrollTop = chatWindow.scrollHeight;
});
document.getElementById("message-input").value = "";
var conversation_state = localStorage.getItem("conversation_state");
// check if conversation state is null
if (conversation_state == null) {
conversation_state = 0;
localStorage.setItem("conversation_state", conversation_state);
}
// send post request to server http://127.0.0.1:5000/ with message in json body
fetch('http://127.0.0.1:7091/api/answer', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({question: message, history: null}),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
msg_html = '