blob: bfa2e06683c4e88789413ead96e9dce114503600 (
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const _path = _interopRequireDefault(require('path'));
module.exports = Ferdium => {
// if the user is on gmail's landing page, go to the login page.
if (
location.hostname === 'www.google.com' &&
location.href.includes('gmail/about/')
) {
location.href =
'https://accounts.google.com/AccountChooser?service=mail&continue=https://mail.google.com/mail/';
}
const getMessages = () => {
let countImportant = 0;
let countNonImportant = 0;
const inboxLinks = document.querySelectorAll('.J-Ke.n0');
const spaceAndChatBadges = document.querySelectorAll(
'div.Xa.bSyoAf span.XU',
);
if (inboxLinks.length > 0) {
const { parentNode } = inboxLinks[0];
if (parentNode) {
const parentNodeOfParentNode = parentNode.parentNode;
if (parentNodeOfParentNode) {
const unreadCounts = parentNodeOfParentNode.querySelectorAll('.bsU');
if (unreadCounts.length > 0) {
const unreadCount = unreadCounts[0].textContent;
if (unreadCount.includes(':')) {
const counts = unreadCount
.split(':')
.map(s => Ferdium.safeParseInt(s.replaceAll(/[^\p{N}]/gu, '')));
countImportant = counts[0];
countNonImportant = counts[1] - counts[0];
} else {
countImportant = Ferdium.safeParseInt(
unreadCount.replaceAll(/[^\p{N}]/gu, ''),
);
}
}
}
}
}
if (spaceAndChatBadges.length > 0) {
const arr = [...spaceAndChatBadges];
const spaceAndChatCount = arr.reduce(
(acc, e) => Ferdium.safeParseInt(e.getInnerHTML()) + acc,
0,
);
countImportant += spaceAndChatCount;
}
Ferdium.setBadge(countImportant, countNonImportant);
};
Ferdium.loop(getMessages);
Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};
|