MediaWiki:Gadget-codeAnchors.js

//

$( 'div.mw-highlight > pre' ).find( 'span.c:contains(/*):contains(*/)' ).not( ':contains( "\\n" )' ).each( function { var rawAnchorID = $( this ).html.slice( $( this ).html.indexOf( '/*' ) + 2, $( this ).html.indexOf( '*/' ) );  anchorID = $.trim( rawAnchorID ).replace( / /g, '_' );  if ( anchorID.length !== 0 ) {    var linkURL = encodeURIComponent( anchorID ).replace( /%/g,  '.' );    var domA = document.createElement( 'a' );    domA.innerHTML = $.trim( rawAnchorID );    domA.classList = 'codeAnchor-link';    domA.href = window.location + '#' + linkURL;    var newSpan = document.createElement( 'span' );    newSpan.id = linkURL;    newSpan.classList = 'c';    newSpan.style.backgroundColor = '#FFDDDD';    newSpan.append( document.createTextNode( '/* ' ) );    newSpan.append( domA );    newSpan.append( document.createTextNode( ' */' ) );console.log( 'newSpan: %o', newSpan );    $( this ).replaceWith( newSpan ); } } );

//