MediaWiki:Gadget-codeAnchors.js

//

$( 'div.mw-highlight > pre' ).find( 'span.c:contains(/*):contains(*/)' ).not( ':contains( "\\n" )' ).each( function { if ( $( this ).html.indexOf( '/*/' ) !== 0 ) {    var rawAnchorID = $( this ).html.slice( 2, $( this ).html.lastIndexOf( '*/' ) );    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.toString.replace( window.location.hash, '' ) + '#' + 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 ); } } } );

//