<div>
<p>
Questo è un testo di prova <a href="#go">Vai</a>
</p>
<p>
non lo so questo è un altro testo in un paragrafo di testo
</p>
</div>
<div class="response"></div>
JavaScript
/*
Coded by Leonardo Ciaccio
App : Conta la densita delle parole nella pagina, restituisce solo i candidati
*/
( function(){
var words = {},
min = 3,
minresult = 2,
maxdisplay = 5;
function $( selector ){
return document.querySelector( selector );
};
$.grep = function( items, callback ){
var filtered = [],
len = items.length,
i = 0;
for( i; i < len; i++ ){
if( callback( items[ i ] ) )filtered.push( items[ i ] );
}
return filtered;
};
function _countWords(){
// Prelevo tutte le parole
var finder = new RegExp( "[a-zA-Z0-9]{" + min + ",}\\S", "gi" ),
all = document.body.innerText.match( finder );
if( !all )return false;
// Contiamo le parole
for( var i = 0; i < all.length; i++ ){
var ident = all[ i ].toLowerCase();
words[ ident ] = ( !words[ ident ] ) ? 1 : words[ ident ] + 1 ;
}
// Le ordiniamo in ordine decrescente
var sortable = [];
for( var word in words ){
sortable.push( [ word, words[ word ] ] );
}
sortable.sort( function( a, b ){ return b[ 1 ] - a[ 1 ] } );
var sortable = $.grep( sortable, function( word ){
return ( word[ 1 ] >= minresult );
} );
var candidate = "Words density :\r\n";
for( i = 0; i < maxdisplay && i < sortable.length; i++ ){
candidate+= sortable[ i ].join( " = " ) + "\r\n";
}
alert( candidate );
};
_countWords();
} )();
/*
Minificato per bookmarklets
(function(){var...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.