Online Research Paper & Study Notes Collector

Online Research Paper & Study Notes Collector

Your Collected Notes

${escapeHTML(note.source)}

${escapeHTML(note.summary)}

`; elements.notesGrid.appendChild(card); }); }; const updateTopicFilter = () => { const topics = [...new Set(notes.map(n => n.topic))]; const currentVal = elements.topicFilter.value; elements.topicFilter.innerHTML = ''; topics.sort().forEach(topic => { const option = document.createElement('option'); option.value = topic; option.textContent = topic; elements.topicFilter.appendChild(option); }); elements.topicFilter.value = topics.includes(currentVal) ? currentVal : 'all'; }; // --- DATA & LOGIC FUNCTIONS --- const loadNotes = () => { const storedNotes = localStorage.getItem(NOTES_KEY); notes = storedNotes ? JSON.parse(storedNotes) : []; }; const saveNotes = () => { localStorage.setItem(NOTES_KEY, JSON.stringify(notes)); }; const handleSaveNote = (e) => { e.preventDefault(); const id = elements.noteId.value; const noteData = { topic: elements.noteTopic.value.trim(), title: elements.noteTitle.value.trim(), source: elements.noteSource.value.trim(), url: elements.noteUrl.value.trim(), summary: elements.noteSummary.value.trim(), quotes: elements.noteQuotes.value.trim(), timestamp: Date.now() }; if (id) { // Editing existing note const index = notes.findIndex(n => n.id == id); if (index > -1) { notes[index] = { ...notes[index], ...noteData }; } } else { // Creating new note noteData.id = Date.now(); notes.push(noteData); } saveNotes(); resetForm(); updateTopicFilter(); renderNotes(); switchTab('dashboard'); }; const handleEditNote = (id) => { const note = notes.find(n => n.id == id); if (!note) return; elements.noteId.value = note.id; elements.noteTopic.value = note.topic; elements.noteTitle.value = note.title; elements.noteSource.value = note.source; elements.noteUrl.value = note.url; elements.noteSummary.value = note.summary; elements.noteQuotes.value = note.quotes; elements.saveNoteBtn.textContent = 'Update Note'; elements.cancelEditBtn.classList.remove('hidden'); switchTab('input'); }; const handleDeleteNote = (id) => { notes = notes.filter(n => n.id != id); saveNotes(); updateTopicFilter(); renderNotes(); }; const resetForm = () => { elements.noteForm.reset(); elements.noteId.value = ''; elements.saveNoteBtn.textContent = 'Save Note'; elements.cancelEditBtn.classList.add('hidden'); }; const downloadPDF = async () => { const { jsPDF } = window.jspdf; const filterValue = elements.topicFilter.value; const notesToPrint = (filterValue === 'all' ? notes : notes.filter(n => n.topic === filterValue)) .sort((a,b) => a.topic.localeCompare(b.topic) || b.timestamp - a.timestamp); if (notesToPrint.length === 0) return; let html = `
`; html += `

Research Notes: ${filterValue === 'all' ? 'All Topics' : escapeHTML(filterValue)}

`; let currentTopic = null; notesToPrint.forEach(note => { if (note.topic !== currentTopic) { currentTopic = note.topic; html += `

${escapeHTML(currentTopic)}

`; } html += `

${escapeHTML(note.title)}

${escapeHTML(note.source)}

${note.url ? `

${escapeHTML(note.url)}

` : ''} ${note.summary ? `

Summary & Notes

${escapeHTML(note.summary).replace(/\n/g, '
')}

` : ''} ${note.quotes ? `

Key Quotes

${escapeHTML(note.quotes).replace(/\n/g, '
')}

` : ''}
`; }); html += `
`; elements.pdfContent.innerHTML = html; elements.pdfContent.classList.remove('hidden'); try { const canvas = await html2canvas(elements.pdfContent, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF('p', 'pt', 'a4'); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgProps = pdf.getImageProperties(imgData); const imgHeight = (imgProps.height * pdfWidth) / imgProps.width; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; while (heightLeft > 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 0, position, pdfWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save('research-notes.pdf'); } catch (error) { console.error("PDF Generation Error:", error); } finally { elements.pdfContent.classList.add('hidden'); } }; const escapeHTML = (str) => str.replace(/[&<>'"]/g, tag => ({'&': '&','<': '<','>': '>',"'": ''','"': '"'}[tag])); // --- EVENT LISTENERS --- elements.tabButtons.dashboard.addEventListener('click', () => switchTab('dashboard')); elements.tabButtons.input.addEventListener('click', () => { resetForm(); switchTab('input'); }); elements.prevBtn.addEventListener('click', () => { const i = TABS.indexOf(activeTab); if (i > 0) switchTab(TABS[i - 1]); }); elements.nextBtn.addEventListener('click', () => { const i = TABS.indexOf(activeTab); if (i < TABS.length - 1) switchTab(TABS[i + 1]); }); elements.noteForm.addEventListener('submit', handleSaveNote); elements.cancelEditBtn.addEventListener('click', () => { resetForm(); switchTab('dashboard'); }); elements.topicFilter.addEventListener('change', renderNotes); elements.downloadPdfBtn.addEventListener('click', downloadPDF); elements.notesGrid.addEventListener('click', (e) => { if (e.target.classList.contains('edit-btn')) handleEditNote(e.target.dataset.id); if (e.target.classList.contains('delete-btn')) handleDeleteNote(e.target.dataset.id); }); // --- INITIALIZATION --- loadNotes(); updateTopicFilter(); renderNotes(); switchTab('dashboard'); });
Scroll to Top