Cost to Build a House Calculator Alabama

SEO Keyword Density & Content Analyzer

Optimize your content for search engines by monitoring keyword frequency and word count.

Word Count
0
Density %
0.00%
Occurrences
0
function analyzeSEO() { var text = document.getElementById('contentArea').value; var keyword = document.getElementById('targetKeyword').value.trim().toLowerCase(); var resultsPanel = document.getElementById('resultsPanel'); if (!text || !keyword) { alert('Please enter both a keyword and content to analyze.'); return; } resultsPanel.style.display = 'block'; // Clean and split text var cleanText = text.replace(/[^\w\s]|_/g, "").replace(/\s+/g, " "); var words = cleanText.trim().split(/\s+/); var wordCount = words.length; // Count keyword occurrences (including phrases) var escapedKeyword = keyword.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); var regex = new RegExp('\\b' + escapedKeyword + '\\b', 'gi'); var matches = text.match(regex); var occurrences = matches ? matches.length : 0; // Calculate density var density = (occurrences / wordCount) * 100; // Update UI document.getElementById('wordCount').innerText = wordCount; document.getElementById('keywordCount').innerText = occurrences; document.getElementById('densityPercent').innerText = density.toFixed(2) + '%'; var adviceBox = document.getElementById('seoAdvice'); var adviceText = ""; var bgColor = ""; var textColor = ""; if (density === 0) { adviceText = "Warning: Target keyword not found in content. Use the keyword naturally in your headings and body text."; bgColor = "#fce8e6"; textColor = "#d93025"; } else if (density > 0 && density <= 0.5) { adviceText = "Optimization Needed: Keyword density is quite low. Try to include the keyword a few more times in key areas like the introduction or subheadings."; bgColor = "#fef7e0"; textColor = "#b06000"; } else if (density > 0.5 && density <= 2.5) { adviceText = "Great job! Your keyword density is in the optimal range (0.5% – 2.5%) for modern SEO. Ensure your content remains readable and provides value."; bgColor = "#e6f4ea"; textColor = "#137333"; } else { adviceText = "Warning: Keyword Stuffing detected. Your density is over 2.5%. This may lead to search engine penalties. Remove some occurrences to make the content flow more naturally."; bgColor = "#fce8e6"; textColor = "#d93025"; } adviceBox.innerHTML = adviceText; adviceBox.style.backgroundColor = bgColor; adviceBox.style.color = textColor; }

Leave a Comment