ej400 wrote: ↑January 30th, 2023, 1:53 am
TriciaG wrote: ↑January 29th, 2023, 5:52 am
I've got a bookmarklet - a little piece of javascript code on my bookmark toolbar. It looks like a regular bookmark but isn't.
I highlight the text I want to count and click the bookmark, and there's the word count!
Put this in the URL field of the bookmark:
Code: Select all
javascript:d=window.getSelection()+'';%20d=(d.length==0)?document.title:d;%20alert(d.split('%20').length+'%20words,%20'+d.length+'%20characters');
This has to be the easiest way! That is incredibly useful, Tricia. Thank you very much for sharing that!
Hi LibriVoxers,
I work hard to be lazy.

I took the bookmarklet that TriciaG shared, and modified it:
*
This will accurately word-count Gutenberg texts with one click, without needing to select the text.
* It only works using the plainText version of the text.
* This will parse only the text of the book, everything between the
*** START OF _____ *** through to
*** END OF ____ ***. (This does include the "transcriber's note" that is sometimes present, but that is easily subtracted from the total count.)
Note: This bookmarklet more accurately counts every word, taking into account "newline" characters that are not parsed by the original word count bookmarklet. That one only separates words by spaces, so selections that span multiple paragraphs (in HTML view) or lines (in plaintext) result in slightly or greatly inaccurate word counts.
To use:
* save this code as a bookmarklet
* Navigate to a Gutenberg title, and click to the Plain Text version
* Click the bookmarklet (no text selection needed)
Code: Select all
javascript:if(document.location.toString().match(/gutenberg.org.*\.txt$/)){d=document.body.innerHTML.match(/(?<=\*{3} START.*? \*{3}).*(?=\*{3} END.*?\*{3})/s)[0].trim();alert(d.split(/[ \n\*/]+/).length+' words, '+d.length+' characters');}else{alert("Use the Gutenberg plaintext version");}
For completeness, here is the original bookmarklet that was posted by TriciaG, modified to be as accurate as above (splits on space, newline and "*").
Code: Select all
javascript:d=(window.getSelection()+'').trim();d=(d.length==0)?document.title:d;alert(d.split(/[ \n\*]+/).length+' words,'+d.length+' characters');
Happy counting!
Edit: Updated the code for both bookmarlets so that they would ignore non-word characters at the beginning and end of the selection.