` : ''}
${entry.gratitude ? `
`;
listEl.appendChild(card);
});
}
}
window.deleteEntry = function(id) {
if (confirm('Are you sure you want to permanently delete this journal entry?')) {
journalEntries = journalEntries.filter(entry => entry.id !== id);
saveJournal();
renderJournal();
}
};
window.changeTab = function(tabIndex) {
const tabs = document.querySelectorAll('.tab');
const tabContents = document.querySelectorAll('.tab-content');
tabs[currentTabIndex].classList.remove('active');
tabContents[currentTabIndex].classList.remove('active');
currentTabIndex = tabIndex;
tabs[currentTabIndex].classList.add('active');
tabContents[currentTabIndex].classList.add('active');
if (tabIndex === 1) {
renderJournal();
}
};
window.downloadPDF = function() {
if (journalEntries.length === 0) {
alert("There are no journal entries to download.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
let yPosition = 22;
doc.setFontSize(20);
doc.setFont('helvetica', 'bold');
doc.text("My Daily Reflection Journal", 105, yPosition, { align: 'center' });
yPosition += 20;
journalEntries.forEach(entry => {
const entryDate = new Date(entry.date).toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
if (yPosition > 250) {
doc.addPage();
yPosition = 22;
}
doc.setFontSize(14);
doc.setFont('helvetica', 'bold');
doc.setTextColor(79, 70, 229); // Indigo
doc.text(entryDate, 14, yPosition);
yPosition += 12;
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
doc.setTextColor(0, 0, 0);
if(entry.learning) {
doc.setFont('helvetica', 'bold');
doc.text("What I learned:", 14, yPosition);
yPosition += 6;
doc.setFont('helvetica', 'normal');
const text = doc.splitTextToSize(entry.learning, 180);
doc.text(text, 20, yPosition);
yPosition += text.length * 5 + 5;
}
if(entry.challenge) {
doc.setFont('helvetica', 'bold');
doc.text("My biggest challenge:", 14, yPosition);
yPosition += 6;
doc.setFont('helvetica', 'normal');
const text = doc.splitTextToSize(entry.challenge, 180);
doc.text(text, 20, yPosition);
yPosition += text.length * 5 + 5;
}
if(entry.gratitude) {
doc.setFont('helvetica', 'bold');
doc.text("I'm grateful for:", 14, yPosition);
yPosition += 6;
doc.setFont('helvetica', 'normal');
const text = doc.splitTextToSize(entry.gratitude, 180);
doc.text(text, 20, yPosition);
yPosition += text.length * 5 + 10;
}
});
doc.save('daily_reflection_journal.pdf');
};
// Initial Load
loadJournal();
displayCurrentDate();
});
Grateful for:
` : ''}
${entry.gratitude.replace(/\n/g, '
')}
