Greasemonkey replace text

Posted under » JavaScript on 20 December 2009

Replacer

(function() {
  var replacements, regex, key, textnodes, node, s; 

  replacements = { 
    
    "facebook": "channelnewsasia",
    "Teh": "The",
    "TEH": "THE",
    };

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; 
} 

})();


web security linux ubuntu GIT svn Raspberry apache mysql php drupal cake symfony javascript Ajax css