From a8b66c0f916d1ee32a63b4e2aa32f55bf04a0061 Mon Sep 17 00:00:00 2001 From: İsmail Karslı <17887754+ismailkarsli@users.noreply.github.com> Date: Sat, 8 Jun 2024 04:21:22 +0300 Subject: Add iCloud Mail recipe (#561) --- recipes/icloud-mail/icon.svg | 51 ++++++++++++++++++++++++++++++++++++++++ recipes/icloud-mail/index.js | 1 + recipes/icloud-mail/package.json | 9 +++++++ recipes/icloud-mail/webview.js | 49 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 recipes/icloud-mail/icon.svg create mode 100644 recipes/icloud-mail/index.js create mode 100644 recipes/icloud-mail/package.json create mode 100644 recipes/icloud-mail/webview.js diff --git a/recipes/icloud-mail/icon.svg b/recipes/icloud-mail/icon.svg new file mode 100644 index 0000000..5ce67f3 --- /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 0000000..dd41f72 --- /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 0000000..4a4fe01 --- /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 0000000..526a205 --- /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 = Ferdium.safePerseInt(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')); +}; -- cgit v1.2.3-54-g00ecf