User:Technical 13/Scripts/Gadget-codeBacklinks.js
( function ( mw, $ ) {
$( 'pre.source-' + mw.config.get( 'wgPageContentModel' ) ).find( 'span.co1, span.coMULTI' ).each( function() {
var codeComment = $( this ).html().substr( $( this ).html().indexOf( '[[' ) );
var wikiLink = , wikiLinkPipe = , replaceWikiLink = , extraLinks = ;// declare variables
while ( codeComment.indexOf( '' ) !== -1 && codeComment.indexOf( '' ) !== -1 ){
if ( codeComment.indexOf( '|' ) !== -1 &&
codeComment.indexOf( '|' ) > codeComment.indexOf( '[[' ) &&
codeComment.indexOf( '|' ) < codeComment.indexOf( ']]' ) ) {
wikiLink = codeComment.slice( codeComment.indexOf( '[[' ) + 2, codeComment.indexOf( '|' ) );
wikiLinkPipe = codeComment.slice( codeComment.indexOf( '|' ), codeComment.indexOf( ']]' ) );
} else {
wikiLink = codeComment.slice( codeComment.indexOf( '' ) + 2, codeComment.indexOf( '' ) );
}
replaceWikiLink = codeComment.slice( codeComment.indexOf( '' ), codeComment.indexOf( '' ) + 2 );
codeComment = codeComment.substr( codeComment.indexOf( ']]' ) + 2 );
if ( wikiLink.search( 'Special:' ) === -1 ) {
extraLinks = ' ( edit | wlh )';
}
$( this ).html( $( this ).html().replace( replaceWikiLink, '[[' + wikiLink + '' +
wikiLinkPipe + ']]' + extraLinks ) );
wikiLink = , wikiLinkPipe = , replaceWikiLink = , extraLinks = ;
}
} );
} ( mediaWiki, jQuery ) );