blob: 4efdf8cab0b2818cd5781c1f923d7af592fd7b55 (
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
|
"use strict";
module.exports = Franz => {
const getMessages = function getMessages() {
let count = 0
let isNotification = /^\((\d+)\)/.test(document.title);
/*
* Notification case for group chats, workaround by tamas646
* see https://github.com/getferdi/ferdi/issues/1113#issuecomment-783409154
*/
if (isNotification) {
count = parseInt(/^\((\d+)\)/.exec(document.title)[1]);
} else {
/*
* Notification case for direct messages, workaround by manavortex
* see https://github.com/getferdi/ferdi/issues/1113#issuecomment-846611765
*/
count = document.querySelectorAll('._5fx8:not(._569x),._1ht3:not(._569x)').length;
if (0 === count) {
count = document.querySelectorAll('.pq6dq46d.is6700om.qu0x051f.esr5mh6w.e9989ue4.r7d6kgcz.s45kfl79.emlxlaya.bkmhp75w.spb7xbtv.cyypbtt7.fwizqjfa').length;
}
if (0 === count) { // might be obsolete, not sure - never ran into this case
count = document.querySelectorAll('[aria-label="Mark as read"]').length;
}
}
/*
* add count of message requests on top of notification counter
*/
const messageRequestsElement = document.querySelector('._5nxf');
if (messageRequestsElement) {
count += parseInt(messageRequestsElement.innerHTML, 10);
}
Franz.setBadge(count);
};
Franz.loop(getMessages);
localStorage.setItem('_cs_desktopNotifsEnabled', JSON.stringify({
__t: new Date().getTime(),
__v: true
}));
if (typeof Franz.onNotify === 'function') {
Franz.onNotify(notification => {
if (typeof notification.title !== 'string') {
notification.title = ((notification.title.props || {}).content || [])[0] || 'Messenger';
}
if (typeof notification.options.body !== 'string') {
notification.options.body = (((notification.options.body || {}).props || {}).content || [])[0] || '';
}
return notification;
});
}
};
|