Book Recommendation Tool

Book Recommendation Tool

Enter a genre, topic, author, or a "books like..." query.

`; resultsContainer.appendChild(card); }); } /** * Handles the PDF Download button click. */ function handleDownloadPDF() { if (lastRecommendations.length === 0) { showMessage("Nothing to download. Please generate recommendations first.", true); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFontSize(18); doc.text("Book Recommendations", 14, 22); doc.setFontSize(11); doc.text(`Query: ${queryInput.value}`, 14, 30); const tableData = lastRecommendations.map((book) => [ book.title, book.author, book.description, ]); doc.autoTable({ startY: 40, head: [ ["Title", "Author", "Description"] ], body: tableData, theme: "striped", headStyles: { fillColor: [0, 95, 204] }, // --primary-color styles: { cellPadding: 3 }, columnStyles: { 2: { cellWidth: 88 } // Wrap description }, }); doc.save("book_recommendations.pdf"); } /** * Shows or hides the loading spinner. */ function setLoading(isLoading) { if (loader) loader.style.display = isLoading ? "block" : "none"; if (generateBtn) generateBtn.disabled = isLoading; if (isLoading) { showMessage("", false); // Clear messages resultsContainer.innerHTML = ""; pdfContainer.style.display = "none"; } } /** * Displays a message to the user. */ function showMessage(message, isError = false) { if (messageArea) { messageArea.textContent = message; messageArea.className = isError ? "text-center text-red-600 p-4" : "text-center text-darkGray p-4"; messageArea.style.display = message ? "block" : "none"; } } });