${entry.type}
${entry.content}
`; entryListDiv.appendChild(entryEl); }); }; // --- EVENT LISTENERS --- addEntryBtn.addEventListener('click', () => { const source = sourceInput.value.trim(); const category = categoryInput.value.trim(); const type = typeSelect.value; const content = contentInput.value.trim(); if (!source || !category || !content) { alert('Please fill out all fields.'); return; } entries.push({ id: Date.now(), source, category, type, content }); sourceInput.value = ''; categoryInput.value = ''; contentInput.value = ''; renderAll(); }); entryListDiv.addEventListener('click', e => { if (e.target.classList.contains('delete-entry-btn')) { const id = parseInt(e.target.dataset.id); entries = entries.filter(entry => entry.id !== id); renderAll(); } }); filterCategorySelect.addEventListener('change', renderEntryList); // --- PDF DOWNLOAD --- downloadPdfBtn.addEventListener('click', () => { const { jsPDF } = window.jspdf; const doc = new jsPDF(); const groupedByCategory = entries.reduce((acc, item) => { (acc[item.category] = acc[item.category] || []).push(item); return acc; }, {}); let finalY = 30; doc.setFontSize(22); doc.text('Research Data Summary', 105, 20, { align: 'center' }); for (const category in groupedByCategory) { if (finalY > 250) { doc.addPage(); finalY = 20; } doc.setFontSize(16); doc.text(category, 14, finalY); finalY += 5; const tableData = groupedByCategory[category].map(e => [ e.source, e.type, e.content ]); doc.autoTable({ head: [['Source', 'Type', 'Content']], body: tableData, startY: finalY, theme: 'grid', styles: { fontSize: 9 }, columnStyles: { 2: { cellWidth: 100 } } }); finalY = doc.lastAutoTable.finalY + 15; } doc.save('research-data.pdf'); }); // --- INITIALIZATION --- loadSampleData(); });