Zotero Manager

Reference Manager

Collect, organize, and cite your research sources.

My Library

Add New Reference

Generate Bibliography

Bibliography

Select a style and click 'Generate' to create your bibliography.

${ref.type.replace(/([A-Z])/g, ' $1')}

`; libraryList.appendChild(item); }); } function handleAddReference(e) { e.preventDefault(); const newRef = { type: addForm.elements['ref-type'].value, title: addForm.elements['ref-title'].value, author: addForm.elements['ref-author'].value, year: parseInt(addForm.elements['ref-year'].value), publisher: addForm.elements['ref-publisher'].value, journal: addForm.elements['ref-journal'].value, websiteName: addForm.elements['ref-website-name'].value, }; references.push(newRef); renderLibrary(); addForm.reset(); updateFormFields(); showTab(0); // Switch to library view after adding } function handleDeleteReference(index) { if (confirm('Are you sure you want to delete this reference?')) { references.splice(index, 1); renderLibrary(); } } function showEditModal(index) { const ref = references[index]; editForm.elements['edit-ref-index'].value = index; editForm.elements['edit-ref-title'].value = ref.title; editForm.elements['edit-ref-author'].value = ref.author; editForm.elements['edit-ref-year'].value = ref.year; editModal.classList.add('visible'); } function hideEditModal() { editModal.classList.remove('visible'); } function handleUpdateReference(e) { e.preventDefault(); const index = editForm.elements['edit-ref-index'].value; if (index === '' || index === null) return; references[index].title = editForm.elements['edit-ref-title'].value; references[index].author = editForm.elements['edit-ref-author'].value; references[index].year = parseInt(editForm.elements['edit-ref-year'].value); renderLibrary(); hideEditModal(); } function updateFormFields() { const type = refTypeSelect.value; document.getElementById('book-fields').style.display = type === 'book' ? 'block' : 'none'; document.getElementById('journal-fields').style.display = type === 'journalArticle' ? 'block' : 'none'; document.getElementById('website-fields').style.display = type === 'website' ? 'block' : 'none'; } // --- BIBLIOGRAPHY GENERATION --- function generateBibliography() { const style = document.getElementById('citation-style').value; const outputDiv = document.getElementById('bibliography-output'); outputDiv.innerHTML = ''; if (references.length === 0) { outputDiv.innerHTML = `

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(); });
Scroll to Top