This is one way to store a javascript as a favorite. It would be nice if there were a simpler way.
1) Create a favorite from anything.
2) Click on Favorites->Organize Favorites
3) Navigate to the one you just created.
4) Right click on it and choose Rename. Type a new name, such as "Get all JPEGs".
5) Right click again and choose Properties.
6) Click on the Web Document tab.
7) Paste the javascript code into the URL field.
8) Click OK. If you get a warning about no program being registered to handle that url, ignore it.