aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp/webview.js
diff options
context:
space:
mode:
Diffstat (limited to 'recipes/whatsapp/webview.js')
-rw-r--r--recipes/whatsapp/webview.js39
1 files changed, 33 insertions, 6 deletions
diff --git a/recipes/whatsapp/webview.js b/recipes/whatsapp/webview.js
index a908637..1c11edc 100644
--- a/recipes/whatsapp/webview.js
+++ b/recipes/whatsapp/webview.js
@@ -1,14 +1,17 @@
1const _path = _interopRequireDefault(require('path')); 1const _path = _interopRequireDefault(require('path'));
2 2
3function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 3function _interopRequireDefault(obj) {
4 return obj && obj.__esModule ? obj : { default: obj };
5}
4 6
5module.exports = (Ferdi, settings) => { 7module.exports = (Ferdi, settings) => {
6 const getMessages = () => { 8 const getMessages = () => {
7 let count = 0; 9 let count = 0;
8 let indirectCount = 0; 10 let indirectCount = 0;
9 11
10 const parentChatElem = [...document.querySelectorAll('div[aria-label]')] 12 const parentChatElem = [
11 .sort((a, b) => (a.offsetHeight < b.offsetHeight) ? 1 : -1)[0]; 13 ...document.querySelectorAll('div[aria-label]'),
14 ].sort((a, b) => (a.offsetHeight < b.offsetHeight ? 1 : -1))[0];
12 if (!parentChatElem) { 15 if (!parentChatElem) {
13 return; 16 return;
14 } 17 }
@@ -17,7 +20,12 @@ module.exports = (Ferdi, settings) => {
17 for (const unreadElem of unreadSpans) { 20 for (const unreadElem of unreadSpans) {
18 const countValue = Ferdi.safeParseInt(unreadElem.textContent); 21 const countValue = Ferdi.safeParseInt(unreadElem.textContent);
19 if (countValue > 0) { 22 if (countValue > 0) {
20 if (!unreadElem.parentNode.previousSibling || unreadElem.parentNode.previousSibling.querySelectorAll('[data-icon=muted]').length === 0) { 23 if (
24 !unreadElem.parentNode.previousSibling ||
25 unreadElem.parentNode.previousSibling.querySelectorAll(
26 '[data-icon=muted]',
27 ).length === 0
28 ) {
21 count += countValue; 29 count += countValue;
22 } else { 30 } else {
23 indirectCount += countValue; 31 indirectCount += countValue;
@@ -28,12 +36,31 @@ module.exports = (Ferdi, settings) => {
28 Ferdi.setBadge(count, indirectCount); 36 Ferdi.setBadge(count, indirectCount);
29 }; 37 };
30 38
39 const getActiveDialogTitle = () => {
40 const element = document.querySelector('header .emoji-texttt');
41
42 Ferdi.setDialogTitle(element ? element.textContent : '');
43 };
44
45 const loopFunc = () => {
46 getMessages();
47 getActiveDialogTitle();
48 };
49
31 window.addEventListener('beforeunload', async () => { 50 window.addEventListener('beforeunload', async () => {
32 Ferdi.clearStorageData(settings.id, { storages: ['appcache', 'serviceworkers', 'cachestorage', 'websql', 'indexdb'] }); 51 Ferdi.clearStorageData(settings.id, {
52 storages: [
53 'appcache',
54 'serviceworkers',
55 'cachestorage',
56 'websql',
57 'indexdb',
58 ],
59 });
33 Ferdi.releaseServiceWorkers(); 60 Ferdi.releaseServiceWorkers();
34 }); 61 });
35 62
36 Ferdi.loop(getMessages); 63 Ferdi.loop(loopFunc);
37 64
38 Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); 65 Ferdi.injectCSS(_path.default.join(__dirname, 'service.css'));
39}; 66};