MediaWiki:Gadget-codeColours.js

// const hexKey = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' ]; const hexColour = new RegExp( '#([0-9A-F]{1,2}){3}', 'i' ); $( 'span.mh' ).each( function { var thisColour = $( this ).text;  if ( hexColour.test( thisColour ) ) {    var thisRGB = thisColour.match( /#([0-9A-F]{1,2})([0-9A-F]{1,2})([0-9A-F]{1,2})/ );    var r = ( hexKey.indexOf( thisRGB[ 1 ][ 0 ] ) * 16 ) + hexKey.indexOf( thisRGB[ 1 ][ 1 ] );    var g = ( hexKey.indexOf( thisRGB[ 2 ][ 0 ] ) * 16 ) + hexKey.indexOf( thisRGB[ 2 ][ 1 ] );    var b = ( hexKey.indexOf( thisRGB[ 3 ][ 0 ] ) * 16 ) + hexKey.indexOf( thisRGB[ 3 ][ 1 ] );    var thisFont = ( Math.sqrt( ( 0.299 * r * r ) + ( 0.587 * g * g ) + ( 0.114 * b * b ) ) > 127.5 ? '#000' : '#FFF' );   $( this ).css( { 'background-color': thisColour, 'color': thisFont } );  } } ); //