My bookmarklets
Below you find a link to two bookmarklets I posted on jsfiddle. If you drag them on your browser toolbar, when you open a Gmail message, clicking a bookmarklet pops up a window with sender and recipients addresses (including CC's).
Since it is a popup window, in Windows, just hit Ctrl-A, Ctrl-C and you get them selected and copied in your clipboard. Eventually Ctrl-W (or Alt-F4) will close the popup window (for a non-Windows OS you should use the equivalent keys).
jsfiddle bookmarklets + code
jsfiddle bookmarklets only
The one bookmarklet named contLong
will show, when available in the message, the long format "John Smith <johnsmith@example.com>"; instead contShort
will only show the Gmail internally stored email addresses.
The bookmarklets were tested with Firefox and Chrome for Windows. No need to mention that to view the output window you might need to:
allow popups from https://mail.google.com
domain.
The javascript code
Here is the bookmarklets' code. Do customise the first three code lines:
internals=true
enables the short format based on the internal addresses;
width
and height
refer to the pixel size of the popup.
tutsplus.com gives some background info on bookmarklets, in case you need it.
Comments on both javascritpt code and functionality are greatly appreciated.
javascript:(function(){
/* Get from, to, cc fields from Gmail */
/* --- Customise these vars ---
* Use only internally stored address?
* Set size of output window. */
var internals=true,
width=400,
height=400;
/* Glocal objects */
var txt='', contPad,
getContacts=function(spanPos){
var c=contPad[spanPos].firstChild.querySelectorAll('span.gI > span');
if(spanPos==0){
if(internals) txt+= c[0].getAttribute('email') + '<br>'; else
txt+= c[0].innerHTML + ' '+ c[1].innerHTML + '<br>';
} else
for (var i = 0; i < c.length; i++)
if(internals) txt+= c[i].getAttribute('email') + '<br>';
else txt+= c[i].innerHTML + '<br>';
return txt;
};
/* Check page */
var loc=window.location;
if(loc.origin != 'https://mail.google.com'){
alert('You are not on a Gmail page.');
return;
}
if(!/inbox\/[^/]+$/.test(loc)){
alert('Run the bookmarklet on an open message');
return;
}
/* Prepare output window */
var wconf= 'width=' + width + ',height=' + height +
',scrollbars=yes,status=no,titlebar=no,toolbar=no',
contacts=window.open('','Gmail_Message_Contacts', wconf);
/* Simulate click on 'to' triangle drop down to show contatcs */
var triangle=document.querySelector( 'div.ajy' ).firstChild ;
triangle=triangle.getAttribute('id');
triangle = document.getElementById(triangle);
var event = document.createEvent('MouseEvents');
event.initEvent('click', true, true);
triangle.dispatchEvent(event);
contPad = document.querySelectorAll('td.gL');
/*from: span pos 0 */
txt+='<b>From:</b><br>';
txt=getContacts(0);
/*to: span pos 1 */
txt+='<br><b>To:</b><br>';
txt=getContacts(1);
/*cc*: span pos 2 */
txt+='<br><b>CC:</b><br>';
txt=getContacts(2);
/* Close Gmail `to' drop down*/
triangle.dispatchEvent(event);
/*Write results in popup */
contacts.document.body.innerHTML=txt ;
contacts.focus();
}())