forked from meetfranz/recipe-gmail
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebview.js
44 lines (32 loc) · 1.03 KB
/
webview.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
"use strict";
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
module.exports = Franz => {
events = {
'new-window': 'newWindow'
};
function newWindow(event) {
console.info('gmail-new-window: ', event);
const newUrl = event.url;
const oldUrl = event.path[0].src;
event.preventDefault();
if (newUrl && oldUrl) {
this.send('new-window', newUrl);
}
}
function getMessages() {
let count = 0;
if (document.getElementsByClassName('J-Ke n0').length > 0) {
if (document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label') != null) {
count = parseInt(document.getElementsByClassName('J-Ke n0')[0].getAttribute('aria-label').replace(/[^0-9.]/g, ''), 10);
}
}
count = parseInt(count, 10);
if (isNaN(count)) {
count = 0;
}
Franz.setBadge(count);
};
Franz.injectCSS(_path.default.join(__dirname, 'service.css'));
Franz.loop(getMessages);
};