This could be done as a JavaScript plugin. The next version, which should be on the App Store any day, allows you to get the current page text via an API call. I may use your idea as the basis for a blog article on how to write simple plugins.
<script>
function count_words (text) {
show_word_count = true;
show_char_count = false;
var char_count = text.length;
var fullStr = text + " ";
var initial_whitespace_rExp = /^[^A-Za-z0-9]+/gi;
var left_trimmedStr = fullStr.replace(initial_whitespace_rExp, "");
var non_alphanumerics_rExp = rExp = /[^A-Za-z0-9]+/gi;
var cleanedStr = left_trimmedStr.replace(non_alphanumerics_rExp, " ");
var splitString = cleanedStr.split(" ");
var word_count = splitString.length -1;
if (fullStr.length <2) {
word_count = 0;
}
if (word_count == 1) {
wordOrWords = " word";
}
else {
wordOrWords = " words";
}
if (char_count == 1) {
charOrChars = " character";
} else {
charOrChars = " characters";
}
alert ("Word Count: " + word_count + wordOrWords);
}
function count_words_on_this_page() {
var page = trunkNotes.get('HomePage');
count_words(page.contents);
}
</script>
<a href="javascript:count_words_on_this_page()">Word count my home page</a>
Users browsing this forum: No registered users and 1 guest