Thursday, October 7, 2010

Word counter on Opera browser

To improve reading comprehension in English, Reading paragraphs quickly is important.
According to Wikipedia, the average American adult reads prose text at 250 to 300 words per minute.

http://en.wikipedia.org/wiki/Words_per_minute#Reading_and_comprehension

When I read articles in English on web site, I want word counter to know the number of words in the articles.
It will be better if it works on my favorite Opera browser.
I tried to find a way to count words on the browser.

Word counter
http://extendopera.org/userjs/content/word-counter

I installed it and It works fine but it is just for counting words in text area.
I want to count words that are not only in text areas but also in plain text.
So I re-write it so that it works as a javascript URL.


javascript:(function(){
/* %s */
var rx=/\r\n/g,rt=/\+/g,nl='\n',w='Words: ',c=' / Characters: ', reTrim = /^\s+|\s+$/g, reWhiteSpace = /[\s\f\t]+/;
var txt= (document.selection?
document.selection.createRange().text:
window.getSelection?
window.getSelection():
window.selection?
window.selection.createRange().text:
document.getSelection?
document.getSelection():
'')+ '';
txt = txt.replace(rx,nl).replace(rt,nl);
window.status=w+(txt?txt.replace(reTrim, '').split(reWhiteSpace).length:0)+c+txt.length;
})()


Here is how to register this script to Opera browser.

1. Press Ctrl-F12 to show Preference dialog and click "Search" tab.
2. Click "Add" and the dialog to register a search engine.
3. Input "Word counter" into "Name."
4. Input "c" into "Keyword." If you have used "c" at Keyword, change it one which is not used yet.
5. Copy the script above and paste it into "Address".
6. Click "Ok"

If you want to count the number of word, select words with the mouse pointer, move the pointer on the selection and click the right button of the mouse. Then choose "Word counter." in the "Search With" item. The number of words and characters are displayed at the below of the browser.

2 comments:

  1. I found a defect that the word counter doesn't when the selected words contain "'" character. I want to fix it sometime.

    ReplyDelete
  2. The script was fixed and it works.
    I referenced the script at
    http://shinshu.fm/MHz/14.30/archives/0000217875.html

    ReplyDelete