User:Enterprisey/search-shortcuts.js

From Wikipedia, the free encyclopedia

This is the current revision of this page, as edited by Enterprisey (talk | contribs) at 02:37, 13 November 2023 (add some more thanks earwig for the suggestions). The present address (URL) is a permanent link to this version.

(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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>