Random Name Generator (Fantasy, Sci-Fi, etc.)

Random Name Generator

Generated Names (Editable)

Go to the "Generator Settings" tab to choose options and generate names.

Generation Options

Error: Invalid genre selected.

`; showTab("rng-tab-dashboard"); return; } for (let i = 0; i < numToGen; i++) { const name = generateName(genre, gender); const itemEl = document.createElement("div"); itemEl.className = "rng-dash-item"; itemEl.innerHTML = ` `; dashboardList.appendChild(itemEl); } showTab("rng-tab-dashboard"); } /** * Handles removing a name from the dashboard */ function handleDashboardClick(e) { if (e.target.dataset.action === "remove") { e.target.closest(".rng-dash-item").remove(); } } /** * Generates a PDF report from the dashboard data */ function downloadPDF() { if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF.autoTable === 'undefined') { alert("Error: PDF libraries could not be loaded. Please try again."); return; } const genreText = genreSelect.options[genreSelect.selectedIndex].text; const genderText = genderSelect.options[genderSelect.selectedIndex].text; const title = `Generated Names - ${genreText} (${genderText})`; const { jsPDF } = window.jspdf; const doc = new jsPDF("p", "pt", "a4"); const margin = 40; const tableHead = [["Generated Names"]]; const tableBody = []; // Get data *from the dashboard* const dashItems = dashboardList.querySelectorAll(".rng-dash-item"); if (dashItems.length === 0) { alert("Please generate names before downloading."); return; } dashItems.forEach((item) => { const name = item.querySelector(".rng-dash-name").value; tableBody.push([name]); }); doc.setFontSize(18); doc.text(title, margin, margin); doc.autoTable({ startY: margin + 20, head: tableHead, body: tableBody, theme: 'striped', headStyles: { fillColor: [0, 115, 230], textColor: [255, 255, 255], }, }); doc.save("Random_Name_List.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("rng-tab-dashboard"); });
Scroll to Top