Fictional Character Name Generator

Fictional Character Name Generator

Discover the perfect name for your next character.

Filters

Generated Names

Your generated names will appear here.

Click 'Generate Names' to start.

`; return; } resultsContainer.innerHTML = generatedNames.map(name => `

${name}

`).join(''); } // --- UTILITY FUNCTIONS --- function showNotification(message) { notification.textContent = message; notification.classList.remove('opacity-0'); setTimeout(() => notification.classList.add('opacity-0'), 2000); } function copyToClipboard(text, message) { navigator.clipboard.writeText(text).then(() => showNotification(message)); } // --- PDF GENERATION --- async function generatePdfReport() { if (generatedNames.length === 0) { showNotification("No names to generate a report for."); return; } downloadPdfBtn.disabled = true; downloadPdfBtn.textContent = '...'; const genreText = genreSelect.options[genreSelect.selectedIndex].text; const nameListItems = generatedNames.map(name => `
  • ${name}
  • `).join(''); const reportHtml = `

    Character Name Ideation

    A collection of names for your next project

    ${genreText} Names
      ${nameListItems}
    `; const pdfTemplate = document.getElementById('pdf-template'); pdfTemplate.innerHTML = reportHtml; pdfTemplate.classList.remove('invisible'); try { const { jsPDF } = window.jspdf; const canvas = await html2canvas(pdfTemplate.querySelector('.pdf-report-container'), { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(), pdfHeight = (canvas.height * pdfWidth) / canvas.width; pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight); pdf.save(`Character_Names_${genreText}.pdf`); } catch (e) { console.error('PDF Generation Error:', e); } finally { downloadPdfBtn.disabled = false; downloadPdfBtn.textContent = 'Download PDF'; pdfTemplate.classList.add('invisible'); pdfTemplate.innerHTML = ''; } } // --- EVENT LISTENERS --- generateBtn.addEventListener('click', generateNames); copyAllBtn.addEventListener('click', () => { if (generatedNames.length > 0) copyToClipboard(generatedNames.join('\n'), 'All names copied!'); }); resultsContainer.addEventListener('click', (e) => { if (e.target.classList.contains('copy-name-btn')) { const name = e.target.previousElementSibling.textContent; copyToClipboard(name, 'Name copied!'); } }); downloadPdfBtn.addEventListener('click', generatePdfReport); // --- INITIALIZATION --- generateNames(); });
    Scroll to Top