Jump to content

User:Qwerfjkl/scripts/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.
// Fork of [[User:Guarapiranga/search-shortcuts.js]]

// Fork of [[User:Enterprisey/search-shortcuts.js]] that can be customised by declaring the shortcuts where it's imported

/* <nowiki> */
var expansions;
$( document ).ready( function() {
   $( document.getElementsByClassName('cdx-text-input__input cdx-text-input__input--has-value')[0] ).on( "keydown", function( event ) { 
        if( event.key === "/" || event.key === ":" ) {
            var val = $( this ).val().toLowerCase();
            if( expansions[val] )
                $( this ).val( expansions[val] );
        } else if( $( this ).val().trim().indexOf( "{{" ) === 0 )
        	if( $( this ).val().trim().indexOf( "{{#" ) === 0 )
        		if( $( this ).val().trim().indexOf( "{{#invoke:" ) === 0 )
        			$( this ).val( $( this ).val().replace( "{{#invoke:", "Module:" ).replace( /\s*\|.*/, "" ).replace( "}}", "" ) );
        		else $( this ).val( $( this ).val().replace( "{{#", "H:MW#" ).replace( /\s*\|.*/, "" ).replace( "}}", "" ) );
        	else $( this ).val( $( this ).val().replace( "{{", "Template:" ).replace( /\s*\|.*/, "" ).replace( "}}", "" ) );
    } );
} );
/* </nowiki> */