// ==UserScript==// @name          tagcount// @namespace     http://www.wayner.org/// @include       http://*.com/*// @include       http://*.boingboing.net/*// @include       http://*.*.com/*// @include       file:*.html// @description   Count certain words. // @exclude// ==/UserScript==    //// Recursively walk down the Document Object Model// tree and stop at the nodes with text that you can// see. This saves some time and also avoids inadvertantly// changing any text or embedded scripts. //window.textCountRecurse=function(node, keep, matchString) { var ans=0; var thisLevel=0; if (node.nodeType == 3) {// text node   thisLevel+=countWords(node); } else {   var child = node.firstChild;   while (child != null) {    if (node.nodeName.toLowerCase()==matchString){           ans+=textCountRecurse(child,true, matchString);    } else {       ans+=textCountRecurse(child, keep, matchString);    }    child = child.nextSibling;   }  } if (!keep) {   return ans; } return ans+thisLevel;}  // From: http://www.somacon.com/p355.phpfunction trim(stringToTrim) {	return stringToTrim.replace(/^\s+|\s+$/g,"");}//// This function breaks apart a string of text into// individual words and then counts them.// This is not the most accurate way to do this, but it will be good// enough for statistics... That is, it should be uniformly inaccurate.//window.countWords=function(node){    s=node.nodeValue.split(" ");   var ans=0;   for (var i=0;i<s.length;i++){      if (trim(s[i]).length>0){         ans++;      }    }   return ans;}  window.popup=function(){   return prompt("Give me a tag to count the words contained within."); }// Space Checking menu command    window.editList=function() {        popup();    }    GM_registerMenuCommand("Add a new replacement mapping with this form: replaceMe=withMe",                           editList); //// This code links the recursive tree replacement// function with the page loader. Every page that// fits the patterns defined in the header will // be given the text replacement treatment.//window.addEventListener("load", function() {     matchString=popup().toLowerCase();   var count=textCountRecurse(document.body,false,matchString);    alert("Word count="+count);}, false); 