diff options
Diffstat (limited to 'recipes/icloud-mail/webview.js')
-rw-r--r-- | recipes/icloud-mail/webview.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/recipes/icloud-mail/webview.js b/recipes/icloud-mail/webview.js new file mode 100644 index 0000000..526a205 --- /dev/null +++ b/recipes/icloud-mail/webview.js | |||
@@ -0,0 +1,49 @@ | |||
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 | const getMessages = root => { | ||
9 | // it's either localised "Inbox" name or unread count. | ||
10 | const unread = root.querySelector( | ||
11 | `.mailbox-list-pane .mailbox-list .mailbox-list-item:first-child p:last-child`, | ||
12 | ); | ||
13 | if (!unread) return; | ||
14 | const count = Ferdium.safePerseInt(unread.textContent) ?? 0; | ||
15 | Ferdium.setBadge(count); | ||
16 | }; | ||
17 | |||
18 | const getActiveDialogTitle = root => { | ||
19 | const activeThread = root.querySelector( | ||
20 | `.thread-list .thread-list-item[aria-selected="true"]`, | ||
21 | ); | ||
22 | // if there's a active thread, use partipicant names. if not, use mailbox name (inbox, junk, trash etc.) | ||
23 | if (activeThread) { | ||
24 | const sender = activeThread.querySelector( | ||
25 | '.thread-header .thread-participants', | ||
26 | ); | ||
27 | Ferdium.setDialogTitle(sender.textContent); | ||
28 | return; | ||
29 | } | ||
30 | |||
31 | const activeMailbox = root.querySelector( | ||
32 | `.mailbox-list-pane .mailbox-list .mailbox-list-item[aria-selected="true"] p`, | ||
33 | ); | ||
34 | Ferdium.setDialogTitle(activeMailbox.textContent); | ||
35 | }; | ||
36 | |||
37 | const loopFunc = () => { | ||
38 | // they put the mail root in an iframe for some reason | ||
39 | const childDocument = document.querySelector( | ||
40 | 'iframe.child-application#early-child', | ||
41 | )?.contentDocument; | ||
42 | getMessages(childDocument); | ||
43 | getActiveDialogTitle(childDocument); | ||
44 | }; | ||
45 | |||
46 | Ferdium.loop(loopFunc); | ||
47 | |||
48 | Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); | ||
49 | }; | ||