>
> // ==UserScript==
> // @name          Link text replacer
> // @namespace     here
> // @description   replace text in links
> // @include       *
> // ==/UserScript==
>
>
> var anchors = document.getElementsByTagName('a');
>
> for ( var i = 0; i<  anchors.length; i++ ) {
>      var link = anchors[i].href.replace( /google/, "foo" );
>      var link = anchors[i].href.replace( /trafficholder.com/, "" );
>    
This line is wrong and makes the previous line useless -- it 
(re)declares |link|, and overwrites the previous value. Try

     link = link.replace(/trafficholder\.com/, "");

(Note too that I fixed your unescaped '.' metacharacter -- as typed, 
that spot would have matched any single character, instead of just 
matching the literal '.'. Do you really need to be using regexes for 
search patterns, and wouldn't it be better to just type the literals out 
as ordinary strings?)
>      anchors[i].href = link;
> }
>    
Finally, one last note: the script does not currently handle <a> 
elements without href attributes (e.g. section headers inserted to allow 
#section-style URLs). Wrap the three inner lines of the for block in an 
if block, like so:

   if (anchors[i].href) {
     //...
   }


--

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