Skip to content

Instantly share code, notes, and snippets.

@bKNN
Last active November 12, 2018 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bKNN/d3d9491dad366dea10fbd61945b1beff to your computer and use it in GitHub Desktop.
Save bKNN/d3d9491dad366dea10fbd61945b1beff to your computer and use it in GitHub Desktop.
BOOKMARKLET - Wordcount
javascript:(function(){function f(d){var t;if(d.getSelection)t=d.getSelection();else if(d.selection)t=d.selection.createRange();if(t.text!=undefined)t=t.text;if(!t||t==''){var a=d.getElementsByTagName('textarea');for(var i=0;i<a.length;++i){if(a[i].selectionStart!=undefined&&a[i].selectionStart!=a[i].selectionEnd){t=a[i].value.substring(a[i].selectionStart,a[i].selectionEnd);break;}}} return t;};function g(d){var t;try{t=f(d);}catch(e){};if(!t||t==''){var fs=d.getElementsByTagName('frame');for(var i=0;i<fs.length;++i){t=g(fs[i].contentDocument);if(t&&t.toString()!='')break;} if(!t||t.toString()==''){fs=d.getElementsByTagName('iframe');for(var i=0;i<fs.length;++i){t=g(fs[i].contentDocument);if(t&&t.toString()!='')break;}}}return t;};var t=g(document);if(!t||t=='')alert('please select some text');else alert('Chars: '+t.toString().length+'\nWords: '+t.toString().match(/(\S+)/g).length);})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment