[Greasemonkey] newsbie-question how to change and replace a link with greasemonkey

Tina Weller blond.woman at googlemail.com
Mon Feb 6 13:21:31 EST 2006


Sorry, but the tip "\?" did not work. Perhaps another workaround is
possible:

At the moment the webpage contains links like this

http://www.xyz.de?=vpath/data/index.php

what I need is to change this into

http://www.abc.de/data/index.php

If it would be possible to tell greasemonkey to "Replace everything before
/data through http://www.abc.de/"
then I would not have the problem with the questionmark. Whiche lines in my
script to I have to change, to reach this goal?

Thanks a lot for your help

Tina




2006/2/6, Tina Weller <blond.woman at googlemail.com>:
>
> The instructions Neil gave me worked very fine. I have online one last
> problem. How can I replace a "?". I have to replace a Questionmark through
> nothing. The line looks like this:
>
> "?": "",
>
> If I have this line in the script, the whole script does not work. If I
> delete it, it works pretty fine! So I guess there is a problem replacing the
> "?". Can anyone help me?
>
> Tina
>
>
>
> (function() {
>     var replacements, regex, key, linknodes, link, linkUri, linkText, i,
> s;
>     replacements = {
>
>          "%2F": "/",
>          "%5F": "_",
>          "bib/": "",
>          "default.asp": "",
>          "vpath=/": "",
>          "?": "",
>         "%2E": "."};
>
>     regex = {};
>     for (key in replacements) {
>         regex[key] = new RegExp(key, 'g');
>     }
>
>     linknodes = document.evaluate(
>         "//a",
>         document,
>         null,
>         XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
>         null);
>
> for (var i = 0; i < linknodes.snapshotLength; i++) {
>    link = linknodes.snapshotItem(i);
>    s = link.href;
>
>         for (key in replacements) {
>             s = s.replace(regex[key], replacements[key]);
>         }
>         link.href = s;
>
> }
> })();
>
>
>
>
>
>
>
> 2006/2/6, Neil Greenwood <neil.greenwood.lists at gmail.com>:
> >
> > On 06/02/06, Neil Greenwood <neil.greenwood.lists at gmail.com > wrote:
> > >
> > > On 05/02/06, Tina Weller <blond.woman at googlemail.com> wrote:
> > > Hi Tina,
> > >
> > >     null);
> > >
> > >
> > > It's the line above, which gets all the text nodes. This means it gets
> > all
> > > the text in the document (including extra whitespace), but not the
> > text or
> > > URLs of links.
> > >
> > > Sorry, this is wrong. The original script *does* get the text of the
> > links, just not the URLs.
> >
> > Neil.
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
> >
>
>


More information about the Greasemonkey mailing list