Skip to content

Commit

Permalink
Add iCloud Mail recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailkarsli authored and vraravam committed Jun 7, 2024
1 parent 421f6cd commit 4423e04
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
51 changes: 51 additions & 0 deletions recipes/icloud-mail/icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions recipes/icloud-mail/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = Ferdium => Ferdium;
9 changes: 9 additions & 0 deletions recipes/icloud-mail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "icloud-mail",
"name": "iCloud Mail",
"version": "1.0.0",
"license": "MIT",
"config": {
"serviceURL": "https://www.icloud.com/mail/"
}
}
49 changes: 49 additions & 0 deletions recipes/icloud-mail/webview.js
Original file line number Diff line number Diff line change
@@ -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'));
};

0 comments on commit 4423e04

Please sign in to comment.