User:Enterprisey/rc-thanks.js

Source: 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.
if( mw.config.get( "wgPageName" ) === "Special:RecentChanges" ) {
    mw.loader.using( [ "mediawiki.util" ], function () {
        function go() {
            $( "table[data-mw-revid],tr[data-mw-revid] td.mw-enhanced-rc-nested" )
                .filter( function( idx, el ) { return !el.querySelector( "a.mw-thanks-thank-link" ); } )
                .each( function ( idx, el ) {
                    var revid = el.dataset.mwRevid ||
                        el.parentNode.dataset.mwRevid;
                    var el = $( el );
                    var thanksSpan = $( "<span>" ).append( " (", $( "<a>" )
                        .addClass( "mw-thanks-thank-link" )
                        .attr( "href", mw.util.getUrl( "Special:Thanks/" + revid ) )
                        .text( "thank" ), ")" );
                    var rollbackLink = el.find( "span.mw-rollback-link" );
                    if( rollbackLink.length ) {
                        rollbackLink.after( thanksSpan );
                    } else {
                        el.append( thanksSpan );
                    }
                } );
        }

        // The hook will already run go(); no need to run it again
        mw.hook( "wikipage.content" ).add( go );
    } );
}