function performAudit() {
var text = document.getElementById('seoContentInput').value;
var resultDiv = document.getElementById('seoResults');
var wordCountSpan = document.getElementById('wordCountValue');
var readabilitySpan = document.getElementById('readabilityValue');
var densityList = document.getElementById('keywordDensityList');
if (!text.trim()) {
alert('Please enter some text to analyze.');
return;
}
var words = text.toLowerCase().match(/\b(\w+)\b/g);
var wordCount = words ? words.length : 0;
wordCountSpan.innerText = wordCount;
var readability = "Good";
if (wordCount 1500) readability = "Comprehensive";
readabilitySpan.innerText = readability;
readabilitySpan.style.color = wordCount < 300 ? "#e53e3e" : "#38a169";
var freq = {};
var stopWords = ['the', 'and', 'a', 'to', 'of', 'in', 'is', 'it', 'that', 'for', 'on', 'with', 'as', 'this', 'was', 'at', 'by', 'an', 'be', 'are'];
for (var i = 0; i 3 && stopWords.indexOf(word) === -1) {
freq[word] = (freq[word] || 0) + 1;
}
}
var sorted = [];
for (var key in freq) {
sorted.push([key, freq[key]]);
}
sorted.sort(function(a, b) { return b[1] – a[1]; });
var topWordsHtml = '
';
var limit = Math.min(sorted.length, 5);
for (var j = 0; j < limit; j++) {
var percentage = ((sorted[j][1] / wordCount) * 100).toFixed(1);
topWordsHtml += '- ' + sorted[j][0] + ': ' + sorted[j][1] + ' occurrences (' + percentage + '%)
';
}
topWordsHtml += '
';
densityList.innerHTML = topWordsHtml;
resultDiv.style.display = 'block';
}
function resetAudit() {
document.getElementById('seoContentInput').value = ";
document.getElementById('seoResults').style.display = 'none';
}