Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Theme Toggle
+ const themeToggle = document.getElementById('themeToggle');
+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
+
+ function setTheme(isDark) {
+ document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
+ localStorage.setItem('theme', isDark ? 'dark' : 'light');
+ }
+
+ themeToggle.addEventListener('click', () => {
+ const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
+ setTheme(!isDark);
+ });
+
+ // Rich Text Editor
+ const toolbar = document.querySelector('.toolbar');
+ toolbar.addEventListener('click', (e) => {
+ if (e.target.matches('button[data-command]')) {
+ const command = e.target.getAttribute('data-command');
+ document.execCommand(command, false, null);
+ }
+ });
+
+ // Save Log
+ const saveLog = document.getElementById('saveLog');
+ saveLog.addEventListener('click', () => {
+ const content = document.getElementById('editor').innerHTML;
+ const tags = document.getElementById('tags').value;
+ const category = document.getElementById('category').value;
+ const timestamp = new Date().toISOString();
+
+ const log = {
+ content,
+ tags: tags.split(',').map(tag => tag.trim()),
+ category,
+ timestamp
+ };
+
+ // Store in localStorage for demo
+ const logs = JSON.parse(localStorage.getItem('logs') || '[]');
+ logs.unshift(log);
+ localStorage.setItem('logs', JSON.stringify(logs));
+
+ updateLogsList();
+ updateStats();
+ clearEditor();
+ });
+
+ function clearEditor() {
+ document.getElementById('editor').innerHTML = '';
+ document.getElementById('tags').value = '';
+ document.getElementById('category').selectedIndex = 0;
+ }
+
+ function updateLogsList() {
+ const logsList = document.getElementById('logsList');
+ const logs = JSON.parse(localStorage.getItem('logs') || '[]');
+
+ logsList.innerHTML = logs.map(log => `
+
+
+ ${new Date(log.timestamp).toLocaleDateString()}
+ ${log.category}
+ ${log.tags.join(', ')}
+
+
+ `).join('');
+ }
+
+ function updateStats() {
+ const logs = JSON.parse(localStorage.getItem('logs') || '[]');
+
+ document.getElementById('totalLogs').textContent = logs.length;
+
+ const weekAgo = new Date();
+ weekAgo.setDate(weekAgo.getDate() - 7);
+ const weeklyLogs = logs.filter(log =>
+ new Date(log.timestamp) > weekAgo
+ ).length;
+ document.getElementById('weeklyLogs').textContent = weeklyLogs;
+
+ // Calculate streak
+ let streak = 0;
+ let currentDate = new Date();
+ while (true) {
+ const hasLog = logs.some(log =>
+ new Date(log.timestamp).toDateString() === currentDate.toDateString()
+ );
+ if (!hasLog) break;
+ streak++;
+ currentDate.setDate(currentDate.getDate() - 1);
+ }
+ document.getElementById('streak').textContent = streak;
+ }
+
+ // Initial load
+ updateLogsList();
+ updateStats();
+ });