Gallery bookmarklet (javascript help needed)

The gallery lost its download link for video files. Since then it has been difficult to download video files from the gallery. I like saving video files I like so I made a quick and dirty bookmarklet to make the process easier. The bookmarklet is on my backcountry.unicyclist.com web page.

The bookmarklet works better in Firefox than IE. It hasn’t been tested on other browsers and has only been tested on Windows.

It has issues that I’m not sure can be worked around within the limits of javascript. Javascript experts are welcome to improve on it.

Problems:
It doesn’t work on all video file types. For example, Real Media files don’t work because they aren’t embedded in the page the same way as other formats.

It doesnt automatically prompt to save some file types. This is due to how the browser defaults for the particular file type. You can change the behavior for specific file types in Firefox if the bookmarklet plays the video instead of prompting to save the video.

  • In Firefox: Tools >> Options >> Downloads >> Download Actions: View & Edit Actions...
  • Select the file type extension you want to change
  • Change Action...
  • Change the default to "Save them on my computer"
I don't know how to do the same for IE.

Here is the code for the bookmarklet all formatted. The bookmarklet itself has the code all scrunched onto one line which makes it difficult to read.


var fn=document.getElementsByTagName('param');
for (i=0;i<fn.length;i++)
{
  if (fn[i].value.length > 0 && fn[i].name == 'FileName')
  {
    window.location.href=fn[i].value;
    alert('Select File >> Save As or File >> Save Page As to save the video if the video does not save automatically');
  } 
};

One nice feature is that the bookmarklet is able to save some of the file types with the original file name that the file was uploaded as, instead of trying to name the file something like “main.php” or something like that.

This is all stretching the boundaries of my javascript-fu. Ideas and code for improvements is welcome. The current version is quick and dirty. Not much error checking. If someone could test it on a Mac that would be cool too.

Anyone know why the video downloads sometimes have the correct file name and most other times will default to main.php? The filename must be stored somewhere since it is being retrieved in some cases. But if I link directly to the file I don’t get the filename.

The current bookmarklet manages to fetch the correct filename in most cases, but I’m not sure why.