[How To] Auto Expand mail folders using GreaseMonkey

*Edit: Updated for Nextcloud 17 and mail v 0.18.1
Note: if you are using another language besides English you will have to change the text Show all folders and Collapse folders

I was sick of having to expand all my mail folders to avoid this bug:

So I wrote this quick user script to automatically expand all my folders.

Using the Latest Firefox Quantum you will need Violent Monkey addon 2.8.27 ( Latest Violent Mokey no longer works Greasemonkey 4.3 however now works ) or greater, Open the Violent monkey dashboard and click the + sign to add a new script.

Past the following code, changing the yourdomain.tld to your domain:

// ==UserScript==
// @name     Nextcloud Mail Expand folders
// @namespace   https://yourdomain.tld/
// @include     https://yourdomain.tld/apps/mail/*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
// @version  1
// @grant    NEXTCLOUDMAIL
// ==/UserScript==

/* Paste Here */

this.$ = this.jQuery = jQuery.noConflict(true);

console.log('[ NMEF ] - Waiting');
waitForKeyElements ("span:contains('Show all folders')", expandALL, true);
waitForKeyElements ("span:contains('Collapse folders')", setTimeout(expandINDIV, 2000), true);

function expandALL() {
  console.log('[ NMEF ] - Expand ALL Folders');
  $("span:contains('Show all folders')")[0].click();
};

function expandINDIV() {
  console.log('[ NMEF ] - Expand individual Folders');
  $('li[class*="app-navigation-entry--collapsible"] > button').click();
}

Note: this loads the remote content jquery and waitForKeyElements.js, if you wish to have them bound locally open the // @require links and past the contents at the /* Paste Here */ line. Then just delete the lines:

// @require     https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @require     https://gist.github.com/raw/2625891/waitForKeyElements.js
1 Like

Currently still working well on Firefox 64.0.2 with Nexcloud 15

Updated for Nextcloud 16

Updated for Nextcloud 17

The following is a Greasemonkey script for expanding all mail folders automatically when opening Nextcloud Mail in Firefox. This is an update for [How To] Auto Expand mail folders using GreaseMonkey which works with Nextcloud 31.

In Firefox install the add-on: Greasemonkey – Get this Extension for 🦊 Firefox (en-US)

Then in the Greasemonkey addon create a new script and paste the script below.

ATTENTION:

  • Make sure to replace cloud.example.com in the lines starting with @namespace and @include with your Nextcloud domain
  • Replace the text ‘Alle abonnierten Postfächer anzeigen’ with the English, French, Spanish, etc. text that you click in Nextcloud Mail to expand all of your subscribed folders. It needs to be exactly the text that the button shows, probably sth. like ‘Show all subscribed mailboxes’ in English.
// ==UserScript==
// @name         Nextcloud Mail: Expand all folders
// @namespace    https://cloud.example.com/
// @include      https://cloud.example.com/apps/mail/*
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js
// @require      https://gist.githubusercontent.com/BrockA/2625891/raw/waitForKeyElements.js
// @version      1
// @grant        none
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

waitForKeyElements(
  'span.app-navigation-entry__name:contains("Alle abonnierten Postfächer anzeigen")',
  function(elem) {
    console.log('[NC Mail Expander] Click expand button', elem);
    elem.click();
  },
  true
);

A polite request to the Nextcloud Mail developers: Please allow users to display exactly the mail folders they want when opening Nextcloud Mail as it can also get very messy when having multiple mailboxes. An example for a feature request in this regard is: Collapse mailboxes to 1 line each with display of unread messages from the inbox · Issue #9300 · nextcloud/mail · GitHub