Commit def9f82c authored by Thathsarani R.P.H.S.R's avatar Thathsarani R.P.H.S.R

Create js files.

parent debd3363
function updateEmotionTable(emotionPercentages) {
var tableBody = document.querySelector("#emotion-table tbody");
tableBody.innerHTML = "";
for (var emotion in emotionPercentages) {
var row = tableBody.insertRow();
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
cell1.textContent = emotion;
cell2.textContent = emotionPercentages[emotion] + "%";
}
}
function updateStressLevel(stressLevel) {
var stressLevelElement = document.querySelector("#stress-level");
stressLevelElement.textContent = stressLevel;
}
function startCounselling() {
window.location.href = '/process_route';
}
function resetCounselling() {
var xhr = new XMLHttpRequest();
xhr.open("POST", "/reset", true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
// Redirect to the login page after resetting
window.location.href = '/login';
}
};
xhr.send();
}
const eventSource = new EventSource('/stream');
const conversationElement = document.getElementById("conversation");
eventSource.onmessage = function (event) {
const newMessage = event.data.trim(); // Trim any leading/trailing whitespace
if (newMessage) {
// Append the new message to the conversation list
appendMessageToConversation(newMessage);
}
};
function toggleRecords() {
const recordsElement = document.querySelector(".previous-stress-level");
recordsElement.classList.toggle("expanded");
}
function appendMessageToConversation(message) {
const conversationList = document.querySelector("#conversation ul");
const messageElement = document.createElement("li");
messageElement.classList.add("message");
messageElement.textContent = message;
conversationList.insertBefore(messageElement, conversationList.firstChild);
}
function togglePreviousRecords() {
const previousRecords = document.getElementById("previous-records");
if (previousRecords.style.display === "block") {
previousRecords.style.display = "none";
} else {
previousRecords.style.display = "block";
}
}
\ No newline at end of file
document.addEventListener("DOMContentLoaded", function () {
// Get a reference to the conversation <div> element
const conversationDiv = document.getElementById("conversation");
// Function to add a message to the conversation
function addMessageToConversation(message, sender) {
// Create a <p> element for the message
const messageElement = document.createElement("p");
// Set the text content based on the sender
if (sender === "User") {
messageElement.textContent = "User: " + message;
} else {
messageElement.textContent = "zenBot: " + message;
}
// Append the <p> element to the conversation <div>
conversationDiv.appendChild(messageElement);
// Scroll the conversation <div> to the bottom to show the latest message
conversationDiv.scrollTop = conversationDiv.scrollHeight;
}
// Display a welcome message when the page loads
addMessageToConversation("Welcome to the Chat !", "zenBot");
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment