User:Qwerfjkl/scripts/toggleCollapse.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
mw.loader.using( 'mediawiki.util', function () {

    // Wait for the page to be parsed
    $( document ).ready( function () { 

        //see below "Portlets" subsection
        var link = mw.util.addPortletLink( 'p-tb', '#', 'Toggle collapse', 't-togglecollapse', 'Toggle all [hide]/[show] boxes on the page.'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            $('a[class~=mw-collapsible-text]').click(); // links with collapsible class
        } );
    } );
} );