Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const newEntryBtn = document.getElementById('newEntry');
+ const modal = document.getElementById('entryModal');
+ const cancelBtn = document.getElementById('cancelEntry');
+ const saveBtn = document.getElementById('saveEntry');
+ const toggleThemeBtn = document.getElementById('toggleTheme');
+
+ // Theme Toggle
+ const toggleTheme = () => {
+ const currentTheme = document.documentElement.getAttribute('data-theme');
+ const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
+ document.documentElement.setAttribute('data-theme', newTheme);
+ localStorage.setItem('theme', newTheme);
+ };
+
+ // Load saved theme
+ const savedTheme = localStorage.getItem('theme') || 'light';
+ document.documentElement.setAttribute('data-theme', savedTheme);
+
+ // Modal handlers
+ const openModal = () => {
+ modal.style.display = 'flex';
+ };
+
+ const closeModal = () => {
+ modal.style.display = 'none';
+ clearForm();
+ };
+
+ const clearForm = () => {
+ document.getElementById('entryTitle').value = '';
+ document.getElementById('entryContent').value = '';
+ document.getElementById('entryTags').value = '';
+ };
+
+ const saveEntry = () => {
+ const title = document.getElementById('entryTitle').value;
+ const content = document.getElementById('entryContent').value;
+ const category = document.getElementById('entryCategory').value;
+ const tags = document.getElementById('entryTags').value.split(',').map(tag => tag.trim());
+
+ if (!title || !content) {
+ alert('Please fill in all required fields');
+ return;
+ }
+
+ const entry = {
+ id: Date.now(),
+ title,
+ content,
+ category,
+ tags,
+ timestamp: new Date().toISOString()
+ };
+
+ const entries = JSON.parse(localStorage.getItem('entries') || '[]');
+ entries.unshift(entry);
+ localStorage.setItem('entries', JSON.stringify(entries));
+
+ closeModal();
+ renderEntries();
+ };
+
+ const renderEntries = () => {
+ const entriesContainer = document.getElementById('logEntries');
+ const entries = JSON.parse(localStorage.getItem('entries') || '[]');
+
+ entriesContainer.innerHTML = entries.map(entry => `
+
+
${entry.title}
+
+ ${new Date(entry.timestamp).toLocaleString()}
+
+ ${entry.tags.map(tag => `${tag}`).join('')}
+
+
+
+ `).join('');
+ };
+
+ // Event Listeners
+ newEntryBtn.addEventListener('click', openModal);
+ cancelBtn.addEventListener('click', closeModal);
+ saveBtn.addEventListener('click', saveEntry);
+ toggleThemeBtn.addEventListener('click', toggleTheme);
+
+ // Initial render
+ renderEntries();
+ });