Conversation Starters Generator
Generated Starters (Editable)
Go to the "Generator Settings" tab to choose options and generate starters.
Generation Options
No starters available for this category.
"; showTab("csg-tab-dashboard"); return; } const count = Math.min(numToGen, source.length); // Don't ask for more than available const selectedStarters = getRandomUnique(source, count); dashboardList.innerHTML = ""; // Clear list selectedStarters.forEach(starter => { const itemEl = document.createElement("div"); itemEl.className = "csg-dash-item"; itemEl.innerHTML = ` `; dashboardList.appendChild(itemEl); }); showTab("csg-tab-dashboard"); } /** * Handles removing a starter from the dashboard */ function handleDashboardClick(e) { if (e.target.dataset.action === "remove") { e.target.closest(".csg-dash-item").remove(); } } /** * Generates a PDF report from the dashboard data */ function downloadPDF() { if (typeof window.jspdf === 'undefined') { alert("Error: PDF library could not be loaded. Please try again."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF("p", "pt", "a4"); const margin = 40; let yPos = margin; const lineHeight = 18; // Adjust line height as needed const usableWidth = doc.internal.pageSize.getWidth() - margin * 2; doc.setFontSize(18); doc.text("Conversation Starters List", margin, yPos); yPos += lineHeight * 1.5; doc.setFontSize(12); // Get data *from the dashboard* const dashItems = dashboardList.querySelectorAll(".csg-dash-item"); if (dashItems.length === 0) { doc.text("No starters generated.", margin, yPos); } else { dashItems.forEach((item, index) => { const starterText = item.querySelector(".csg-dash-starter").value; const fullText = `${index + 1}. ${starterText}`; // Split text to handle wrapping const splitText = doc.splitTextToSize(fullText, usableWidth); // Check if it fits on the current page if (yPos + (splitText.length * lineHeight) > doc.internal.pageSize.getHeight() - margin) { doc.addPage(); yPos = margin; } doc.text(splitText, margin, yPos); yPos += splitText.length * lineHeight + (lineHeight / 2); // Add extra space between items }); } doc.save("Conversation_Starters.pdf"); } /** * Helper to escape HTML */ function escapeHTML(str) { if (!str) return ""; return str .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """) .replace(/'/g, "'"); } // --- 4. INITIALIZATION & EVENT LISTENERS --- // Tab Listeners tabButtons.forEach((btn) => { btn.addEventListener("click", () => showTab(btn.dataset.target)); }); navButtons.forEach((btn) => { btn.addEventListener("click", () => showTab(btn.dataset.target)); }); // Config Tab Listeners if (generateBtn) { generateBtn.addEventListener("click", handleGenerate); } // Dashboard Tab Listeners if (pdfBtn) { pdfBtn.addEventListener("click", downloadPDF); } if (dashboardList) { dashboardList.addEventListener("click", handleDashboardClick); } // Initial State showTab("csg-tab-dashboard"); });