blob: 036a38f8d1de3428a869bfd82053763ac6504b92 (
plain) (
blame)
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
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const _path = _interopRequireDefault(require('path'));
module.exports = Ferdium => {
const getMessages = () => {
let direct = 0;
let indirect = 0;
// Count how many people/groups have texted you
const conversationElems = document.querySelectorAll(
'[data-uie-name="conversation-folder-badge"]',
);
if (conversationElems) {
for (const conversationElem of conversationElems) {
direct += Ferdium.safeParseInt(conversationElem.textContent);
}
}
// Count unread pending user requests
const pendingElem = document.querySelector(
'[data-uie-name="item-pending-requests"]',
);
if (pendingElem) {
const matches =
pendingElem.textContent && pendingElem.textContent.match(/^([1-9]\d*)/);
if (matches && matches.length > 1) {
indirect += Ferdium.safeParseInt(matches[1]);
}
}
// Alternative would be to count all messages (unread conversation count + pending) from the header
// const titleElem = document.querySelector('head title');
// const matches = titleElem.textContent.match(/^\(([1-9][0-9]*)\)/);
// if (matches) {
// direct = matches[1];
// }
Ferdium.setBadge(direct, indirect);
};
Ferdium.loop(getMessages);
Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};
|