Calculating Total Manufacturing Cost

SEO Content Analyzer

Words
0
Characters
0
Reading Time
0m

Top Keyword Density

function analyzeSEOText() { var text = document.getElementById('seo-input-text').value; var wordCountDisplay = document.getElementById('res-word-count'); var charCountDisplay = document.getElementById('res-char-count'); var readTimeDisplay = document.getElementById('res-read-time'); var densitySection = document.getElementById('keyword-density-section'); var densityTable = document.getElementById('density-table'); if (!text.trim()) { alert('Please enter some text to analyze.'); return; } // Basic Stats var cleanText = text.replace(/[^\w\s]/gi, "); var wordsArray = cleanText.toLowerCase().split(/\s+/).filter(function(word) { return word.length > 0; }); var wordCount = wordsArray.length; var charCount = text.length; var readingTime = Math.ceil(wordCount / 225); wordCountDisplay.innerText = wordCount; charCountDisplay.innerText = charCount; readTimeDisplay.innerText = readingTime + 'm'; // Keyword Density var freqMap = {}; var stopWords = ['the', 'and', 'a', 'to', 'of', 'in', 'is', 'it', 'with', 'for', 'on', 'was', 'as', 'at', 'by', 'an', 'be', 'this', 'that', 'are', 'or']; for (var i = 0; i < wordsArray.length; i++) { var word = wordsArray[i]; if (word.length -1) continue; freqMap[word] = (freqMap[word] || 0) + 1; } var sortedKeywords = []; for (var key in freqMap) { sortedKeywords.push([key, freqMap[key]]); } sortedKeywords.sort(function(a, b) { return b[1] – a[1]; }); var html = '
'; var limit = Math.min(sortedKeywords.length, 5); for (var j = 0; j < limit; j++) { var keyword = sortedKeywords[j][0]; var count = sortedKeywords[j][1]; var percent = ((count / wordCount) * 100).toFixed(1); html += '
' + '' + keyword + '' + '' + count + ' times' + '' + percent + '%' + '
'; } html += '
'; densityTable.innerHTML = html; densitySection.style.display = 'block'; } function clearSEOText() { document.getElementById('seo-input-text').value = "; document.getElementById('res-word-count').innerText = '0'; document.getElementById('res-char-count').innerText = '0'; document.getElementById('res-read-time').innerText = '0m'; document.getElementById('keyword-density-section').style.display = 'none'; }

Leave a Comment