// ==UserScript==
// @namespace   http://afunamatata.com/greasemonkey/
// @name        LiveJournal Gmail Userpic-chooser
// @description   Allows you to choose a userpic from the comment notification e-mail in Gmail
// @include     http://mail.google.com/*
// @include     https://mail.google.com/*
// @tags        livejournal, needswork
// ==/UserScript==

// TODO: make it a dropdown
// TODO: check that it *is* a comment notification ;-0
// need to add something for when a message is expanded

window.addEventListener('load', function() {   
  if(unsafeWindow.gmonkey) 
  {    
    unsafeWindow.gmonkey.load('1.0', function(gmail) {
      function addUserpicField() {
        if(gmail.getActiveViewType() == 'cv') {
          cv = gmail.getActiveViewElement();
          forms = cv.getElementsByTagName("form"); 
          for(var i=0; i < forms.length; ++i) {
            var form = forms[i];            
            
            // TODO: move this to a different script
            form.onsubmit = null;
            
            var label = document.createElement("label");
            label.innerHTML = "<b>Userpic: </b>";

            // eventually, this shall be a dropdown ;-)
            var userpic = document.createElement("input");            
            userpic.setAttribute("name", "prop_picture_keyword");

            form.appendChild(label);
            form.appendChild(userpic);
          }
        }
      }      
      gmail.registerViewChangeCallback(addUserpicField);
      addUserpicField();
    });      
  }
}, true);
