Online Word Association & Thesaurus Tool

Word Association & Thesaurus Tool

Explore connections and find the perfect word.

An error occurred. Please try again.

`; } finally { loader.classList.add('hidden'); loader.classList.remove('flex'); resultsWrapper.classList.remove('hidden'); } }; generateBtn.addEventListener('click', handleGeneration); wordInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleGeneration(); }); const renderResults = (data) => { const createTags = (items) => items.map(item => `${item}`).join(''); associationsOutput.innerHTML = createTags(data.associations || []); synonymsOutput.innerHTML = createTags(data.thesaurus.synonyms || []); antonymsOutput.innerHTML = createTags(data.thesaurus.antonyms || []); if (data.thesaurus.antonyms.length === 0) { antonymsOutput.innerHTML = '

No direct antonyms found.

'; } pdfBtnContainer.classList.remove('hidden'); }; // --- PDF Export --- pdfBtn.addEventListener('click', () => { if (!lastResult) { showMessage('No results to download.', 'error'); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFontSize(18); doc.text(`Analysis for: ${lastResult.originalWord}`, 105, 20, { align: 'center' }); doc.autoTable({ startY: 30, head: [['Word Associations']], body: lastResult.associations.map(a => [a]), headStyles: { fillColor: [79, 70, 229] } }); doc.autoTable({ startY: doc.previousAutoTable.finalY + 10, head: [['Synonyms', 'Antonyms']], body: formatThesaurusForPdf(lastResult.thesaurus), headStyles: { fillColor: [79, 70, 229] } }); doc.save(`word-analysis-${lastResult.originalWord}.pdf`); }); const formatThesaurusForPdf = (thesaurus) => { const synonyms = thesaurus.synonyms || []; const antonyms = thesaurus.antonyms || []; const maxLength = Math.max(synonyms.length, antonyms.length); const rows = []; for (let i = 0; i < maxLength; i++) { rows.push([synonyms[i] || '', antonyms[i] || '']); } return rows; }; // --- Utility --- const showMessage = (message, type = 'success') => { messageBox.textContent = message; messageBox.className = `message-box ${type} show`; setTimeout(() => { messageBox.classList.remove('show'); }, 3000); }; });
Scroll to Top