Personalized Longevity Diet Planner

Personalized Longevity Diet Planner

Create a diet plan tailored to your body and longevity goals in just a few steps.

Tell us about yourself

Primary Goal: ${goalInfo.name}

${generateMealHTML('Breakfast', plan.breakfast)} ${generateMealHTML('Lunch', plan.lunch)} ${generateMealHTML('Dinner', plan.dinner)} ${generateMealHTML('Snacks', plan.snacks)}

Disclaimer: This is a sample plan for informational purposes only. It is not medical advice. Consult a registered dietitian or healthcare provider for personalized nutritional guidance. Serving sizes are illustrative.

`; document.getElementById('plan-output').innerHTML = planHTML; } function getFood(foodList, type, goal) { // Prioritize foods that match the goal, then fallback to any food of the type let candidates = foodList.filter(f => f.type === type && f.tags.includes(goal)); if (candidates.length === 0) { candidates = foodList.filter(f => f.type === type); } return candidates[Math.floor(Math.random() * candidates.length)] || { name: `No ${type} available`, calories: 0 }; } function generateMealHTML(mealName, foods) { let totalCalories = foods.reduce((sum, food) => sum + (food.calories || 0), 0); return `

${mealName} ~${totalCalories} kcal

    ${foods.map(f => `
  • ${f.name}
  • `).join('')}
`; } // --- V. PDF GENERATION --- function generatePDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const reportContainer = document.createElement('div'); reportContainer.id = 'pdf-report-container'; reportContainer.innerHTML = generatePdfReportHTML(); document.body.appendChild(reportContainer); html2canvas(reportContainer, { scale: 2, useCORS: true }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdfWidth = doc.internal.pageSize.getWidth(); const pdfHeight = doc.internal.pageSize.getHeight(); const imgProps = doc.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = imgHeight; let position = 0; doc.addImage(imgData, 'PNG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; while (heightLeft >= 0) { position = heightLeft - imgHeight; doc.addPage(); doc.addImage(imgData, 'PNG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; } doc.save('Longevity-Diet-Plan.pdf'); document.body.removeChild(reportContainer); }).catch(err => { console.error("PDF generation error:", err); document.body.removeChild(reportContainer); }); } function generatePdfReportHTML() { const date = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }); const goalInfo = goalData.find(g => g.id === userData.goal); const mealTable = (mealName, foods) => { let foodRows = foods.map(f => `- ${f.name}${f.calories} kcal`).join(''); let totalCalories = foods.reduce((sum, food) => sum + (food.calories || 0), 0); return `

${mealName}

${foodRows}
Subtotal ~${totalCalories} kcal
`; }; return `

Personalized Longevity Diet Report

Generated on: ${date}

Your Profile Summary

Age:${userData.age} years Gender:${userData.gender}
Weight:${userData.weight} lbs Height:${userData.height} in
Estimated Daily Needs: ${userData.tdee} kcal

Longevity Goal: ${goalInfo.name}

${goalInfo.description}

Sample 1-Day Meal Plan

${mealTable('Breakfast', userData.plan.breakfast)} ${mealTable('Lunch', userData.plan.lunch)} ${mealTable('Dinner', userData.plan.dinner)} ${mealTable('Snacks', userData.plan.snacks)}
Disclaimer: This is a sample plan for informational purposes and is not medical advice. Serving sizes are illustrative. Consult a registered dietitian or healthcare provider for personalized nutritional guidance before making any dietary changes.
`; } // --- VI. SCRIPT EXECUTION START --- initializeUI(); updateUI(); });
Scroll to Top