Study Session Optimizer
Total Available Study Time
Subjects to Study
Your Optimized Study Schedule
Here is your personalized plan to maximize productivity.
${item.end - item.start} minutes
`; scheduleTimeline.appendChild(itemDiv); }); }; /** * Generates and downloads a PDF of the schedule. */ const handlePdfDownload = () => { const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-output'); // Use html2canvas to render the div to a canvas html2canvas(pdfContent, { scale: 2, // Higher scale for better quality useCORS: true, }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; const margin = 40; pdf.addImage(imgData, 'PNG', margin, margin, pdfWidth - (margin * 2), pdfHeight); pdf.save('study-schedule.pdf'); }); }; // --- Event Listeners --- Object.keys(tabs).forEach(tabName => { tabs[tabName].btn.addEventListener('click', () => switchTab(tabName)); }); navButtons.next.addEventListener('click', () => switchTab('schedule')); navButtons.prev.addEventListener('click', () => switchTab('config')); addSubjectBtn.addEventListener('click', () => addSubjectRow()); generateScheduleBtn.addEventListener('click', handleGenerateSchedule); downloadPdfBtn.addEventListener('click', handlePdfDownload); // --- Initial Setup --- addSubjectRow({ name: 'Mathematics', priority: 3, hours: 1, minutes: 30 }); addSubjectRow({ name: 'English Literature', priority: 2, hours: 1, minutes: 0 }); addSubjectRow({ name: 'Physics', priority: 3, hours: 2, minutes: 0 }); updateNavButtons(); });