Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iCloud Mail recipe #561

Merged
merged 2 commits into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = 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'));
};
Loading