[Greasemonkey] newsbie-question how to change and replace a link
with greasemonkey
Tina Weller
blond.woman at googlemail.com
Mon Feb 6 12:57:19 EST 2006
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