Online Word Choice Enhancer

Online Word Choice Enhancer

Elevate your writing by replacing common words with stronger alternatives.

Please enter some text to enhance.

'; elements.resultsSummary.textContent = ''; elements.resultsSection.classList.remove('hidden'); return; } enhancedWords = {}; const wordsToFind = Object.keys(wordMap); const regex = new RegExp(`\\b(${wordsToFind.join('|')})\\b`, 'gi'); let enhancementCount = 0; const highlightedHtml = text.replace(regex, (match) => { enhancementCount++; const lowerCaseMatch = match.toLowerCase(); enhancedWords[lowerCaseMatch] = wordMap[lowerCaseMatch]; const suggestions = wordMap[lowerCaseMatch].join(', '); return `${match}`; }).replace(/\n/g, '
'); elements.resultsContainer.innerHTML = highlightedHtml; elements.resultsSummary.textContent = `Found ${enhancementCount} words with potential enhancements. Hover over a highlighted word to see suggestions.`; elements.resultsSection.classList.remove('hidden'); }; const handleDownloadPdf = () => { const { jsPDF } = window.jspdf; if (!jsPDF) { console.error("jsPDF is not loaded."); return; } const doc = new jsPDF({ orientation: 'portrait', unit: 'in', format: 'letter' }); const originalText = elements.textInput.value; const margin = 0.75; const pageWidth = doc.internal.pageSize.getWidth(); const usableWidth = pageWidth - (margin * 2); let currentY = 0; // PDF Header doc.setFillColor('#4338ca'); // indigo-700 doc.rect(0, 0, pageWidth, 1.5, 'F'); doc.setFont('helvetica', 'bold'); doc.setFontSize(22); doc.setTextColor('#ffffff'); doc.text('Vocabulary Enhancement Guide', margin, 0.9); doc.setFontSize(11); doc.setTextColor('#c7d2fe'); // indigo-200 doc.text(`Based on your provided text`, margin, 1.2); currentY = 2.0; // Original Text Section doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.setTextColor('#1e1b4b'); // indigo-900 doc.text('ORIGINAL TEXT', margin, currentY); doc.setDrawColor('#d1d5db'); doc.line(margin, currentY + 0.05, pageWidth - margin, currentY + 0.05); currentY += 0.3; doc.setFont('times', 'normal'); doc.setFontSize(11); doc.setTextColor('#374151'); const textLines = doc.splitTextToSize(originalText, usableWidth); doc.text(textLines, margin, currentY); currentY += (textLines.length * 0.2) + 0.4; // Vocabulary Suggestions Section if (currentY > 8) { doc.addPage(); currentY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(12); doc.setTextColor('#1e1b4b'); doc.text('VOCABULARY SUGGESTIONS', margin, currentY); doc.line(margin, currentY + 0.05, pageWidth - margin, currentY + 0.05); currentY += 0.3; if (Object.keys(enhancedWords).length > 0) { doc.setFont('helvetica', 'normal'); for (const word in enhancedWords) { if (currentY > 10.2) { doc.addPage(); currentY = margin; } doc.setFont('helvetica', 'bold'); doc.setFontSize(11); doc.setTextColor('#4f46e5'); // indigo-600 doc.text(word.charAt(0).toUpperCase() + word.slice(1), margin, currentY); doc.setFont('helvetica', 'italic'); doc.setFontSize(10); doc.setTextColor('#6b7280'); // gray-500 const suggestions = enhancedWords[word].join(', '); const suggestionLines = doc.splitTextToSize(suggestions, usableWidth - 1.5); doc.text(suggestionLines, margin + 1.5, currentY); currentY += (suggestionLines.length * 0.18) + 0.2; } } else { doc.setFont('helvetica', 'italic'); doc.setFontSize(10); doc.setTextColor('#6b7280'); doc.text("No words were flagged for enhancement in the provided text.", margin, currentY); } doc.save('Word-Choice-Enhancement-Guide.pdf'); }; // --- Tooltip Logic --- const showTooltip = (e) => { const target = e.target; if (!target.classList.contains('highlight-enhance')) return; const suggestions = target.getAttribute('data-suggestions'); elements.tooltip.textContent = `Suggestions: ${suggestions}`; elements.tooltip.classList.add('visible'); const rect = target.getBoundingClientRect(); const tooltipRect = elements.tooltip.getBoundingClientRect(); // Position tooltip above the word let top = rect.top + window.scrollY - tooltipRect.height - 8; let left = rect.left + window.scrollX + (rect.width / 2) - (tooltipRect.width / 2); // Adjust if it goes off-screen if (left < 0) left = 5; if (left + tooltipRect.width > window.innerWidth) left = window.innerWidth - tooltipRect.width - 5; if (top < window.scrollY) top = rect.bottom + window.scrollY + 8; elements.tooltip.style.left = `${left}px`; elements.tooltip.style.top = `${top}px`; }; const hideTooltip = (e) => { if (e.target.classList.contains('highlight-enhance')) { elements.tooltip.classList.remove('visible'); } }; // --- Event Listeners --- elements.enhanceTextBtn.addEventListener('click', analyzeText); elements.downloadPdfBtn.addEventListener('click', handleDownloadPdf); elements.resultsContainer.addEventListener('mouseover', showTooltip); elements.resultsContainer.addEventListener('mouseout', hideTooltip); });
Scroll to Top