I've done a bit of customization on the email command. The standard
one wasn't really working for me because I find it more useful to
write the subject in ubiquity instead of writing the body of the
message. Even so, that is still a possibility in my version of the
command. I'm posting it here just for kicks, I don't think it'll be
very useful for most people because part of the predefined contents
were translated to European Portuguese. And there are still some rough
edges, I haven't fully tested it yet. Meanwhile if anybody knows a way
how to distinguish between directObj having been obtained from the
command line or from the selected text on the page I would appreciate
if you could share it with me. Other suggestions will be greatly
appreciated.

Here's my version of the command:

/* No changes in this function  */
function findGmailTab() {
  var window = Application.activeWindow;

  var gmailURL = "://mail.google.com";
  var currentLocation = String
(Application.activeWindow.activeTab.document.location);
  if(currentLocation.indexOf(gmailURL) != -1) {
    return Application.activeWindow.activeTab;
  }

  for (var i = 0; i < window.tabs.length; i++) {
    var tab = window.tabs[i];
    var location = String(tab.document.location);
    if (location.indexOf(gmailURL) != -1) {
      return tab;
    }
  }
  return null;
}

CmdUtils.CreateCommand({
  name: "my_email",
  takes: {"message": noun_arb_text},
  icon: "chrome://ubiquity/skin/icons/email.png",
  modifiers: {subject:noun_arb_text,
                to: noun_type_contact},
  description:"Begins composing an email to a person from your contact
list.",
  help:"Currently only works with <a href=\"http://mail.google.com
\">Google Mail</a>, so you'll need a Gmail account to use it." +
       " Try selecting part of a web page (including links, images,
etc) and then issuing &quot;email this&quot;.  You can" +
       " also specify the recipient of the email using the word
&quot;to&quot; and the name of someone from your contact list." +
       " For example, try issuing &quot;email hello to jono&quot;
(assuming you have a friend named &quot;jono&quot;).",
  preview: function(pblock, directObj, modifiers) {
    var html = "Creates an email message ";
    if (modifiers.subject) {
        html += "with the subject " + modifiers.subject.text + " ";
    }
    if (modifiers.to) {
      html += "to " + modifiers.to.text + " ";
    }
    if (directObj.html) {
      html += "with these contents:" + directObj.html;
    } else {
      html += "with a link to the current page.";
    }
    pblock.innerHTML = html;
  },

  execute: function(directObj, headers) {
    var html = directObj.html;
    var document = context.focusedWindow.document;
    var title, subject_text;
    var toAddress = "";
    var location = document.location;
    if (document.title)
      title = document.title;
    else
      title = location;
    var gmailTab = findGmailTab();
    var pageLink = "<a href=\"" + location + "\">" + title + "</a>";
    if (html) {
      html = ("&quot;" + html + "&quot;" + "<br /><p>in " + pageLink +
":</p>");
    } else {
      // If there's no selection, just send the current page.
      html = "<p>Vê este endereço: " + pageLink + ".</p>";
    }
    html = html + "<br /><br />    Paulo"

    if (headers.subject) {
        if (headers.subject.text) {
            subject_text = headers.subject.text;
        } else {
            subject_text = title;
        }
    }

    if (headers.to)
      if (headers.to.text)
          toAddress = headers.to.text;

    if (gmailTab) {
      // Note that this is technically insecure because we're
      // accessing wrappedJSObject, but we're only executing this
      // in a Gmail tab, and Gmail is trusted code.
      var console =
gmailTab.document.defaultView.wrappedJSObject.console;
      var gmonkey =
gmailTab.document.defaultView.wrappedJSObject.gmonkey;

      var continuer = function() {
        // For some reason continuer.apply() won't work--we get
        // a security violation on Function.__parent__--so we'll
        // manually safety-wrap this.
    try {
          var gmail = gmonkey.get("1.0");
          var sidebar = gmail.getNavPaneElement();
          var composeMail = sidebar.getElementsByTagName("span")[0];
      //var composeMail = sidebar.getElementById(":qw");
          var event = composeMail.ownerDocument.createEvent("Events");
          event.initEvent("click", true, false);
          composeMail.dispatchEvent(event);
          var active = gmail.getActiveViewElement();
      var toField = composeMail.ownerDocument.getElementsByName("to")
[0];
      toField.value = toAddress;
          var subject = active.getElementsByTagName("input")[0];
          if (subject) subject.value = subject_text;
          var iframe = active.getElementsByTagName("iframe")[0];
          if (iframe)
            iframe.contentDocument.execCommand("insertHTML", false,
html);
          else {
            var body = composeMail.ownerDocument.getElementsByName
("body")[0];
            html = ("Note: the following probably looks strange
because " +
                    "you don't have rich formatting enabled.  Please "
+
                    "click the 'Rich formatting' link above, discard "
+
                    "this message, and try " +
                    "the email command again.\n\n" + html);
            body.value = html;
          }
          gmailTab.focus();
        } catch (e) {
          displayMessage({text: "A gmonkey exception occurred.",
                          exception: e});
        }
      };

      gmonkey.load("1.0", continuer);
    } else {
      // No Gmail tab open?  Open a new one:
      var params = {fs:1, tf:1, view:"cm", su:title, to:toAddress,
body:html};
      Utils.openUrlInBrowser("http://mail.google.com/mail/?"; +
                 Utils.paramsToString(params));
    }
  }
});
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"ubiquity-firefox" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/ubiquity-firefox?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to