开发者

Running a greasemonkey script on a non-HTML page

开发者 https://www.devze.com 2023-01-18 09:52 出处:网络
I have the following fairly basic greasemonkey script: var newloc = location.href.replace(/^(.*)-xyz-(.*)$/i, \"$1$2\");

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 开发者_C百科text/html? What is an alternative way this functionality could be done?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消