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

Tina Weller blond.woman at googlemail.com
Mon Feb 6 00:03:51 EST 2006


thx all for your help. i found a little script, which should exactly do what
I want. The problem is, that this litte script works well replacing visible
text. But it does not replace the links. Can anyone tell my why this is so?
If I understand it right, it should replace all the text:


// DumbQuotes
// version 0.4 BETA!
// 2005-05-02
// Copyright (c) 2005, Mark Pilgrim
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey 0.3 or later: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "DumbQuotes", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          DumbQuotes
// @namespace     http://diveintomark.org/projects/greasemonkey/
// @description   straighten curly quotes and apostrophes, simplify fancy
dashes, etc.
// @include       *
// ==/UserScript==
//
// --------------------------------------------------------------------
//
// This script is dedicated to Cory Doctorow, who will know why.
//

var replacements, regex, key, textnodes, node, s;

replacements = {
    "bib/default.asp?vpath=/bibdata/": "bibdata/",
    "%2F": "/",
    "%2E": ".";
regex = {};
for (key in replacements) {
    regex[key] = new RegExp(key, 'g');
}

textnodes = document.evaluate(
    "//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;
}

//
// ChangeLog
// 2005-05-02 - 0.4 - MAP - remove anon function wrapper, require GM 0.3
// 2005-04-21 - 0.3 - MAP - linted
// 2005-04-18 - 0.2 - MAP - tidy code
//








2006/2/5, Jeremy Dunck <jdunck at gmail.com>:
>
> On 2/5/06, Charles Iliya Krempeaux <supercanadian at gmail.com> wrote:
> > Hello Tina,
> >
> > On 2/5/06, Tina Weller <blond.woman at googlemail.com> wrote:
> > > is it possible to do the following with Greasemonkey?
> ...
> > Yes, it is possible.  (And, depending on your JavaScript experience)
> pretty
> > easy to do.
>
> And now, Charles, please dazzle us with your JavaScript experience.
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list