diff options
Diffstat (limited to 'recipes/thelounge')
-rw-r--r-- | recipes/thelounge/package.json | 2 | ||||
-rw-r--r-- | recipes/thelounge/webview.js | 45 |
2 files changed, 28 insertions, 19 deletions
diff --git a/recipes/thelounge/package.json b/recipes/thelounge/package.json index f5dc06f..ef43758 100644 --- a/recipes/thelounge/package.json +++ b/recipes/thelounge/package.json | |||
@@ -1,7 +1,7 @@ | |||
1 | { | 1 | { |
2 | "id": "thelounge", | 2 | "id": "thelounge", |
3 | "name": "The Lounge", | 3 | "name": "The Lounge", |
4 | "version": "1.3.0", | 4 | "version": "1.4.0", |
5 | "license": "MIT", | 5 | "license": "MIT", |
6 | "config": { | 6 | "config": { |
7 | "hasCustomUrl": true, | 7 | "hasCustomUrl": true, |
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 | }; |