Online AI-Powered Note Summarizer
Paste your notes below and let our AI provide a clear and concise summary.
Your summary will appear here.
AI is thinking...
'; const prompt = `Summarize the following notes in a clear, concise, and easy-to-read format. Use bullet points for key takeaways if appropriate:\n\n---\n\n${originalText}`; const payload = { contents: [{ role: "user", parts: [{ text: prompt }] }] }; try { const response = await fetch(API_URL, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!response.ok) { throw new Error(`API request failed with status ${response.status}`); } const result = await response.json(); if (result.candidates && result.candidates.length > 0) { const summaryText = result.candidates[0].content.parts[0].text; displaySummary(summaryText); lastResult = { original: originalText, summary: summaryText }; } else { throw new Error("No summary was returned from the AI."); } } catch (error) { console.error("Error during summarization:", error); errorMessage.textContent = `An error occurred: ${error.message}. Please try again.`; summaryOutputDiv.innerHTML = 'Failed to generate summary.
'; } finally { setLoadingState(false); } }; /** * Renders the summary in the UI. * @param {string} summaryText - The AI-generated summary. */ const displaySummary = (summaryText) => { // A simple conversion of markdown-like lists to HTML const htmlText = summaryText .replace(/^\* (.*$)/gm, '${match}
`); summaryOutputDiv.innerHTML = `${htmlText}
`;
downloadSection.classList.remove('hidden');
};
/**
* Generates and triggers the download of a PDF report.
*/
const generatePdf = () => {
if (!lastResult) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ unit: 'pt', format: 'a4' });
const margin = 40;
const usableWidth = doc.internal.pageSize.getWidth() - margin * 2;
let currentY = margin;
const addSection = (title, text, isSummary = false) => {
doc.setFontSize(isSummary ? 16 : 14);
doc.setFont('helvetica', 'bold');
doc.text(title, margin, currentY);
currentY += 20;
doc.setFontSize(11);
doc.setFont('helvetica', 'normal');
const lines = doc.splitTextToSize(text, usableWidth);
doc.text(lines, margin, currentY);
currentY += (lines.length * 12) + 25;
};
addSection("Original Notes", lastResult.original);
doc.addPage();
currentY = margin;
addSection("AI-Generated Summary", lastResult.summary, true);
doc.save('AI_Summary_Report.pdf');
};
// --- EVENT LISTENERS ---
summarizeBtn.addEventListener('click', handleSummarization);
downloadPdfBtn.addEventListener('click', generatePdf);
});
