// Based on a script in Mark Pilgram's upcoming "Dive into Greasemonkey", as well as "renamer"

// ==UserScript== 
// @name          Eliminate excessive exclamation points
// @namespace     http://www.zieak.com
// @description   Turns 2-42 exclamation points into just one
// @include       * 
// ==/UserScript== 

// Why 42?  We should ask Earth before it is too late.


(function() {
  var replacements, regex, key, textnodes, node, s; 

  replacements = { 
    
    "!!!!!": "!",
    "!!!!": "!",
    "!!!": "!",
    "!!": "!",
    "!!!!!!": "!",
    "!!!!!!!": "!",
    "!!!!!!!!": "!",
    "!!!!!!!!!": "!",
    "!!!!!!!!!!": "!",
    "!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",
    "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!": "!",

    };

regex = {}; 
for (key in replacements) { 
    regex[key] = new RegExp(key, 'g'); 
} 

textnodes = document.evaluate( "//body//text()", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); 

for (var i = 0; i < textnodes.snapshotLength; i++) { 
    node = textnodes.snapshotItem(i); 
    s = node.data; 
    for (key in replacements) { 
        s = s.replace(regex[key], replacements[key]); 
    } 
    node.data = s; 
} 

})();