AskOscar.herbal.ai / script.js
Askoscar's picture
Upload 5 files
b55a14c verified
raw
history blame
2.63 kB
document.addEventListener("DOMContentLoaded", () => {
const aboutBtn = document.getElementById("aboutBtn");
const donateBtn = document.getElementById("donateBtn");
const aboutModal = document.getElementById("aboutModal");
const donateModal = document.getElementById("donateModal");
const closeAbout = document.getElementById("closeAbout");
const closeDonate = document.getElementById("closeDonate");
const sendBtn = document.getElementById("askButton");
const chatBox = document.getElementById("chat-box");
const input = document.getElementById("userInput");
// open / close modals
aboutBtn.onclick = () => aboutModal.style.display = "block";
donateBtn.onclick = () => donateModal.style.display = "block";
closeAbout.onclick = () => aboutModal.style.display = "none";
closeDonate.onclick = () => donateModal.style.display = "none";
window.onclick = e => {
if (e.target === aboutModal) aboutModal.style.display = "none";
if (e.target === donateModal) donateModal.style.display = "none";
};
// send message
sendBtn.onclick = sendMessage;
input.addEventListener("keydown", e => { if (e.key === "Enter") sendMessage(); });
function appendMessage(who, text) {
const div = document.createElement("div");
div.classList.add("message", who);
div.textContent = (who === "user" ? "🧍 " : "πŸͺ΄ ") + text;
chatBox.appendChild(div);
chatBox.scrollTop = chatBox.scrollHeight;
}
function sendMessage() {
const q = input.value.trim();
if (!q) return;
appendMessage("user", q);
input.value = "";
appendMessage("bot", "🌿 Thinking...");
setTimeout(() => {
const a = simulateHerbalAnswer(q);
replaceLastBotMessage(a);
}, 1000);
}
function replaceLastBotMessage(text) {
const bots = chatBox.querySelectorAll(".bot");
if (bots.length === 0) return appendMessage("bot", text);
bots[bots.length - 1].textContent = "πŸͺ΄ " + text;
}
function simulateHerbalAnswer(q) {
const s = q.toLowerCase();
if (s.includes("moringa")) return "Moringa oleifera β€” known locally as Nkruma. Rich in nutrients and supports **anti-inflammatory** and **antioxidant** activity.";
if (s.includes("neem")) return "Azadirachta indica (Neem). Locally Nkwanta. Famous for **antimicrobial** and **skin-cleansing** effects.";
if (s.includes("hello") || s.includes("hi")) return "Hello 🌿! Ask about any medicinal plant or natural remedy.";
return "I’m trained for herbal knowledge. Try asking about a plant, its healing uses, or safe dosage.";
}
});