Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function SporkInfoboxTools()
{
 var s = prompt("1 = Expand, 2 = Compress, 3 = Convert");
 if(s == 1){
  var txt = document.editform.wpTextbox1;
  var m = txt.value.match(/\|[ ]*(?:label|data|header|class|rowclass)[0-9]+[ ]*=/g);
  if (m) {
    // For each label/data/header on the list
    for (var i = 0; i < m.length; i++) {
      var n_arr = m[i].toString().match(/\|[_ ]*(?:label|data|header|class|rowclass)([0-9]+)[ ]*=/);
      var n = n_arr[1]; // Contains the number
      var n2 = 2*n;
      var nr = new RegExp('(\\|[ ]*(?:label|data|header|class))'+ n.toString() + '([ ]*=)', 'g');
      txt.value = txt.value.replace( nr, '$1' + '<!-- SPORK SKIP -->' + n2 + '$2');
    }
    txt.value = txt.value.replace(/<!-- SPORK SKIP -->/g, '');
  }
 }
 if(s == 2){
  var txt = document.editform.wpTextbox1;
  var m = txt.value.match(/\|[ ]*(?:label|data|header|class|rowclass)[0-9]+[ ]*=/g);
  if (m) {
  // For each label/data/header on the list
    for (var i = 0; i < m.length; i++) {
      var n_arr = m[i].toString().match(/\|[_ ]*(?:label|data|header|class|rowclass)([0-9]+)[ ]*=/);
      var n = n_arr[1]; // Contains the number
      var n2 = n;
      var flag = 0;
      while(n2 > 1 && flag == 0) {
       n2--;
       var nr = new RegExp('\\|[ ]*(?:label|data|header|class|rowclass)'+ n2.toString() + '[ ]*=', 'g')
       if(txt.value.search( nr ) >= 0 ) {
         n2++;
         flag = 1;
       }
     }
     if( n2 != n ) {
       var nr = new RegExp( '(\\|[ ]*(?:label|data|header|class|rowclass))'+ n.toString() + '([ ]*=)', 'g');
       txt.value = txt.value.replace( nr, '$1' + n2 + '$2');
     }
   }
  }
 }
 if(s == 3){
  var txt = document.editform.wpTextbox1;

  txt.value = txt.value.replace(/{{[ ]*#if:[ ]*({{{[^{}]*\|}}}|{{{[^{}]*\|{{{[^{}]*\|}}}}}})[ ]*\|(?: |[\r\n]|{{!}}-)*(?:!|{{!}}[ ]*''')[ ]*((?:[^\r\n\|{}]|\[\[[^\[\]]*\]\])*)(?: |[\r\n]|''')*[\r\n]{{!}}[ ]*(?:{{{[^{}]*\|*}}}|{{{[^{}]*\|{{{[^{}]*\|*}}}}}})[ ]*[\r\n](?: |[\r\n]|{{!}}-)*}}/gim, '| labelSPORKNUM    = $2\n| dataSPORKNUM     = $1\n');

  txt.value = txt.value.replace(/{{[ ]*#if:[ ]*({{{[^{}]*\|}}}|{{{[^{}]*\|{{{[^{}]*\|}}}}}})[ ]*\|(?: |[\r\n]|{{!}}-)*(?:!|{{!}}[ ]*''')[ ]*((?:[^\r\n\|{}]|\[\[[^\[\]]*\]\])*)(?: |[\r\n]|''')*[\r\n]{{!}}[ ]*class[ ]*=[ ]*"([^"{}\|]*)"[ ]*{{!}}[ ]*(?:{{{[^{}]*\|*}}}|{{{[^{}]*\|{{{[^{}]*\|*}}}}}})[ ]*[\r\n](?: |[\r\n]|{{!}}-)*}}/gim, '| labelSPORKNUM    = $2\n| classSPORKNUM    = $3\n| dataSPORKNUM     = $1\n');

  txt.value = txt.value.replace(/{{[ ]*#if:[ ]*({{{[^{}]*\|}}}|{{{[^{}]*\|{{{[^{}]*\|}}}}}})[ ]*\|(?: |[\r\n])*{{!}}-[ ]*class[ ]*=[ ]*"([^"{}\|]*)"(?: |[\r\n])*(?:!|{{!}}[ ]*''')[ ]*((?:[^\r\n\|{}]|\[\[[^\[\]]*\]\])*)(?: |[\r\n]|''')*[\r\n]{{!}}[ ]*(?:{{{[^{}]*\|*}}}|{{{[^{}]*\|{{{[^{}]*\|*}}}}}})[ ]*[\r\n](?: |[\r\n]|{{!}}-)*}}/gim, '| labelSPORKNUM    = $3\n| rowclassSPORKNUM = $2\n| dataSPORKNUM     = $1\n');

  var i = 1;
  while ( txt.value.search(/(?:label|header)SPORKNUM/g) >= 0 ) {
     txt.value = txt.value.replace(/(label|header)SPORKNUM/, '$1' + i.toString() );
     i++;
  }
  txt.value = txt.value.replace(/(label|header)([0-9]+)([ ]*=[^\r\n]*[\r\n]\|[ ]*(?:row|)class)SPORKNUM/g, '$1$2$3$2');
  txt.value = txt.value.replace(/(label|header|class|rowclass)([0-9]+)([ ]*=[^\r\n]*[\r\n]\|[ ]*data)SPORKNUM/g, '$1$2$3$2');

 }
}
addOnloadHook(function () {
 if (document.forms.editform) {
  addPortletLink('p-cactions', 
   'javascript:SporkInfoboxTools()',
   'Infobox Tools', 'ca-infoboxtools',
   'Tools for editing infobox templates', 
   'T', document.getElementById('ca-history'));
  }
});
// [[Category:Wikipedia scripts]]