Firefox extension to control HTML forms?
January 30, 2007 7:19 AM   Subscribe

Can a user install an extension, preference or script to have Firefox manipulate an HTML form element on loading, e.g., having a SELECT's default OPTION set when visiting a certain page.

If a user visits a webpage that, for example, requests selecting a drop-down menu containing different server names, I'd like to have the user be able to set his or her default server and then have the pull-down menu set upon each visit.

I don't have the option of doing this server-side, or setting cookie variables, since I don't administrate the web server or application.

Thanks for any advice!
posted by Blazecock Pileon to Computers & Internet (11 answers total)
 
Extensions can run arbitrary javascript, yes. You probably want to find a demo extension or something similar to what you want
(say, Linkification) and base it off of that. Or, if you wanted to make it really easy, just write a Greasemonkey script.
posted by spaceman_spiff at 7:26 AM on January 30, 2007


Response by poster: I don't have the time to hack and test a script. Is there something pre-written?
posted by Blazecock Pileon at 7:32 AM on January 30, 2007


Response by poster: Or, rather, I'm looking for something I can distribute to end users who may not be savvy enough to manipulate the DOM or write and test a chunk of JavaScript.
posted by Blazecock Pileon at 8:13 AM on January 30, 2007


This might work, I haven't used it.

But I'm not sure how you intend to do all of this without coding at all... your users wouln't need to manipulate the DOM or test JS, but I would hope you are able to. Greasemonkey does make it very easy, just download the extension and do the tutorials.
posted by tmcw at 8:38 AM on January 30, 2007


Response by poster: Greasemonkey does make it very easy, just download the extension and do the tutorials.

I'm sure it would be easy for me, but not for end users. I need something I can distribute that they would reliably be able to set up on their own, without our assistance or troubleshooting.
posted by Blazecock Pileon at 9:16 AM on January 30, 2007


Blazecock: it can be simple for them. All they have to do is look the preferences, which you can set up. So they choose the option they want from a list (if you know ahead of time what page they're going to, or what the options are), or they can type in the option they want (if you don't know what the options are in advance).

Then, have the script 'grab' all the options from the page - they'll be in an array. Once you find which one is the one you want (Dom_Stuff_Here.value == userSelectedOption), then you can manipulate the dom to select that option.
posted by spaceman_spiff at 11:05 AM on January 30, 2007


Are you talking about always applying your preference to a specific page and a specific option? Or are you looking for something which can be adapted for any page and any option?
posted by AmbroseChapel at 12:03 PM on January 30, 2007


Response by poster: Or are you looking for something which can be adapted for any page and any option?

Yes.
posted by Blazecock Pileon at 12:36 PM on January 30, 2007


Have the Greasemonkey script you provide fire on window load. Walk the document tree for selects and put them in an array. Set event listeners on 'change' for each select you want to keep settings. At each listener function, ask the user if s/he would like to keep their just-made selection as permanent. Store each selection with a unique ID (or the index count if they aren't uniquely ID'ed) along with the page URL.

On second through nth window loads, walk your storage of page URLs. If you get a hit, walk the document tree for selects again (still need event listeners in case the user changes an option), and force the default option to what the user stored, i.e. set the proper option selected value to true.

Should work for any number of pages provided a) they have a unique URL and b) the number of selects don't change, although you can make that gracefully degrade if the selects have a unique ID. Indexed count identification will not gracefully degrade on changing select counts, of course. Obviously performance becomes an issue if you have hundred or thousands of pages and selects.

That's off the top of my head, might be wrong in some details, but on the whole it sounds pretty close to correct for my in-brain editor (although that piece of neuronic material occasionally exhibits low standards). You can fancy the logic up as much as necessary to keep the users happy.
posted by mdevore at 10:32 PM on January 30, 2007


#Blazecock Pileon: Or are you looking for something which can be adapted for any page and any option?

Yes.


A big problem for a general solution is that sometimes a <select> element is passive (the user selects one element from the list and then clicks some other button to act upon it) and other times it is active (selecting "Oklahoma" does something like sending you to the Oklahoma sub page).

A general script solution to the passive case is easy - just use GM_setValue to remember the latest selected value for every URL encounted and restore it on script load. With such a general script you can then use Manage User Script to say which URLs you want it to include or exclude.

The active case is trickier. I would try something like wrapping the <select> in a <span> that postfixes the <select> with say the symbol ♥. You wouldn't get the active action until you made a new selection or clicked on the ♥. However there are tons of ways to make a <select> active and since a script might have to defeat the old way and install a new way I don't think there is any general solution to active <select>s.

If you want to hire me then for $40 I can write you a passive select remembrance script, or an active select script that works for just one site your are interested in. This offer only applies if you can clearly say what you want and where it should apply. Providing something that works does not imply endless email support without compensation or any assurance that what was provided will still work after the targets web sites change their HTML code..
posted by MonkeySaltedNuts at 12:52 AM on January 31, 2007


Actually, $40 is a steal for a custom script. You could do lots worse than seriously consider that as a solution. Be easy to spend well over $40 of your time just looking for a good example script, before any modifications to it.
posted by mdevore at 1:25 AM on January 31, 2007


« Older Mapping drive to MSSQL table   |   Please help me find a replacement for my HP... Newer »
This thread is closed to new comments.