// ==UserScript==
// @name          Dirty Talk
// @namespace     http://hacks.atrus.org/
// @description	  Spice up your web pages
// @include       http://*
// @include       https://*
// ==/UserScript==

(function() {
// Add more bad words as desired
var badwords=[ 
               "ass",
               "ass pirate",
               "asshole",
               "bitch",
               "bastard",
               "clits",
               "cock",
               "cum",
               "cunt",
               "damn",
               "dick",
               "dildo",
               "fag",
               "fuck",
               "fux0r",
               "gay",
               "h4x0r",
               "jackass",
               "lesbian",
               "lesbo",
               "motherfucker",
               "fatherfucker",
               "piss",
               "pr0n",
               "prick",
               "pussy",
               "queer",
               "scrotum",
               "sh!t",
               "shemale",
               "shit",
               "slut",
               "smut",
               "tits",
               "titties",
               "titty",
               "twat",
               "wank",
               "whore"];
//list of elements to not touch. should be lower case
var no_touch = ["script",
                "style" ]
// probability of inserting a dirty word
var prob = 0.3;

var els = document.evaluate("//*", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
var el,i=0,arr;

no_touch = no_touch.join( " " );
while (el=els.snapshotItem(i++)) {
  //don't mess with these tags
  if ( no_touch.indexOf( el.tagName.toLowerCase() ) != -1 ) continue;
  
  for (var j=0; j<el.childNodes.length; j++) {
    if ('#text'==el.childNodes[j].nodeName) {
      arr = el.childNodes[j].textContent.split( " " );
      // don't modify really short strings. avoids messing up pages too much
      if( arr.length > 3 ) {
        for( var k=0; k < arr.length; k++ ) {
          if( Math.random() < prob ) {
            var num = Math.random() * badwords.length;
            num = Math.floor( num );
            arr[ k ] += " " + badwords[ num ] + " ";
          }
        }
      }
      el.childNodes[j].textContent = arr.join( " " );
    }
  }
}

})();
