User:DodoMan/modifysection.js

From Test Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
 * 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);
            }

        } );
    } );
}