-
Notifications
You must be signed in to change notification settings - Fork 14
/
webview.js
35 lines (26 loc) · 1.13 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
import path from 'path';
module.exports = (Franz) => {
const getMessages = function getMessages() {
let count = 0;
document.querySelectorAll('[data-testid="mwthreadlist-item"]').forEach((node) => {
if (node.querySelector('.lrazzd5p, .is6700om, .o48pnaf2')) count += 1;
});
count += document.querySelectorAll('[role="gridcell"] .xwnonoy, [role="gridcell"] .x107p15e').length;
Franz.setBadge(count);
};
Franz.loop(getMessages);
/* Enable desktop notifications in messenger settings */
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;
});
}
Franz.injectCSS(path.join(__dirname, 'service.css'));
};