views:

232

answers:

1

Hi there. I'm on my way to creating a greasemonkey script for gmail.

The first thing I want to play with is reducing the size of 'main' pane. This is where either the list of emails are or where the email message is being displayed.

Using Firebug, I can find two separate instances of a "<div class="nH nn" style="width: 1013px;">" tag. One changes the width of the background of the relevant pane, the other changes the width of the messages contained in the pane. Using Firebug I can change the width values in each of these tags to have the middle pane take up half the available space, for example.

How should I do this using Greasemonkey? Is the gmailAPI the way to go? The wiki here:

http://code.google.com/p/gmail-greasemonkey/wiki/GmailGreasemonkey10API

doesn't give much description for each method. Would gmail.getMastheadElement() maybe be it?

Or would more of a standard DOM transverse approach be better than dealing with the API? If so, I'm not sure how to target those particular divs. They're only using the classes "nH nn" for identification, which seem to be reused multiple times throughout the gmail code.

Thanks.

UPDATE: Wish we could put code in replies to answers... here's the thing that I'm trying. Where is this going wrong?

window.addEventListener('load', function() {
  if (unsafeWindow.gmonkey) {
    unsafeWindow.gmonkey.load('1.0', function(gmail) {

      gmail.getActiveViewElement().style.width = "500px";

    });
  }
}, true);
+1  A: 

gmail greasemonkey api is the way to go.

gmail.getActiveViewElement (along with gmail.getActiveViewType) seems to be what you are looking for.

Edit: Responding to your comment - I have never tried this before but I typed the following in my firebug console (when gmail was open and gm enabled) and it worked perfectly (reduced the width of the conversations view).

gmonkey.load("1.0", function() { 
    var gmail = gmonkey.get("1.0");
    gmail.getActiveViewElement().style.width = "500px";
});

Also, you can visually inspect what element is returned by the functions if you console.log the element. When you hover over the result in console, Firebug highlights it in the html document.

Edit 2 : The following worked for me.

window.addEventListener('load', function() {
  if (unsafeWindow.gmonkey) {
    unsafeWindow.gmonkey.load('1.0', function(gmail) {
      setTimeout(function() {gmail.getActiveViewElement().style.width = "500px";},0);
    });
  }
}, true);

Now I have no idea why a setTimeout helps here. Maybe gmail does a lot of its own dom manipulation stuff on window.load burying your change. Here's a related SO discussion on that!

Chetan Sastry
Any helpful "debugging" type code/strategies? Mainly for knowing what node this is returning and etc. Setting the width of this returned node directly doesn't change anything, even though changing the root node of the right hand column via firebug changes the width of the background. I wish these things had IDs, It's very hard to tell which of the endless <div class="nH"> tags you have...
cksubs
Thanks, that does work. What makes that different, or what am I doing wrong, when I do a .user.js file like this?window.addEventListener('load', function() { if (unsafeWindow.gmonkey) { unsafeWindow.gmonkey.load('1.0', function(gmail) { gmail.getActiveViewElement().style.width = "500px"; }); }}, true);
cksubs
errr... I posted that in the original question too so it's easier to read.
cksubs