aboutsummaryrefslogtreecommitdiffstats
path: root/recipes/whatsapp
diff options
context:
space:
mode:
authorLibravatar Iaroslav <yavoloh@mail.ru>2021-10-23 19:13:55 +0500
committerLibravatar GitHub <noreply@github.com>2021-10-23 19:43:55 +0530
commit591a9a4ca229dcda6e54d4e24f79dfef14d0acc5 (patch)
tree8676eb01fe567fb96c8220459746d55cc3dbf12a /recipes/whatsapp
parentfix for #286 with fallback (#738) (diff)
downloadferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.tar.gz
ferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.tar.zst
ferdium-recipes-591a9a4ca229dcda6e54d4e24f79dfef14d0acc5.zip
Add setDialogTitle feature to api, WhatsApp and Telegram (#750)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'recipes/whatsapp')
-rw-r--r--recipes/whatsapp/package.json2
-rw-r--r--recipes/whatsapp/webview.js39
2 files changed, 34 insertions, 7 deletions
diff --git a/recipes/whatsapp/package.json b/recipes/whatsapp/package.json
index 8f4aab7..208a3a8 100644
--- a/recipes/whatsapp/package.json
+++ b/recipes/whatsapp/package.json
@@ -1,7 +1,7 @@
1{ 1{
2 "id": "whatsapp", 2 "id": "whatsapp",
3 "name": "WhatsApp", 3 "name": "WhatsApp",
4 "version": "3.3.5", 4 "version": "3.3.6",
5 "license": "MIT", 5 "license": "MIT",
6 "config": { 6 "config": {
7 "serviceURL": "https://web.whatsapp.com", 7 "serviceURL": "https://web.whatsapp.com",
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};