Neat Nice New Notelet Nodelet > notelet nodelet utilities

Welcome! You can use this utility for getting a word count of selected text and for calculations.

This utility is a button that upon clicking will prompt you with a dialog box containing a word count of selected text. If you replace the text with an arithmetical expression and then click OK, the script should return a calculation. Otherwise, clicking OK on an unmodified text or clicking Cancel will exit the program. You can press the return key for OK, the escape key for Cancel.

Version: 1.1 (more compact)

This is the cross-platform version (254 characters):
<button onclick="
d=document;p=d.all?d.selection.createRange().text:d.getSelection();
q=p.replace(/&#91;^\w\s&#93;/g,'').replace(/&#91;\s&#93;+$/,'').
split(/&#91;\s&#93;+/).length;do{eval('p='+q);q=prompt('',p);}
while(q&&q!=p);">Word Count</button>
Below are more economical, browser-specific versions.

Version for Mozilla (approx. 204 characters):
<button onclick="q=document.getSelection().
replace(/&#91;^\w\s&#93;/g,'').replace(/&#91;\s&#93;+$/,
'').split(/&#91;\s&#93;+/).length;do{eval('p='+q);
q=prompt('',p);}while(q&&q!=p);">Word Count</button>
Version for Internet Explorer (aprox. 178 characters):
<button onclick="q=document.selection.createRange().text.
replace(/&#91;^\w\s&#93;/g,'').split(/\s/).length;do{
eval('p='+q);q=prompt('',p);}while(q&&q!=p);">Word Count
</button>

Log in or register to write something here or to contact authors.