/*
 * Copyright (C) 2005 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 meta description and keywords from a web page
 *
 * @name Show Meta
 *
 * @substitute meta_tags a
 * @substitute meta_index b
 * @substitute meta_keywords c
 * @substitute meta_description d
 * @substitute meta_name e
 * @substitute meta_content f
 * @substitute display_node g
 * @substitute meta_display h
 * @substitute title_tag i
 * @substitute page_title j
 * @substitute h1_tags k
 * @substitute h1_text l
 *
 * @compatible Firefox
 * @compatible Internet Explorer
 * @compatible Opera
 * @compatible Mozilla
 *
 * @category Meta
 *
 */
void(
    (function(){
      var meta_tags,meta_index,meta_keywords,meta_description,meta_name,meta_content,meta_display,display_node,title_tag,page_title,h1_tags,h1_text;
        meta_keywords=meta_description="";
        // Use the DOM to pick out all the meta tags
        meta_tags=document.getElementsByTagName("meta");
        // Go through the meta tags and pick out the keywords and descirption
        for(meta_index=0;meta_index<meta_tags.length;meta_index++){        
            meta_name=meta_tags[meta_index].name;
            meta_content=meta_tags[meta_index].content;
            if(meta_name.match(/keywords/i))meta_keywords=meta_content;
            if(meta_name.match(/description/i))meta_description=meta_content;
        }
        // Grab the title
        title_tag=document.getElementsByTagName("title");
        if(title_tag && title_tag.length>0)page_title=title_tag[0].innerHTML;
        // Grab all H1s
        h1_tags=document.getElementsByTagName("h1");
        h1_text="";
        for(i=0;i<h1_tags.length;i++)h1_text+="<p>h1:%20<b>"+h1_tags[i].innerHTML+"</b></p>";
        // Create a display area for the desciption and keywords
        display_node=document.createElement("div");
        display_node.innerHTML="<div id='MD' style='padding:0.5cm;background-color:white;z-index:99;position:absolute;top:0'><div style='float:right;color:red' onclick='document.getElementById(\"MD\").style.display=\"none\";'>close</div><p>Description: <b>"+meta_description+"</b></p><p>Keywords: <b>"+meta_keywords+"</b></p><p>Title:%20<b>"+page_title+"</b></p>"+h1_text+"</div>";
        // Show the display area at the top of the page.
        document.body.insertBefore(display_node,document.body.firstChild);
    })()
)