Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const chatMessages = document.getElementById('chat-messages');
+ const userInput = document.getElementById('user-input');
+ const sendButton = document.getElementById('send-button');
+
+ const botResponses = {
+ 'hello': 'Hello! How can I assist with your journalism today?',
+ 'help': 'I can help with research, interview questions, fact-checking, and story angles. What would you like to explore?',
+ 'default': 'I understand. Let me help you gather more information about that topic.'
+ };
+
+ function addMessage(message, isBot = false) {
+ const messageDiv = document.createElement('div');
+ messageDiv.className = `message ${isBot ? 'bot' : 'user'}`;
+ messageDiv.style.padding = '10px';
+ messageDiv.style.margin = '10px';
+ messageDiv.style.borderRadius = '10px';
+ messageDiv.style.maxWidth = '70%';
+ messageDiv.style.alignSelf = isBot ? 'flex-start' : 'flex-end';
+ messageDiv.style.background = isBot ? '#f0f0f0' : '#6c63ff';
+ messageDiv.style.color = isBot ? '#333' : 'white';
+ messageDiv.textContent = message;
+ chatMessages.appendChild(messageDiv);
+ chatMessages.scrollTop = chatMessages.scrollHeight;
+ }
+
+ function getBotResponse(input) {
+ const lowercaseInput = input.toLowerCase();
+ return botResponses[lowercaseInput] || botResponses.default;
+ }
+
+ function handleSubmit() {
+ const message = userInput.value.trim();
+ if (message) {
+ addMessage(message, false);
+ userInput.value = '';
+
+ setTimeout(() => {
+ const response = getBotResponse(message);
+ addMessage(response, true);
+ }, 500);
+ }
+ }
+
+ sendButton.addEventListener('click', handleSubmit);
+ userInput.addEventListener('keypress', (e) => {
+ if (e.key === 'Enter' && !e.shiftKey) {
+ e.preventDefault();
+ handleSubmit();
+ }
+ });
+
+ // Initial bot greeting
+ setTimeout(() => {
+ addMessage('Welcome to JournoBot! How can I assist with your journalism today?', true);
+ }, 1000);
+ });