diff --git a/recipes/icloud-mail/icon.svg b/recipes/icloud-mail/icon.svg new file mode 100644 index 000000000..5ce67f3d5 --- /dev/null +++ b/recipes/icloud-mail/icon.svg @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + \ No newline at end of file diff --git a/recipes/icloud-mail/index.js b/recipes/icloud-mail/index.js new file mode 100644 index 000000000..dd41f7287 --- /dev/null +++ b/recipes/icloud-mail/index.js @@ -0,0 +1 @@ +module.exports = Ferdium => Ferdium; diff --git a/recipes/icloud-mail/package.json b/recipes/icloud-mail/package.json new file mode 100644 index 000000000..4a4fe014f --- /dev/null +++ b/recipes/icloud-mail/package.json @@ -0,0 +1,9 @@ +{ + "id": "icloud-mail", + "name": "iCloud Mail", + "version": "1.0.0", + "license": "MIT", + "config": { + "serviceURL": "https://www.icloud.com/mail/" + } +} diff --git a/recipes/icloud-mail/webview.js b/recipes/icloud-mail/webview.js new file mode 100644 index 000000000..1e46251b4 --- /dev/null +++ b/recipes/icloud-mail/webview.js @@ -0,0 +1,49 @@ +function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { default: obj }; +} + +const _path = _interopRequireDefault(require('path')); + +module.exports = Ferdium => { + const getMessages = root => { + // it's either localised "Inbox" name or unread count. + const unread = root.querySelector( + `.mailbox-list-pane .mailbox-list .mailbox-list-item:first-child p:last-child`, + ); + if (!unread) return; + const count = Number.parseInt(unread.textContent) ?? 0; + Ferdium.setBadge(count); + }; + + const getActiveDialogTitle = root => { + const activeThread = root.querySelector( + `.thread-list .thread-list-item[aria-selected="true"]`, + ); + // if there's a active thread, use partipicant names. if not, use mailbox name (inbox, junk, trash etc.) + if (activeThread) { + const sender = activeThread.querySelector( + '.thread-header .thread-participants', + ); + Ferdium.setDialogTitle(sender.textContent); + return; + } + + const activeMailbox = root.querySelector( + `.mailbox-list-pane .mailbox-list .mailbox-list-item[aria-selected="true"] p`, + ); + Ferdium.setDialogTitle(activeMailbox.textContent); + }; + + const loopFunc = () => { + // they put the mail root in an iframe for some reason + const childDocument = document.querySelector( + 'iframe.child-application#early-child', + )?.contentDocument; + getMessages(childDocument); + getActiveDialogTitle(childDocument); + }; + + Ferdium.loop(loopFunc); + + Ferdium.injectCSS(_path.default.join(__dirname, 'service.css')); +};