views:

29

answers:

1

I have the following fairly basic greasemonkey script:

var newloc = location.href.replace(/^(.*)-xyz-(.*)$/i, "$1$2");
if (newloc != location.href)
    location.href = newloc;

That is, it basically strips out "-xyz-" from the URL and loads the page again. So if you navigate to "www.example.com/a-xyz-b/" it'll reload the page at "www.example.com/ab/".

Now, the script work fine if the page is an HTML page. But if I open a .jpg file or something that's not HTML then the script does not run at all.

Is this just a limitation of greasemonkey? That it only works if the page is actually text/html? What is an alternative way this functionality could be done?

+1  A: 

Yes, Greasemoney fires on the DOMContentLoaded event, which doesn't seem to trigger on media objects (no DOM).

Get around this by firing on the parent/referrer pages and changing the links there.

Or, if the file names are on the local machine, use a text editor or batch job to rename/rewrite the links/names.

If neither of these workarounds is viable, post the specific details of how you are feeding these URLS to FireFox (name the browser in use if it's not FF).

Brock Adams
Hmm, interesting. I was really only doing it as a favour for a client and I don't know all of the details, but thanks... you've given me some ideas to go on with. If I get any more, I'll update the question :)
Dean Harding