-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathwebview.js
36 lines (27 loc) · 1.1 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
import path from 'path';
module.exports = (Franz) => {
const getMessages = function getMessages() {
let count = 0;
const elements = document.querySelectorAll('.bsU');
elements.forEach((el) => {
count += parseInt(el.textContent, 10);
});
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);
}
}
const chatCount = parseInt(((document.querySelector('[data-tooltip="Chat"]') || '').ariaLabel || '').replace(/[^\d]/g, ''), 10) || 0;
// Just incase we don't end up with a number, set it back to zero (parseInt can return NaN)
count = parseInt(count, 10);
if (isNaN(count)) {
count = 0;
}
count += chatCount;
// set Franz badge
Franz.setBadge(count);
};
Franz.injectCSS(path.join(__dirname, 'service.css'));
// check for new messages every second and update Franz badge
Franz.loop(getMessages);
};