Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created September 28, 2008 14:44
Show Gist options
  • Save Sixeight/13464 to your computer and use it in GitHub Desktop.
Save Sixeight/13464 to your computer and use it in GitHub Desktop.
// listgmail.js
// View new mail list on Gmail.
// tomohiro nishimura ( tomohiro68__at__gmail.con )
//
// 参考: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/gmail_biff.js
liberator.plugins.sbmCommentsViewer = (function(){
liberator.commands.addUserCommand(['newmail', 'gnew'], 'List up new mail on gmail',
function(argument, special){
setTimeout(function(){
try {
var form = ['https://www.google.com', 'https://www.google.com', null];
var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager);
var logins = passwordManager.findLogins({}, form[0], form[1], form[2]);
if(logins.length)
var [gmailUser, gmailPassword] = [logins[0].username, logins[0].password];
else {
return;
}
const feed_url = 'https://mail.google.com/mail/feed/atom';
var xhr = new XMLHttpRequest();
xhr.mozBackgroundRequest = true;
xhr.open("GET", feed_url, false, gmailUser, gmailPassword);
xhr.send(null);
var names = xhr.responseXML.getElementsByTagName('name');
var titles = xhr.responseXML.getElementsByTagName('title');
var summarys = xhr.responseXML.getElementsByTagName('summary');
// FIXME: なぜかfont-weightだけ指定できない
// 一行毎に隙間があいてしまう
var res = '<style type="text/css">' + "\n"
+ "div.list_gmail { margin: 0; padding: 0; border-bottom: 1px solid #ccc; }\n"
//+ "span.list_gmail_name,\n"
//+ "span.list_gmail_title { font-weight: bold; }\n"
+ "span.list_gmail_summary { color: #666; }\n"
+ '</style>' + "\n";
for (var i = 0; i < names.length; i++) {
res += '<div class="list_gmail">'
+ '[' + i + '] '
+ '<span class="list_gmail_name" style="font-weight: bold">' + names[i].childNodes[0].nodeValue + '</span> > '
+ '<span class="list_gmail_title">' + titles[i+1].childNodes[0].nodeValue + '</span> '
+ '- <span class="list_gmail_summary">' + summarys[i].childNodes[0].nodeValue + '</span>'
+ '</div><br />'
}
echo(res);
} catch(e) {
log(e);
echoerr('ListGmailError: ' + e);
}
}, 1000);
},
{ argCount: "0", }
);
})();
// vim:sw=4 ts=4 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment