1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

greasemonkey javascript replace help

Discussion in 'HTML & JavaScript' started by foxler, Jun 3, 2008.

  1. foxler

    foxler Regular Member

    Joined:
    Mar 7, 2008
    Messages:
    279
    Likes Received:
    159
    I found a greasemonkey javascript script that replaces text on a page with whatever you want and I'm trying to get it to work with these forums to replace those dam *'s with blank spaces to help legibility.

    I tried replacing the replacements variable with the following
    *
    /*/g
    \*
    and none of them seem to work to replace all asterisk with blanks


    Code:
    // Based on a script in Mark Pilgram's upcoming "Dive into Greasemonkey", as well as "renamer"
    
    // ==UserScript== 
    // @name          Eliminate all asterisks
    // @namespace     http://www.zieak.com
    // @description   Gets rid of the asterisks
    // @include       * 
    // ==/UserScript== 
    
    
    
    
    (function() {
      var replacements, regex, key, textnodes, node, s; 
    
      replacements = { 
        // replace asterisk with blank
        "*": "" ,
    
        };
    
    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; 
    } 
    
    })();
    If anyone knows what the regex is, please help :)
     
  2. anonymous

    anonymous Newbie

    Joined:
    Dec 17, 2007
    Messages:
    32
    Likes Received:
    0
    Occupation:
    Slave Trader
    probably there shouldnt be a comma after "*": ""
    I mean at least after the last defination.
    Ex:
    "*": "",
    "-": "^^",
    "=": "+"(no comma)