Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const workEntryForm = document.getElementById('work-entry-form');
+ const entriesList = document.getElementById('entries-list');
+
+ // Load saved entries from localStorage
+ let entries = JSON.parse(localStorage.getItem('workEntries')) || [];
+
+ function updateSummary() {
+ const today = new Date();
+ const weekStart = new Date(today.setDate(today.getDate() - today.getDay()));
+
+ const weeklyEntries = entries.filter(entry => {
+ const entryDate = new Date(entry.timestamp);
+ return entryDate >= weekStart;
+ });
+
+ const totalHours = weeklyEntries.reduce((sum, entry) => {
+ return sum + (entry.hours + entry.minutes / 60);
+ }, 0);
+
+ document.getElementById('total-hours').textContent = totalHours.toFixed(1);
+ document.getElementById('tasks-completed').textContent = weeklyEntries.length;
+ document.getElementById('productivity-score').textContent =
+ Math.min(Math.round((totalHours / 40) * 100), 100) + '%';
+ }
+
+ function addEntry(entry) {
+ entries.unshift(entry);
+ localStorage.setItem('workEntries', JSON.stringify(entries));
+ renderEntries();
+ updateSummary();
+ }
+
+ function renderEntries() {
+ entriesList.innerHTML = entries
+ .slice(0, 5)
+ .map(entry => `
+
+
${entry.title}
+
Time: ${entry.hours}h ${entry.minutes}m
+ ${new Date(entry.timestamp).toLocaleDateString()}
+
+ `)
+ .join('');
+ }
+
+ workEntryForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+
+ const entry = {
+ title: document.getElementById('task-title').value,
+ description: document.getElementById('task-description').value,
+ hours: parseInt(document.getElementById('hours').value) || 0,
+ minutes: parseInt(document.getElementById('minutes').value) || 0,
+ timestamp: new Date().toISOString()
+ };
+
+ addEntry(entry);
+ workEntryForm.reset();
+ });
+
+ // Generate weekly report automatically
+ function generateWeeklyReport() {
+ const today = new Date();
+ if (today.getDay() === 0) { // Sunday
+ const weeklyEntries = entries.filter(entry => {
+ const entryDate = new Date(entry.timestamp);
+ const weekStart = new Date(today.setDate(today.getDate() - 7));
+ return entryDate >= weekStart;
+ });
+
+ // Here you could implement email sending or report generation
+ console.log('Weekly Report Generated:', weeklyEntries);
+ }
+ }
+
+ // Check for weekly report generation daily
+ setInterval(generateWeeklyReport, 24 * 60 * 60 * 1000);
+
+ // Initial render
+ renderEntries();
+ updateSummary();
+ });