joelekstrom / fastmate

A native Fastmail-wrapper for Mac.
MIT License
193 stars 12 forks source link

Fastmate tip: label-specific inbox #101

Closed mdbraber closed 1 year ago

mdbraber commented 1 year ago

I'm putting this here as a tip. I'm using Fastmate with different automatically labeled messages in my inbox. Sometimes I want to focus on just the inbox messages for a specific label. I can do that with search, but e.g. the automatic From address and other label-specific features don't work then. That's why I've written the JS below. Include this in a startup JS script with Fastmate and it will load an Inbox view for a label if you click that label in the sidebar.

let previousUrl = '';
const observer = new MutationObserver(function(mutations) {
    if (window.location.href !== previousUrl) {
                let mailboxRegex = /\/mail\/(Inbox|LabelA|LabelB|LabelC)/;
                let previousMailbox = mailboxRegex.test(previousUrl) ? previousUrl.match(mailboxRegex)[1] : null;
                let mailbox = mailboxRegex.test(window.location.href) ? window.location.href.match(mailboxRegex)[1] : null;
                if(mailbox !== "Inbox" && mailbox != null && previousMailbox !== null && (previousMailbox !== mailbox || (previousMailbox == mailbox && /filter=Inbox/.test(window.location.href)))) {
            let v102 = document.getElementById('v102')
                    if (v102) {
                        v102.click();
                        document.evaluate("//span[contains(.,'In Inbox')]", document, null, XPathResult.ANY_TYPE, null).iterateNext().click();
                        console.log("Filter inbox activated");
                    }
                }
            previousUrl = window.location.href;
    }
});
// start listening to changes
observer.observe(document, {subtree: true, childList: true});
joelekstrom commented 1 year ago

Thank you for this! Converting this to a discussion to keep it around 👌