User:PerfektesChaos/js/fixCentralAuthLocalLinks.js

/// fixCentralAuthLocalLinks.js // Fix relative links in Special:CentralAuth. // Bugzilla:45412 Phabricator:T47412                Submitted 2013-02-26 // Links in block reason on Special:CentralAuth //          link to the local wiki, not the one the block was issued on. // ResourceLoader: compatible;  dependencies: NONE /// 2014-12-30 PerfektesChaos@de.wikipedia /// Fingerprint: #0#0# /// mw:User:PerfektesChaos/js/fixCentralAuthLocalLinks /// /*jshint bitwise:true, curly:true, eqeqeq:true, latedef:true, laxbreak:true, strict:true, trailing:true, undef:true, unused:true, white:false                                     */ /*global window:false                                                 */ ( function ( mw, $ ) {  "use strict";   var Version   = 1,       Sign      = "fixCentralAuthLocalLinks",       Signature = "ext.gadget." + Sign,       Superfix  = Sign + "@PerfektesChaos." + Version;

function fire { // Autorun on load // Precondition: //   DOM.ready // 2014-12-30 PerfektesChaos@de.wikipedia var i, j, n, s, shift, show, $a, $aUser, $cells, $links, $rows, $table; if ( mw.config.get( "wgCanonicalSpecialPageName" ) ===  "CentralAuth" ) { $table = $( "table.mw-centralauth-wikislist" ); if ( $table.length ) { $rows = $table.find( "tr" ); for ( i = 0; i < $rows.length;  i++ ) { $cells = $rows.eq( i ).find( "td" ); $links = $cells.eq( 3 ).find( "a" ); n     = $links.length; if ( n ) { $aUser = $cells.eq( 0 ).find( "a" ); shift = $aUser.attr( "href" ); j     = shift.indexOf( ".org/wiki/User:" ); if ( j > 0 ) { shift = shift.substr( 0, j + 4 ); for ( j = 0; j < n;  j++ ) { $a = $links.eq( j ); s = $a.attr( "href" ); if ( /^\/[^/]/.test( s ) ) { s = s.replace( /&action=edit&redlink=1/, "" ); if ( s.indexOf( "&" ) < 0 ) { s = s.replace( /\/w\/index\.php\?title=/,                                            "/wiki/" ); }                          if ( s.indexOf( "/wiki/" ) ) { show = Superfix; } else { show = s.substr( 6 ).replace( /_/g, " " ); show = decodeURIComponent( show ) + "\n\n" + Superfix; }                          $a.attr( { "href":  shift + s,                                      "title": show } ); $a.css( { "color": "#008000" } ); }                    }   // for j                  } }           }   // for i         } }  }   // fire

if ( mw.loader.getState( Signature ) !==  "ready" ) { mw.loader.state( Signature, "ready" ); $( fire );  // don't hurry } }( window.mediaWiki, window.jQuery ) ); /// EOF  fixCentralAuthLocalLinks.js