[Greasemonkey] New script doesn't seem to work
BrentNewland
brent_newland at msn.com
Mon Oct 23 00:07:55 PDT 2006
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.
More information about the Greasemonkey
mailing list