diff options
Diffstat (limited to 'recipes/reddit-chat/webview.js')
-rw-r--r-- | recipes/reddit-chat/webview.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/recipes/reddit-chat/webview.js b/recipes/reddit-chat/webview.js new file mode 100644 index 0000000..7e2ef95 --- /dev/null +++ b/recipes/reddit-chat/webview.js | |||
@@ -0,0 +1,29 @@ | |||
1 | function _interopRequireDefault(obj) { | ||
2 | return obj && obj.__esModule ? obj : { default: obj }; | ||
3 | } | ||
4 | |||
5 | const _path = _interopRequireDefault(require('path')); | ||
6 | |||
7 | module.exports = Ferdium => { | ||
8 | // Regular expression for (*) or (1), will extract the asterisk or the number | ||
9 | const titleRegEx = /^\(([\d*])\)/; | ||
10 | const getMessages = function unreadCount() { | ||
11 | let directCount = 0; | ||
12 | let indirectCount = 0; | ||
13 | |||
14 | const matchArr = document.title.match(titleRegEx); | ||
15 | if (matchArr) { | ||
16 | if (matchArr[1] === '*') { | ||
17 | indirectCount = 1; | ||
18 | } else { | ||
19 | directCount = Number(matchArr[1]); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | Ferdium.setBadge(directCount, indirectCount); | ||
24 | }; | ||
25 | |||
26 | Ferdium.loop(getMessages); | ||
27 | |||
28 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | ||
29 | }; | ||