User:WOSlinker/medal-table-headers.js

function metaltable_queryString(p) { var re = RegExp('[&?]' + p + '=([^&]*)'); var matches; if (matches = re.exec(document.location)) { try { return decodeURI(matches[1]); } catch (e) { } }   return null; }

//Add a 'metaltable edit' tab if(mw.config.get('wgArticleId') != 0 ) { $( function metaltableEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',metaltable:true}), 'metaltable', 'p-metaltable', 'metaltable edit');   } )}

if(mw.config.get('wgAction') == 'edit' && metaltable_queryString('metaltable') == 'true') { $(function metaltable {       var myContent = document.getElementById('wpTextbox1').value;

myContent = myContent.replace(/\| *align *\= *\"center\" *bgcolor *\= *\"(gold|silver|\#CC9966)\" *\|/gi,'|style="text-align:center;background-color:$1;"|'); myContent = myContent.replace(/\| *align *\= *\"center\" *bgcolor *\= *\"(CC9966)\" *\|/gi,'|style="text-align:center;background-color:#$1;"|');

myContent = myContent.replace(/\! *align *\= *\"center\" *bgcolor *\= *\"(gold|silver|\#CC9966)\" *\|/gi,'!style="text-align:center;background-color:$1;"|'); myContent = myContent.replace(/\! *align *\= *\"center\" *bgcolor *\= *\"(CC9966)\" *\|/gi,'!style="text-align:center;background-color:#$1;"|');

myContent = myContent.replace(/\n\| *bgcolor *\= *\"(gold|silver|\#CC9966)\" *\|/gi,'\n|style="text-align:center;background-color:$1;"|'); myContent = myContent.replace(/\n\| *bgcolor *\= *\"(CC9966)\" *\|/gi,'\n|style="text-align:center;background-color:#$1;"|');

myContent = myContent.replace(/\|\- bgcolor\=\"\#efefef\"\n\| \'\'\'Medal\'\'\'\n\| \'\'\'Athlete\'\'\'\n\| \'\'\'Time\'\'\'/gi,'! Medal\n! Athlete\n! Time'); myContent = myContent.replace(/\|\- bgcolor\=\"\#efefef\"\n\| \'\'\'Medal\'\'\'\n\| \'\'\'Athlete\'\'\'\n\| \'\'\'Points\'\'\'/gi,'! Medal\n! Athlete\n! Points');

//myContent = myContent.replace(/\{\| class\=\"wikitable\"\n\|\- bgcolor\=\"\#efefef\"\n\!/gi,'{| class="wikitable"\n!');

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='use style for medal table headers'; document.getElementById('wpMinoredit').checked = true; }

} )}