Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ // Theme toggling
+ const themeToggle = document.querySelector('.theme-toggle');
+ const prefersDark = window.matchMedia('(prefers-color-scheme: dark)');
+
+ function setTheme(isDark) {
+ document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
+ themeToggle.textContent = isDark ? '☀️' : '🌙';
+ }
+
+ setTheme(prefersDark.matches);
+
+ themeToggle.addEventListener('click', () => {
+ const isDark = document.documentElement.getAttribute('data-theme') === 'dark';
+ setTheme(!isDark);
+ });
+
+ // Course management
+ const courseForm = document.getElementById('courseForm');
+ const courseList = document.getElementById('courseList');
+ let courses = JSON.parse(localStorage.getItem('courses')) || [];
+
+ function saveCourses() {
+ localStorage.setItem('courses', JSON.stringify(courses));
+ updateStats();
+ renderCourses();
+ }
+
+ function updateStats() {
+ document.getElementById('totalCourses').textContent = courses.length;
+
+ const totalHours = courses.reduce((sum, course) => sum + course.hoursSpent, 0);
+ document.getElementById('totalHoursStudied').textContent = totalHours.toFixed(1);
+
+ const completion = courses.reduce((sum, course) => {
+ return sum + (course.hoursSpent / course.totalHours) * 100;
+ }, 0) / (courses.length || 1);
+
+ document.getElementById('completionRate').textContent = `${completion.toFixed(1)}%`;
+ }
+
+ function renderCourses() {
+ courseList.innerHTML = '';
+ courses.forEach((course, index) => {
+ const progress = (course.hoursSpent / course.totalHours) * 100;
+
+ const courseCard = document.createElement('div');
+ courseCard.className = 'course-card';
+ courseCard.innerHTML = `
+
${course.name}
+
${course.hoursSpent}/${course.totalHours} hours
+ `;
+ courseList.appendChild(courseCard);
+ });
+ }
+
+ courseForm.addEventListener('submit', (e) => {
+ e.preventDefault();
+ const newCourse = {
+ name: document.getElementById('courseName').value,
+ platform: document.getElementById('platform').value,
+ totalHours: parseFloat(document.getElementById('totalHours').value),
+ hoursSpent: 0
+ };
+ courses.push(newCourse);
+ saveCourses();
+ courseForm.reset();
+ });
+
+ window.addTime = (index, hours) => {
+ courses[index].hoursSpent = Math.min(
+ courses[index].hoursSpent + hours,
+ courses[index].totalHours
+ );
+ saveCourses();
+ };
+
+ window.removeCourse = (index) => {
+ if (confirm('Are you sure you want to delete this course?')) {
+ courses.splice(index, 1);
+ saveCourses();
+ }
+ };
+
+ // Initial render
+ renderCourses();
+ updateStats();
+ });