Jump to content

User:Enterprisey/search-shortcuts.js

From Wikipedia, the free encyclopedia
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.
// <nowiki>
$( document ).ready( function() {
    var expansions = {
        "wp:rfa": "WP:Requests for adminship",
        "wp:afd": "WP:Articles for deletion",
        "wp:brfa": "WP:Bots/Requests for approval",
        "wp:tfd": "WP:Templates for discussion/Log",
        't:': 'Template:',
        'c:': 'Category:',
        'p:': 'Portal:',
        'h:': 'Help:',
        'd:': 'Draft:',
        'wp:cci': 'WP:Contributor copyright investigations',
        'wp:spi': 'WP:Sockpuppet investigations',
    };
    $( "#searchInput" ).on( "keydown", function( event ) {
        if( event.key === "/" ) {
            var val = $( this ).val().toLowerCase();
            var expansion;
            if( expansion = expansions[val] ) {
                $( this ).val( expansion );
            }
        } else if( $( this ).val().trim().indexOf( "{{" ) === 0 ) {
            $( this ).val( $( this ).val().replace( "{{", "Template:" ).replace( "}}", "" ) );
        }
    } );
} );
// </nowiki>