MediaWiki:Gadget-PrefixIndexHide.js

From Zelda Dungeon Wiki
Jump to navigation Jump to search
Want an adless experience? Log in or Create an account.

Note: After saving, 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 (Command+R on a Mac)
  • Google Chrome: press Ctrl+Shift+R (Command+Shift+R on a Mac)
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl+F5
  • Konqueror: click Reload or press F5
  • Opera: clear the cache in Tools → Preferences
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Prefixindex' ) {
        var prefix = $( '#nsfrom' ).val();
        var hideprefixVal = mw.util.getParamValue( 'hideprefix' );
                // ^ Works only 1.17+
                // Replace with a call to a similar function or create one if you're using 1.16 or lower
        var $hideprefixLabel = $( '<label/>', {
                        'for': 'hideprefix',
                        'text': 'Hide prefix:'
        } );
        var $hideprefixInput = $( '<input/>', {
                'type': 'checkbox',
                'name': 'hideprefix',
                'id': 'hideprefix',
                'value': '1'
        } );
        if ( hideprefixVal == '1' ) {
                $hideprefixInput.attr( 'checked', 'checked' );
        }
        var $hideprefixRow = $( '<tr/>' )
                .append( $( '<td/>', {
                        'class': 'mw-label',
                        'html': $hideprefixLabel
                        } ) )
                .append( $( '<td/>', {
                        'class': 'mw-input',
                        'html': $hideprefixInput
                        } ) );
        // Add checkbox
        $( '#nsselect' ).find( ' > tbody:first' ).append( $hideprefixRow );
        // Do it
        if ( prefix && hideprefixVal == '1' ) {
                $( '#mw-prefixindex-list-table td a' ).text( function( i, val ) {
                        return val.replace( prefix, '' );
                } );
        }
}