Gmail
From GreaseSpot
Also see Category:Ajax site tips for tips that apply to JavaScript-heavy sites in general.
Contents |
[edit] Recommended @includes
// @include https://mail.google.tld/mail/* // @include http://mail.google.tld/mail/* // @include https://mail.google.tld/a/* // @include http://mail.google.tld/a/*
This matches both regular Gmail and Google Apps.
[edit] The P() function
All Gmail data received from the server flows through the top.js.P() function. Intercepting this function and inspecting or manipulating that data can be useful in script development. Do note that using unsafeWindow has security implications.
Inspect the data using Firebug:
var oldP = unsafeWindow.P;
unsafeWindow.P = function(iframe, data) {
unsafeWindow.console.log("P(%o, %o)", iframe, data);
return oldP.apply(iframe, arguments);
}
Manipulate the data:
var oldP = unsafeWindow.P;
unsafeWindow.P = function(iframe, data) {
if (data[0] == "mb")
data[1] = do_something_with(data[1]);
return oldP.apply(iframe, arguments);
}
In this example, the data is something like ["mb", "The body of a mail", 0]. The code applies do_something_with() to the mail body text if the first item in the data array is the mb identifier.
[edit] Example scripts
[edit] P() identifiers
In ["mb", "The body of a mail", 0], we will call mb the identifier, and "The body of a mail", 0 the arguments. This table represents an attempt to document these identifiers and arguments.
| Identifier | Meaning/comments | Arguments | Example |
|---|---|---|---|
ds | Mailbox counts (always in this order?) | ["Mailbox name", count], …] | [["inbox", 1], ["drafts", 0], ["spam", 14]] |
ct | Tag counts (alphabetically?) | ["Tag name", count], …] | [["bar", 5], ["foo", 3]] |
mb | Mail body text | "Mail body text", unknown_number | "<div style=\"direction:ltr\">Hello world!</div>", 0 |
gn | User's Google Account name (not the customized name) | "Name" | "John Doe" |

