User:Sm8ps/SectionEditing.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.
/*
 * Add a tab to toggle section editing links.
 */

/* sm8ps
 * 20220905: show links
 * 20220906: toggle links
 */

if ( mw.config.get('wgNamespaceNumber') >= 0 ) {

    mw.loader.using( 'mediawiki.util', function () {
        $( function ( $ ) {

            var link = mw.util.addPortletLink( 'p-cactions', '#', 'Section editing', 'Section editing' );
            $( link ).click( function ( e ) {
                e.preventDefault();
                mw.loader.using( [ 'mediawiki.api', 'oojs-ui' ], function () {
                    launch();
                } );
            } );

            function launch( apicontinue ) {
                /* get display style and toggle value */
                var element = document.querySelector( '.mw-editsection' ) ;
                var style = getComputedStyle( element ) ;
                var display = style.display ;
                var styles ;
                if( display == 'none' ) {
                    styles = '.mw-editsection { display:inline!important; }';
                } else {
                    styles = '.mw-editsection { display:none!important; }';
                }
                /* add tab */
                var head = document.getElementsByTagName('HEAD')[0];
                var css = document.createElement('style');
                css.type = 'text/css';
                if (css.styleSheet)
                    css.styleSheet.cssText = styles;
                else
                    css.appendChild(document.createTextNode(styles));
                head.appendChild(css);
            }

        } );
    } );
}