/*
 * Copyright (C) 2004 Stephen Ostermiller
 * http://ostermiller.org/contact.pl?regarding=Bookmarklets
 *
 * This bookmarklet is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This bookmarklet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */
 
/**
 * Changes forms to submit using the GET method to the home page of the site.
 *
 * Traverses all frames on the current page searching for forms and sets their
 * method to GET and their action to /.
 * <p>
 * When a form submits via GET, its arguments are visible in the URL bar allowing
 * them to be inspected.  Changing the action to the homepage also often prevents
 * a redirect from being issued that would make the arguments disappear.  
 * Unfortunately some sites have a redirect on the home page itself which would
 * make this ineffective.
 * 
 * @name Forms to Homepage GET
 *
 * @substitute forms_seen       a
 * @substitute current_frame    b
 * @substitute frame_index      c
 * @substitute document_forms   d
 * @substitute form_index       e
 * @substitute current_form     f 
 * @substitute caught_exception g
 *
 * @compatible Firefox
 * @compatible Netscape
 * @compatible Opera
 * @compatible Mozilla
 * @compatible Konqueror
 * @compatible Internet Explorer
 * @compatible Safari
 *
 * @category Form
 * @category Utilities
 *
 * @keyword form to homepage get bookmarklet
 * @keyword post to homepage get bookmarklet
 * @keyword homepage get bookmarklet
 */
void(
    (function(){
        // number of forms seen
        var forms_seen=0;
        (function(current_frame){
            var frame_index,document_forms,form_index,current_form;
            // For each frame in the current document
            for(frame_index=0;frame_index<current_frame.length;frame_index++){
                try{
                    arguments.callee(current_frame.frames[frame_index]); // Recurse frame
                }catch(caught_exception){}
            }
            document_forms=current_frame.document.forms;
            // For each form in the document
            for(form_index=0;form_index<document_forms.length;form_index++){
                current_form=document_forms[form_index];
                current_form.method="GET";
                current_form.action="/";
                forms_seen++;
            }
        })(top); // Start with the top level frame
        alert(forms_seen+" forms changed to use homepage GET");
    })()
)
