diff options
author | 2021-10-23 19:13:55 +0500 | |
---|---|---|
committer | 2021-10-23 19:43:55 +0530 | |
commit | 591a9a4ca229dcda6e54d4e24f79dfef14d0acc5 (patch) | |
tree | 8676eb01fe567fb96c8220459746d55cc3dbf12a /recipes | |
parent | fix for #286 with fallback (#738) (diff) | |
download | ferdium-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')
-rw-r--r-- | recipes/element/webview.js | 8 | ||||
-rw-r--r-- | recipes/telegram/package.json | 2 | ||||
-rw-r--r-- | recipes/telegram/webview.js | 23 | ||||
-rw-r--r-- | recipes/whatsapp/package.json | 2 | ||||
-rw-r--r-- | recipes/whatsapp/webview.js | 39 |
5 files changed, 56 insertions, 18 deletions
diff --git a/recipes/element/webview.js b/recipes/element/webview.js index 771c758..75df4d9 100644 --- a/recipes/element/webview.js +++ b/recipes/element/webview.js | |||
@@ -9,7 +9,7 @@ module.exports = Ferdi => { | |||
9 | let indirectCount = 0; | 9 | let indirectCount = 0; |
10 | // Count Badges depending on Element Settings | 10 | // Count Badges depending on Element Settings |
11 | if (avatarBadges.length > 0) { | 11 | if (avatarBadges.length > 0) { |
12 | avatarBadges.forEach(function(badge) { | 12 | for (const badge of avatarBadges) { |
13 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | 13 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { |
14 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); | 14 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); |
15 | } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { | 15 | } else if (badge.parentElement.previousSibling != null && badge.parentElement.previousSibling.getAttribute('class').includes('mx_DecoratedRoomAvatar_icon_online')) { |
@@ -19,9 +19,9 @@ module.exports = Ferdi => { | |||
19 | } else { | 19 | } else { |
20 | indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); | 20 | indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); |
21 | } | 21 | } |
22 | }); | 22 | } |
23 | } else { | 23 | } else { |
24 | spaceBadges.forEach(function(badge) { | 24 | for (const badge of spaceBadges) { |
25 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { | 25 | if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_highlighted')) { |
26 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); | 26 | directCount = directCount + Ferdi.safeParseInt(badge.textContent); |
27 | } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { | 27 | } else if (badge.parentElement.getAttribute('class').includes('mx_NotificationBadge_dot')) { |
@@ -29,7 +29,7 @@ module.exports = Ferdi => { | |||
29 | } else { | 29 | } else { |
30 | indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); | 30 | indirectCount = indirectCount + Ferdi.safeParseInt(badge.textContent); |
31 | } | 31 | } |
32 | }); | 32 | } |
33 | } | 33 | } |
34 | // set Ferdi badge | 34 | // set Ferdi badge |
35 | Ferdi.setBadge(directCount, indirectCount); | 35 | Ferdi.setBadge(directCount, indirectCount); |
diff --git a/recipes/telegram/package.json b/recipes/telegram/package.json index adb6de6..beda3c3 100644 --- a/recipes/telegram/package.json +++ b/recipes/telegram/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "telegram", | 2 | "id": "telegram", |
3 | "name": "Telegram", | 3 | "name": "Telegram", |
4 | "version": "3.2.2", | 4 | "version": "3.2.3", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "serviceURL": "https://web.telegram.org", | 7 | "serviceURL": "https://web.telegram.org", |
diff --git a/recipes/telegram/webview.js b/recipes/telegram/webview.js index 358bdaa..7d2c8e3 100644 --- a/recipes/telegram/webview.js +++ b/recipes/telegram/webview.js | |||
@@ -8,25 +8,36 @@ function _interopRequireDefault(obj) { | |||
8 | 8 | ||
9 | module.exports = Ferdi => { | 9 | module.exports = Ferdi => { |
10 | const getMessages = () => { | 10 | const getMessages = () => { |
11 | let count = 0; | 11 | let direct = 0; |
12 | let count_sec = 0; | 12 | let indirect = 0; |
13 | const elements = document.querySelectorAll('.rp'); | 13 | const elements = document.querySelectorAll('.rp'); |
14 | for (const element of elements) { | 14 | for (const element of elements) { |
15 | const subtitleBadge = element.querySelector('.dialog-subtitle-badge'); | 15 | const subtitleBadge = element.querySelector('.dialog-subtitle-badge'); |
16 | if (subtitleBadge) { | 16 | if (subtitleBadge) { |
17 | const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent); | 17 | const parsedValue = Ferdi.safeParseInt(subtitleBadge.textContent); |
18 | if (element.dataset.peerId > 0) { | 18 | if (element.dataset.peerId > 0) { |
19 | count += parsedValue; | 19 | direct += parsedValue; |
20 | } else { | 20 | } else { |
21 | count_sec += parsedValue; | 21 | indirect += parsedValue; |
22 | } | 22 | } |
23 | } | 23 | } |
24 | } | 24 | } |
25 | 25 | ||
26 | Ferdi.setBadge(count, count_sec); | 26 | Ferdi.setBadge(direct, indirect); |
27 | }; | 27 | }; |
28 | 28 | ||
29 | Ferdi.loop(getMessages); | 29 | const getActiveDialogTitle = () => { |
30 | const element = document.querySelector('.top .peer-title'); | ||
31 | |||
32 | Ferdi.setDialogTitle(element ? element.textContent : ''); | ||
33 | }; | ||
34 | |||
35 | const loopFunc = () => { | ||
36 | getMessages(); | ||
37 | getActiveDialogTitle(); | ||
38 | }; | ||
39 | |||
40 | Ferdi.loop(loopFunc); | ||
30 | 41 | ||
31 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); | 42 | Ferdi.injectCSS(_path.default.join(__dirname, 'service.css')); |
32 | }; | 43 | }; |
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 @@ | |||
1 | const _path = _interopRequireDefault(require('path')); | 1 | const _path = _interopRequireDefault(require('path')); |
2 | 2 | ||
3 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | 3 | function _interopRequireDefault(obj) { |
4 | return obj && obj.__esModule ? obj : { default: obj }; | ||
5 | } | ||
4 | 6 | ||
5 | module.exports = (Ferdi, settings) => { | 7 | module.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 | }; |