diff options
author | 2023-07-26 06:29:03 -0600 | |
---|---|---|
committer | 2023-07-26 17:59:03 +0530 | |
commit | 9b8f01716774a960073e944823ab727cc867a8f6 (patch) | |
tree | 732b83770baa78f5cf12776aaa33ce65bebfa418 /recipes/thelounge/webview.js | |
parent | Add Excalidraw recipe (#393) (diff) | |
download | ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.gz ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.tar.zst ferdium-recipes-9b8f01716774a960073e944823ab727cc867a8f6.zip |
chore: improve lint setup (#397)
- update eslint config to closely mirror the ones from ferdium-app
- add .eslintignore
- opt in to eslint `reportUnusedDisableDirectives` config option
- remove `trailingComma: all` from `prettier` config which is default in `prettier` v3
- autofix or disable a lot of lint issues throughout codebase
- add `volta` configuration to `package.json` to autoload correct `node` and `pnpm` versions
- upgrade all `eslint` and `prettier` related dependencies to latest
- update lint:fix npm script
- reformat touched files with prettier
- bumped up minor version for all recipes that have changes
- introduced injection of 'service.css' where it was missing in many recipes
---------
Co-authored-by: Vijay A <vraravam@users.noreply.github.com>
Diffstat (limited to 'recipes/thelounge/webview.js')
-rw-r--r-- | recipes/thelounge/webview.js | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/recipes/thelounge/webview.js b/recipes/thelounge/webview.js index 5d3dbb7..9be0862 100644 --- a/recipes/thelounge/webview.js +++ b/recipes/thelounge/webview.js | |||
@@ -1,10 +1,15 @@ | |||
1 | function _interopRequireDefault(obj) { | ||
2 | return obj && obj.__esModule ? obj : { default: obj }; | ||
3 | } | ||
4 | |||
5 | const _path = _interopRequireDefault(require('path')); | ||
1 | 6 | ||
2 | function countsOfUnreadMessagesAfterMarker(unreadMarker) { | 7 | function countsOfUnreadMessagesAfterMarker(unreadMarker) { |
3 | var children = unreadMarker.parentElement.childNodes; | 8 | const children = unreadMarker.parentElement.childNodes; |
4 | var unread = 0; | 9 | let unread = 0; |
5 | var unreadHighlighted = 0; | 10 | let unreadHighlighted = 0; |
6 | 11 | ||
7 | for(var i = children.length-1; i >= 0; --i) { | 12 | for (let i = children.length - 1; i >= 0; i -= 1) { |
8 | if (children[i] === unreadMarker) { | 13 | if (children[i] === unreadMarker) { |
9 | break; | 14 | break; |
10 | } | 15 | } |
@@ -14,10 +19,10 @@ function countsOfUnreadMessagesAfterMarker(unreadMarker) { | |||
14 | } | 19 | } |
15 | 20 | ||
16 | if (children[i].classList.contains('msg')) { | 21 | if (children[i].classList.contains('msg')) { |
17 | unread++; | 22 | unread += 1; |
18 | 23 | ||
19 | if (children[i].classList.contains('highlight')) { | 24 | if (children[i].classList.contains('highlight')) { |
20 | unreadHighlighted++; | 25 | unreadHighlighted += 1; |
21 | } | 26 | } |
22 | } | 27 | } |
23 | } | 28 | } |
@@ -26,8 +31,8 @@ function countsOfUnreadMessagesAfterMarker(unreadMarker) { | |||
26 | } | 31 | } |
27 | 32 | ||
28 | module.exports = Ferdium => { | 33 | module.exports = Ferdium => { |
29 | var unreadMessagesAtLastActivity = 0; | 34 | let unreadMessagesAtLastActivity = 0; |
30 | var unreadHighlightedMessagesAtLastActivity = 0; | 35 | let unreadHighlightedMessagesAtLastActivity = 0; |
31 | 36 | ||
32 | const getMessages = () => { | 37 | const getMessages = () => { |
33 | // In order to get a correct tally of unread messages, we must | 38 | // In order to get a correct tally of unread messages, we must |
@@ -37,7 +42,7 @@ module.exports = Ferdium => { | |||
37 | // messages that arrived before or while the app has focus. | 42 | // messages that arrived before or while the app has focus. |
38 | 43 | ||
39 | let direct = 0; | 44 | let direct = 0; |
40 | var directElements = document.querySelectorAll('.badge.highlight'); | 45 | const directElements = document.querySelectorAll('.badge.highlight'); |
41 | 46 | ||
42 | for (const directElement of directElements) { | 47 | for (const directElement of directElements) { |
43 | if (directElement.textContent.length > 0) { | 48 | if (directElement.textContent.length > 0) { |
@@ -51,16 +56,16 @@ module.exports = Ferdium => { | |||
51 | ); | 56 | ); |
52 | for (const indirectElement of indirectElements) { | 57 | for (const indirectElement of indirectElements) { |
53 | if (indirectElement.textContent.length > 0) { | 58 | if (indirectElement.textContent.length > 0) { |
54 | indirect++; | 59 | indirect += 1; |
55 | } | 60 | } |
56 | } | 61 | } |
57 | 62 | ||
58 | const unreadMarkers = document.querySelectorAll('div.unread-marker'); | 63 | const unreadMarkers = document.querySelectorAll('div.unread-marker'); |
59 | 64 | ||
60 | if (unreadMarkers.length > 0) { | 65 | if (unreadMarkers.length > 0) { |
61 | var counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); | 66 | const counts = countsOfUnreadMessagesAfterMarker(unreadMarkers[0]); |
62 | var unread = counts[0]; | 67 | const unread = counts[0]; |
63 | var unreadHighlighted = counts[1]; | 68 | const unreadHighlighted = counts[1]; |
64 | 69 | ||
65 | if (document.hasFocus()) { | 70 | if (document.hasFocus()) { |
66 | unreadMessagesAtLastActivity = unread; | 71 | unreadMessagesAtLastActivity = unread; |
@@ -68,10 +73,13 @@ module.exports = Ferdium => { | |||
68 | } | 73 | } |
69 | 74 | ||
70 | if (unread > unreadMessagesAtLastActivity) { | 75 | if (unread > unreadMessagesAtLastActivity) { |
71 | if (unreadHighlighted > 0 && unreadHighlighted > unreadHighlightedMessagesAtLastActivity) { | 76 | if ( |
72 | direct += (unreadHighlighted - unreadHighlightedMessagesAtLastActivity); | 77 | unreadHighlighted > 0 && |
78 | unreadHighlighted > unreadHighlightedMessagesAtLastActivity | ||
79 | ) { | ||
80 | direct += unreadHighlighted - unreadHighlightedMessagesAtLastActivity; | ||
73 | } else { | 81 | } else { |
74 | indirect++; | 82 | indirect += 1; |
75 | } | 83 | } |
76 | } | 84 | } |
77 | } else { | 85 | } else { |
@@ -84,8 +92,9 @@ module.exports = Ferdium => { | |||
84 | 92 | ||
85 | Ferdium.loop(getMessages); | 93 | Ferdium.loop(getMessages); |
86 | 94 | ||
95 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | ||
96 | |||
87 | // We need to monkey patch ServierWorker.postMessage so that notifications | 97 | // We need to monkey patch ServierWorker.postMessage so that notifications |
88 | // will work, and that needs to be done without context isolation: | 98 | // will work, and that needs to be done without context isolation: |
89 | const path = require('path'); | 99 | Ferdium.injectJSUnsafe(_path.default.join(__dirname, 'webview-unsafe.js')); |
90 | Ferdium.injectJSUnsafe(path.join(__dirname, 'webview-unsafe.js')); | ||
91 | }; | 100 | }; |