I needed this for something, it’s pretty simple javascript but hey who knows. All it does is take all the words on a page and counts them, then lists them from highest count to lowest count (I only show the top 20).
var pageKeywords;
var keywordAmount = 20;
var commonWords = ['you','cached','the','who','there','thier','are','our','com','www','and','for'];
pageKewords = count(getText(document.body));
alert(pageKeywords);
function getText(n) {
var s = [];
function getStrings(n, s) {
var m;
if (n.nodeType == 3) { // text_NODE
s.push(n.data);
}
else if (n.nodeType == 1) { // ELEMENT_NODE
for (m = n.firstChild; null != m; m = m.nextSibling) {
getStrings(m, s);
}
}
}
getStrings(n, s);
var result = s.join(" ");
return result;
}
function rever(str) { var inp = str; var outp = ""; for (i = 0; i <= inp.length; i++) { outp = inp.charAt (i) + outp; } return outp; }
function fmtNum(num) {
return ""+new String(100000-num).substring(1);
return num;
}
function count(str) {
var words = str.replace(/[^a-zA-Z0-9]/g,' ').toLowerCase().split(' ');
var assoc = new Array();
for (i=0; i 2){
var isInCommon = false;
for(i=0; i
if(commonWords[i] == word){
isInCommon = true;
}
}
if(!isInCommon){
output[output.length]=fmtNum(assoc[word])+':'+word;
}
}
}
output.sort();
output = output.splice(0,keywordAmount);
var keywords = Array();
for (i=0; i
keywords[i] = output[i].split(":")[1];
}
return keywords.join("|");
}
So if you ever want to find word counts on a page, now you can
.
(I’m not good, so I am not saying this is a good way of doing anything)