User:Enterprisey/search-links.js

// vim: ts=4 sw=4 et ai // $( function {    function insertSearchLinks {        $( ".suggestions-results" )            .children            .children            .append( function  { try { var titleOfSuggestion = $( this ).text, editUrl = mw.util.getUrl( titleOfSuggestion, { "action": "edit" } ); return $( "" ) .addClass( "suggestion-link" ) .attr( "href", editUrl ) .text( "(edit)" ) } catch (e) { console.error(e); } } )   }

// Useful for troubleshooting //window.addEventListener( "blur", function (e) { e.stopPropagation; e.stopImmediatePropagation; return false; }, true );

// Wire up the handler for searching. Note that this is HACKY and depends on   // implementation details. As of October 2019, the mediawiki.searchSuggest // module depends on the jquery.suggestions module. The former uses // mediawiki.track to fire a bunch of searchSuggest tracking events, and the // final one called when everything's updated is impression-results. That's   // the one we look for here. Ideally we would use the actual // jquery.suggestions hooks, but I couldn't figure out how to do that. mw.loader.using( "mediawiki.util", function {        mw.trackSubscribe( "mediawiki.searchSuggest", function ( topic, value ) { if( value.action === "impression-results" ) { insertSearchLinks; }       } );    } );

mw.loader.addStyleTag(       ".suggestion-link { z-index: 1; float: right; position:relative; left: 0.2em; }" +        ".suggestions-result-current a { color: white; }"    ); } ); //