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
|
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
const _path = _interopRequireDefault(require('path'));
module.exports = Ferdium => {
const getMessages = () => {
// With `// Legacy ` are marked those selectors that were working for some
// Nextcloud version before 27 (24 or 25).
const counterBubble = '.counter-bubble__counter';
const directFromLeftSideBar = document.querySelectorAll(
`${counterBubble}--highlighted`, // Nextcloud 27
).length;
let indirect = 0;
for (const counter of document.querySelectorAll(
'.app-navigation-entry__counter, ' + // Legacy
`${counterBubble}:not(${counterBubble}--highlighted)`, // Nextcloud 27
)) {
indirect += Ferdium.safeParseInt(counter?.textContent.trim());
}
if (document.title.startsWith('*')) {
indirect += 1;
}
Ferdium.setBadge(
// Try to use the unread conversations count retrieved from the left
// sidebar, otherwise check Talk specific notifications
directFromLeftSideBar > 0
? directFromLeftSideBar
: Ferdium.safeParseInt(
document
.querySelector(
'.notifications .notification-wrapper, ' + // Legacy
'.notification-container .notification-wrapper', // Nextcloud 27
)
?.querySelectorAll(
'.notification[object_type="chat"], ' + // Legacy
'.notification[object_type="room"], ' + // Legacy
'.notification[data-object-type="chat"], ' + // Nextcloud 27
'.notification[data-object-type="room"]', // Nextcloud 27
).length,
),
indirect,
);
};
Ferdium.loop(getMessages);
Ferdium.injectCSS(_path.default.join(__dirname, 'service.css'));
};
|