-
Notifications
You must be signed in to change notification settings - Fork 3
/
jquery.wordstats.min.js
1 lines (1 loc) · 3.27 KB
/
jquery.wordstats.min.js
1
jQuery.wordStats={unsortedWords:null,sortedWords:null,topWords:null,topWeights:null,_computed:false,addWords:function(e,d){if(e&&e.length>1){var b=this.splitWords(e.toLowerCase());for(var a=0,f=b.length;a<f;a++){word=b[a];if(word.length>1&&!this.stopWords[word]){if(this.unsortedWords[word]){this.unsortedWords[word]+=d}else{this.unsortedWords[word]=d}}}}},addWordsFromTextNodes:function(e,f){var a=e.childNodes;for(var d=0,b=a.length;d<b;d++){if(a[d].nodeType==3){this.addWords(a[d].nodeValue,f)}}},testChar:function(a){return((a>=97&&a<=122)||(a>=128&&a<=151)||(a>=160&&a<=164)||(a>=48&&a<=57)||(a>=224&&a<=246)||(a>=249&&a<=255))},splitWords:function(f){var a=new Array(),e="";for(var d=0,b=f.length;d<b;d++){c=f.charCodeAt(d);if(this.testChar(c)){e+=f.substring(d,d+1)}else{a.push(e);e=""}}if(e.length>0){a.push(e)}return(a)},computeWords:function(a){if(!a){a=window.document}this.unsortedWords=new Array();if(a.is("textarea")){this.addWords(a.val(),1);return}this.addWords($("title",a).text(),20);wordstats=this;$("h1",a).each(function(){wordstats.addWordsFromTextNodes($(this).get(0),15)});$("h2",a).each(function(){wordstats.addWordsFromTextNodes($(this).get(0),10)});$("h3, h4, h5, h6",a).each(function(){wordstats.addWordsFromTextNodes($(this).get(0),5)});$("strong, b, em, i",a).each(function(){wordstats.addWordsFromTextNodes($(this).get(0),3)});$("p, div, th, td, li, a, span",a).each(function(){wordstats.addWordsFromTextNodes($(this).get(0),2)});$("img",a).each(function(){wordstats.addWords($(this).attr("alt"),1);wordstats.addWords($(this).attr("title"),1)});this._computed=true},computeTopWords:function(d,b){if(!this._computed){this.computeWords(b)}this.topWords=new Array();this.topWeights=new Array();this.topWeights.push(0);for(word in this.unsortedWords){for(var a=0;a<d;a++){if(this.unsortedWords[word]>this.topWeights[a]){this.topWeights.splice(a,0,this.unsortedWords[word]);this.topWords.splice(a,0,word);break}}}},sortWords:function(){this.sortedWords=new Array();i=0;for(word in this.unsortedWords){this.sortedWords[i]=word;i++}this.sortedWords.sort(function(e,d){return wordstats.unsortedWords[d]-wordstats.unsortedWords[e]})},clear:function(){this.unsortedWords=this.sortedWords=this.topWords=this.topWeights=null;this._computed=false},setStopWords:function(a){for(var b in this.stopWords){this.stopWords[b]=a}}};jQuery.wordStats.stopWords={about:true,after:true,ago:true,all:true,also:true,an:true,and:true,any:true,are:true,as:true,at:true,be:true,been:true,before:true,both:true,but:true,by:true,can:true,did:true,"do":true,does:true,done:true,edit:true,even:true,every:true,"for":true,from:true,had:true,has:true,have:true,he:true,here:true,him:true,his:true,however:true,"if":true,"in":true,into:true,is:true,it:true,its:true,less:true,many:true,may:true,more:true,most:true,much:true,my:true,no:true,not:true,often:true,quote:true,of:true,on:true,one:true,only:true,or:true,other:true,our:true,out:true,re:true,says:true,she:true,so:true,some:true,soon:true,such:true,than:true,that:true,the:true,their:true,them:true,then:true,there:true,these:true,they:true,"this":true,those:true,though:true,through:true,to:true,under:true,use:true,using:true,ve:true,was:true,we:true,were:true,what:true,where:true,when:true,whether:true,which:true,"while":true,who:true,whom:true,"with":true,within:true,you:true,your:true};