After chopping up another Greasemonkey script, I've gotten this far.

var words = {
        "what" : "test",
}

var matches=new Array()
var replacements=new Array()

for(var word in words) {
                matches.push(new RegExp("\\b"+word+"\\b", 'gi'));
                replacements.push(words[word]);
}

var texts = document.evaluate(".//text()[normalize-space(.)!
='']",document.body,null,6,null), text="";

for(var i=0,l=texts.snapshotLength; (this_text=texts.snapshotItem(i));
i++) {
        if(text=this_text.textContent) {
                for(var x=0,l=matches.length; x<l; x++) {
                        text = text.replace(matches[x],replacements[x]);
                        this_text.textContent = text;
                }
        }
}

This will replace any instance of the word "what" with "test".
However, there's still a few problems. First, I need the variable
"what" in the "words" array to have multiple values, an array within
an array, something like this.

var words = {
        "what" : ["test", "test2", "test3"]
}

Then I need to be able to call it, rather than using
"replacements[x]", with something like words[x][1] to replace it with
"test" or words[x][2] to replace it with "test2". Lastly, I need to be
able to look at the word BEFORE and AFTER the matching word, with
different cases pulling different values of words[x], for one match to
pull words[x][1] and one to pull words[x][2].

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to