Strength Training Progress Tracker

Log a New Workout

Sets

Sorry, the AI coach is unavailable right now. Please try again later.

'; } finally { elements.aiAnalysisLoading.classList.add('hidden'); elements.aiAnalysisContainer.classList.remove('hidden'); } } elements.analyzeProgressBtn.addEventListener('click', analyzeProgressWithGemini); // --- PDF DOWNLOAD FUNCTIONALITY --- async function downloadPDF() { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const contentArea = elements.pdfContentArea; if (!contentArea) { console.error("PDF content area not found!"); return; } document.body.classList.add('pdf-export-mode'); try { const canvas = await html2canvas(contentArea, { scale: 2, useCORS: true, logging: false }); document.body.classList.remove('pdf-export-mode'); const imgData = canvas.toDataURL('image/png'); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = pdfHeight; let position = 0; const pageHeight = pdf.internal.pageSize.getHeight(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight); heightLeft -= pageHeight; while (heightLeft > 0) { position = heightLeft - pdfHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, pdfHeight); heightLeft -= pageHeight; } const selectedExercise = exercises.find(ex => ex.id === parseInt(elements.progressExerciseSelect.value)); const fileName = `Strength_Progress_${selectedExercise.name.replace(/\s+/g, '_')}.pdf`; pdf.save(fileName); } catch (error) { console.error("Error generating PDF:", error); document.body.classList.remove('pdf-export-mode'); alert("An error occurred while generating the PDF. Please try again."); } } elements.downloadPdfBtn.addEventListener('click', downloadPDF); // --- INITIALIZATION --- function initializeTool() { populateExerciseDropdowns(); renderExerciseList(); elements.workoutDate.valueAsDate = new Date(); addSet(); updateNavButtons(); updateProgressView(); } initializeTool(); });
Scroll to Top