[Greasemonkey] New script doesn't seem to work

Aaron Boodman boogs at youngpup.net
Thu Oct 26 18:57:44 PDT 2006


Well for starters, you aren't doing anything with the return value of
the unascii() function.

You should either assign it to link.href, or else modify link.href
directly inside unascii().

Also, there is probably a more elegant form that will handle all ascii
escaping. Something like:

link.href = unescape(link.href)

might be enough for most things. Or you can get more specific:

link.href = link.href.replace(/\%([0-9a-f])/ig, function(m) { return
String.fromCharCode(parseInt(m[1], 16)); });

(not tested in the slightest, will probably need tweaking).

- a

On 10/23/06, BrentNewland <brent_newland at msn.com> wrote:
>
> I am trying to write a script that will rewrite all URLs to convert %2f to /
> and such (convert from ASCII). It doesn't seem to work. I tried making a
> link to http://www.google.com%2fwebmasters%2f in an HTML file and clicking
> it, but it wants to take me to http://www.google.com%2fwebmasters%2f/ (with
> the extension installed). I'm not that familiar with JS (I'm a PHP guy
> myself). Any tips?
>
> // ==UserScript==
> // @name          unASCII
> // @description   Replace ASCII elements in links with their real
> counterparts (i.e. %2f with /)
> // @include       *
> // ==/UserScript==
> function unASCIIChars(s)
> {
>  s = s.replace ( /%3A/g, ':' );
>  s = s.replace ( /%2F/g, '/' );
>  s = s.replace ( /%3F/g, '?' );
>  s = s.replace ( /%3D/g, '=' );
>  s = s.replace ( /%26/g, '&' );
>  s = s.replace ( /%2B/g, '+' );
>  s = s.replace ( /%25/g, '%' );
>  return s;
> };
> (function() {
> var allLinks, thisLink;
> allLinks = document.evaluate(
>     '//a[@href]',
>     document,
>     null,
>     XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
>     null);
> for (var i = 0; i < allLinks.snapshotLength; i++) {
>     thisLink = allLinks.snapshotItem(i);
>     unASCIIChars(thisLink);
> }
> })();
> --
> View this message in context: http://www.nabble.com/New-script-doesn%27t-seem-to-work-tf2492721.html#a6949376
> Sent from the MozDev - greasemonkey mailing list archive at Nabble.com.
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list