/*
 * 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.
 */
 
/**
 * View the contents of all the password fields in the page which are normally hidden by ****.
 *
 * Traverses all frames on the current page searching for password boxes.  It collects all the
 * passwords and displays them in plain text in a popup window.  
 *
 * @name View Passwords
 *
 * @substitute popup_document_pointer a
 * @substitute result_html            b
 * @substitute current_frame          c
 * @substitute frame_index            d
 * @substitute document_forms         e
 * @substitute form_index             f
 * @substitute form_element           g
 * @substitute element_index          h
 * @substitute caught_exception       i
 *
 * @compatible Firefox
 * @compatible Netscape
 * @compatible Opera
 * @compatible Mozilla
 * @compatible Konqueror
 * @compatible Internet Explorer
 * @compatible Safari
 *
 * @category Password
 * @category Utilities
 *
 * @keyword view passwords bookmarklet
 * @keyword show passwords bookmarklet
 * @keyword display passwords bookmarklet
 * @keyword passwords display bookmarklet
 */
void(
    (function(){
        var popup_document_pointer,result_html;
        // Build an html document with all the passwords on the page
        result_html="<"+"html>\n<body>Passwords in this page:<p>\n";
        (function(current_frame){
            var frame_index,document_forms,form_index,form_element,element_index;
            // 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++){
                form_element=document_forms[form_index];
                // For each element in the form
                for(element_index=0;element_index<form_element.length;element_index++){
                    // Find the password elements and extract them.
                    if(form_element[element_index].type.toLowerCase()=="password")result_html+=form_element[element_index].value+"<br>\n";
                }
            }
        })(top); // Start with the top level frame
        result_html+="</body>\n</html>\n";
        // Open a pop-up window to show all the passwords
        popup_document_pointer=window.open("","","width=200,height=300").document;
        popup_document_pointer.open();
        popup_document_pointer.write(result_html);
        popup_document_pointer.close();
    })()
)
