Your library is empty.
`; return; } references.forEach(ref => { const p = document.createElement('p'); p.innerHTML = formatCitation(ref, style); outputDiv.appendChild(p); }); } function formatCitation(ref, style) { const { author, year, title, publisher, journal, websiteName } = ref; switch (style) { case 'apa': if (ref.type === 'book') return `${author} (${year}). ${title}. ${publisher}.`; if (ref.type === 'journalArticle') return `${author} (${year}). ${title}. ${journal}.`; if (ref.type === 'website') return `${author} (${year}). ${title}. ${websiteName}.`; break; case 'mla': if (ref.type === 'book') return `${author}. ${title}. ${publisher}, ${year}.`; if (ref.type === 'journalArticle') return `${author}. "${title}." ${journal}, ${year}.`; if (ref.type === 'website') return `${author}. ${title}. ${websiteName}, ${year}.`; break; case 'chicago': if (ref.type === 'book') return `${author}. ${year}. ${title}. ${publisher}.`; if (ref.type === 'journalArticle') return `${author}. "${title}." ${journal} (${year}).`; if (ref.type === 'website') return `${author}. "${title}." ${websiteName}. Accessed ${year}.`; break; default: return 'Invalid citation style.'; } return ''; } // --- PDF DOWNLOAD --- function downloadPDF() { const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content'); if (!pdfContent) return; html2canvas(pdfContent, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save('Bibliography.pdf'); }); } // --- EVENT LISTENERS --- function setupEventListeners() { tabsNav.addEventListener('click', e => { e.preventDefault(); if (e.target.classList.contains('tab-link')) { showTab(parseInt(e.target.dataset.index)); } }); prevBtn.addEventListener('click', () => showTab(currentTabIndex - 1)); nextBtn.addEventListener('click', () => showTab(currentTabIndex + 1)); refTypeSelect.addEventListener('change', updateFormFields); addForm.addEventListener('submit', handleAddReference); libraryList.addEventListener('click', e => { if (e.target.classList.contains('delete-btn')) { handleDeleteReference(parseInt(e.target.dataset.index)); } if (e.target.classList.contains('edit-btn')) { showEditModal(parseInt(e.target.dataset.index)); } }); editForm.addEventListener('submit', handleUpdateReference); cancelEditBtn.addEventListener('click', hideEditModal); generateBtn.addEventListener('click', generateBibliography); downloadPdfBtn.addEventListener('click', downloadPDF); } // --- START THE APP --- initialize(); });