Stretching Routine Generator
Create a custom routine to improve your flexibility.
Your Stretching Routine
Medical Disclaimer
Consult with a healthcare professional before beginning any new exercise or stretching program, especially if you have pre-existing injuries or medical conditions. Stop if you feel sharp pain.
for the instructions and duration. Do not include any other text, explanation, or HTML tags outside of these divs.`; const apiKey = ""; // API key is handled by the environment const apiUrl = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-05-20:generateContent?key=${apiKey}`; const payload = { contents: [{ parts: [{ text: prompt }] }] }; try { const response = await fetch(apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const result = await response.json(); const routineHtml = result.candidates?.[0]?.content?.parts?.[0]?.text; if (routineHtml) { elements.routineContent.innerHTML = routineHtml; } else { throw new Error("No content received from API."); } } catch (error) { console.error("Gemini API Error:", error); elements.routineContent.innerHTML = '
Sorry, we couldn\'t generate a routine right now. Please try again in a moment.
'; } finally { elements.loadingSpinner.classList.add('hidden'); } } async function downloadPDF() { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const contentArea = document.getElementById('pdf-content-area'); 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() - 20; // A4 width with margin const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth, pdfHeight); // Add disclaimer to the bottom of the PDF pdf.setFontSize(8); pdf.setTextColor(100); const disclaimer = "Disclaimer: Consult with a healthcare professional before beginning any new exercise or stretching program, especially if you have pre-existing injuries or medical conditions. Stop if you feel sharp pain."; const splitDisclaimer = pdf.splitTextToSize(disclaimer, pdfWidth); pdf.text(splitDisclaimer, 10, pdf.internal.pageSize.getHeight() - 15); const focusArea = elements.focusAreaSelect.value.replace(/\s+/g, '_'); pdf.save(`Stretching_Routine_${focusArea}.pdf`); } 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."); } } });