Simple link rewrite script
|
|
Hi, I'm trying to do something really basic but for some reason, I can't seem to get my poor excuse for a script to work (and Firefox's error console isn't much help either). Basically, what I'm trying to do is to rewrite a /b/ URL. The basic page layout is like this: link to a picture (href value is http://host/src/filename.jpg). And then we've got an image inline link to http://host/src.cgi/filename.jpg. Both are links actually reference the same file. Since the URLs aren't the same, all my scripts assume they reference different images. Therefore, what I'm trying to do is to cycle through a bunch of s/src/g calls which replace 'src' with 'src.cgi' (or vice versa). In any case, I want to the link and the inline href to point to the same URL but I can't seem to make it work. Any help would be greatly appreciated. :) -Tony |
|
|
Something like
for (var i = 0; i < document.images.length; i++) {
var image = document.images[i];
image.src = image.src.replace(/([^/]+)\.cgi/, '$1');
}
perhaps? |
|
|
Hi Henrik, thanks for your help. :) I'm doing something similar (although my code is a bit more... clumsy ;) but it still throws a couple of exceptions every once in a while. I'll see if it's just my browser (or one of my extensions) or something when I get a chance. Thanks again. - Tony Edit: Argh, I finally found the source of my problem. The script does in fact work. It's just that I'm trying to use it with an extension and since Greasemonkey only rewrites the page after it's been loaded, I'm seeing the modified page whereas the extension is seeing the original page. |
