diff options
author | Markus Hatvan <markus_hatvan@aon.at> | 2021-10-05 17:04:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 17:04:09 +0200 |
commit | d3841b766f9d37d557646003899f67525c5f755f (patch) | |
tree | 1bcab990c94f2b05678b7a83ffebe08298500f0b /recipes/hangoutschat/webview.js | |
parent | chore: repo maintenance (#732) (diff) | |
download | ferdium-recipes-d3841b766f9d37d557646003899f67525c5f755f.tar.gz ferdium-recipes-d3841b766f9d37d557646003899f67525c5f755f.tar.zst ferdium-recipes-d3841b766f9d37d557646003899f67525c5f755f.zip |
chore: add eslint-plugin-unicorn (#733)
Diffstat (limited to 'recipes/hangoutschat/webview.js')
-rw-r--r-- | recipes/hangoutschat/webview.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/recipes/hangoutschat/webview.js b/recipes/hangoutschat/webview.js index c8aa952..e2e5912 100644 --- a/recipes/hangoutschat/webview.js +++ b/recipes/hangoutschat/webview.js | |||
@@ -1,4 +1,4 @@ | |||
1 | module.exports = (Ferdi) => { | 1 | module.exports = Ferdi => { |
2 | // class corresponding to the red badge that is visible for direct messages | 2 | // class corresponding to the red badge that is visible for direct messages |
3 | const directMessageSelector = 'div.V6.CL.su.ahD.X9.Y2 span.akt span.XU'; | 3 | const directMessageSelector = 'div.V6.CL.su.ahD.X9.Y2 span.akt span.XU'; |
4 | 4 | ||
@@ -7,10 +7,21 @@ module.exports = (Ferdi) => { | |||
7 | 7 | ||
8 | const getMessages = () => { | 8 | const getMessages = () => { |
9 | // get unread direct messages | 9 | // get unread direct messages |
10 | const directCount = Number(document.querySelector(directMessageSelector).innerText); | 10 | let directCount; |
11 | let indirectCount; | ||
12 | |||
13 | const directCountSelector = document.querySelector(directMessageSelector); | ||
14 | if (directCountSelector) { | ||
15 | directCount = Number(directCountSelector.textContent); | ||
16 | } | ||
11 | 17 | ||
12 | // get unread indirect messages | 18 | // get unread indirect messages |
13 | const indirectCount = Number(document.querySelector(indirectMessageSelector).innerText); | 19 | const indirectCountSelector = document.querySelector( |
20 | indirectMessageSelector, | ||
21 | ); | ||
22 | if (indirectCountSelector) { | ||
23 | indirectCount = Number(indirectCountSelector.textContent); | ||
24 | } | ||
14 | 25 | ||
15 | // set Ferdi badge | 26 | // set Ferdi badge |
16 | Ferdi.setBadge(directCount, indirectCount); | 27 | Ferdi.setBadge(directCount, indirectCount); |
@@ -18,7 +29,8 @@ module.exports = (Ferdi) => { | |||
18 | 29 | ||
19 | Ferdi.loop(getMessages); | 30 | Ferdi.loop(getMessages); |
20 | 31 | ||
21 | document.addEventListener('click', (e) => { | 32 | document.addEventListener('click', e => { |
33 | // @ts-ignore | ||
22 | const { tagName, target, href } = e.target; | 34 | const { tagName, target, href } = e.target; |
23 | 35 | ||
24 | if (tagName === 'A' && target === '_blank') { | 36 | if (tagName === 'A' && target === '_blank') { |