-
Notifications
You must be signed in to change notification settings - Fork 123
/
gmail_biff.js
105 lines (97 loc) · 6.15 KB
/
gmail_biff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Vimperator plugin: gmail-biff
// Maintainer: mattn <[email protected]> - http://mattn.kaoriya.net
(function(){
const ICON1 = 'data:image/png;base64,'+
'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAIAAADAAbR1AAAACXBIWXMAAABIAAAASABGyWs+AAAA'+
'CXZwQWcAAAAQAAAAEABcxq3DAAAEXklEQVQ4y7WUXUxTdxyG33/bU6gIY5VSa8WkXSUu6hyDKMkM'+
'S1TAuSUQl10sMtAsGnQKs64Vq5KAGWNxas1E/GJ1YHQJjMT4FdEZIqgJBkRnZA7mV0uFCuLgcNpz'+
'2vP/7UKz7GLJrnwu3svn5k0eRkREhNeGDiFswzYMUiVVIpmtYqtgww7sANCABgAxxP7XUoxiPMU5'+
'nMNT8pAHZraVbYUVdajD+OKzj84+Cma7FrsWD3+8q3dXr/zjXcNdA5EUlsJEk/ZJO5EYESNEoiIq'+
'RKIsykSTwqRAJMmSHCt/Yntie/bcO9M7M5jmvOO889TQpDapkhSZEpmikz99kPAgQWxt97f70Udl'+
'VCa3DNQM1KR8Uq6UKwY1oyKjAm/iEA4BaEQjgIVYCECBokgPpYfSyOa6kbqRydYOZ4cTnbEDsQMT'+
'C+ROuZMXLr239J6GbdHe1N5Ei/a09rTwTVp5Wnl0dLBosGjYVS1Xy+JvV+ZdmQcPP8qPAuhGN0Jg'+
'YOFbt/pv9Q9bqpZULQlf6antqY0T0y+kX2AufbO+WW1CGcq4jVu4RQOOcYyjlfI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IWXMAAABIAAAASABGyWs+AAAA'+
'CXZwQWcAAAAQAAAAEABcxq3DAAABvUlEQVQoz2P4TwAw/J/13/x/9f87/6f/n4IErwHFTf73ARUc'+
't5zOskjjvtvPVT+Sfrj8cAVC359rXv5bPWGq9w7O79sZ1uam1aXeaFt26/n/zf83/s//P/X//+cc'+
'U5PSJ6Yc6yh4lsqwviXTo0axqKS65eyrv7eBlvbfOtMWlv+hRTTjUQfHk0aG9VXpvxZPPLWp8nQx'+
'x77qH+KnflVZlzgcWrVrVvrF9rgnC0AKji5T/G9xM6Blad7zSSHFDnUfL5z9/2zfzbSKttInixjW'+
'V6YfXsbxf/3//3f/d3Km7WyVv9H+//3/33vTUgxaNj5ZxbA+Ir136cu/rz8ueXnsCe+u/EcrX616'+
'v+lfyR7WhPNNdU+2MKx3TV+54Oersre7fn/4v+l/5v8Vf6a9F311bPOa2BMNa57sY1g3LW3K7Luf'+
'nf9s/PPyz+Q/LUC48k/V14DVz6KZ6k89Ocyw6lei65yMjz4f7T6afDT7aA6Elh95P85Y+z2iq+78'+
'k9UMW8vzxTtMN0ZvrATDio05GxM3hm/cMvFrhlvno2dxDF9Nbh+9Gn/19NUzUHj66kkgPH91y1WH'+
'O1e/yzEQjk0CAAARc29gwOvTnwAAAABJRU5ErkJggg==';
var gmailBiffIntervals = parseInt(liberator.globalVariables.gmbf_check_intervals || 30) * 1000;
var gmailBiffIcon = document.createElement('statusbarpanel');
gmailBiffIcon.setAttribute('id','gmail-biff-icon');
gmailBiffIcon.setAttribute('class','statusbarpanel-iconic');
gmailBiffIcon.setAttribute('src', ICON2);
gmailBiffIcon.setAttribute('tooltip', 'gmail-biff-tip');
gmailBiffIcon.addEventListener("click",function(e){
liberator.open("https://mail.google.com/", liberator.NEW_TAB);
},false);
var gmailBiffTip = document.createElement('tooltip');
gmailBiffTip.setAttribute('id','gmail-biff-tip');
var gmailBiffText = document.createElement('description');
gmailBiffText.setAttribute('id','gmail-biff-text');
gmailBiffTip.appendChild(gmailBiffText);
document.getElementById('status-bar')
.insertBefore(gmailBiffIcon,document.getElementById('security-button').nextSibling);
document.getElementById('status-bar').appendChild(gmailBiffTip);
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 {
liberator.echoerr("Gmail Biff: account not found");
var promptSvc = Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService);
var user = { value : null };
var pass = { value : null };
var ret = promptSvc.promptUsernameAndPassword(
window, form[0], "GMail Biff Login", user, pass, null, {});
if(ret){
var nsLoginInfo = new Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
Ci.nsILoginInfo,
"init");
[gmailUser, gmailPassword] = [user.value, pass.value];
var formLoginInfo = new nsLoginInfo(
form[0], form[1], form[2],
gmailUser, gmailPassword, '', '');
passwordManager.addLogin(formLoginInfo);
}
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 count = parseInt(xhr.responseXML.getElementsByTagName('fullcount')[0].childNodes[0].nodeValue);
gmailBiffIcon.setAttribute('src', count > 0 ? ICON1 : ICON2);
gmailBiffText.setAttribute('value', count > 0 ? 'You have new mail (' + count + ')' : 'No new mail');
setTimeout(arguments.callee, gmailBiffIntervals);
} catch(e) {
liberator.log(e);
liberator.echoerr("Gmail Biff: " + e);
}
}, 1000);
})();
// vim:sw=4 ts=4 et: