Jump to content

User:WOSlinker/tennis.js

From Wikipedia, the free encyclopedia
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.
//<syntaxhighlight lang="javascript">
function font_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 'font edit' tab
if(mw.config.get('wgArticleId') != 0 ) { 
    $( function fontEditButton() {
        mw.util.addPortletLink('p-cactions', 
                       mw.util.getUrl(null,{action:'edit',font:true}),
                       'font',
                       'p-font',
                       'font edit');
    }
)}

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

        myContent = myContent.replace(/\<SMALL\>/g,'<small>');
        myContent = myContent.replace(/\<CENTER\>/g,'<center>');

        myContent = myContent.replace(/\|\<center\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'|<center>$1</center>\n|');
        myContent = myContent.replace(/\|\<center\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'|<center>$1</center>\n|');
        myContent = myContent.replace(/\| \<center\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'| <center>$1</center>\n|');
        myContent = myContent.replace(/\| \<center\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'| <center>$1</center>\n|');

        myContent = myContent.replace(/\|( )*\<center\>([\d\w\,\.\—\–\'\:\#\%\(\)]*)( )*\|\|/g,'|$1<center>$2</center>$3||');
        myContent = myContent.replace(/\|( )*\<center\>([\d\w\,\.\—\–\'\:\#\%\(\)]*)( )*\|\|/g,'|$1<center>$2</center>$3||');

        myContent = myContent.replace(/\<center\>\<\/center\>/g,'');

        myContent = myContent.replace(/\|\<small\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'|<small>$1</small>\n|');
        myContent = myContent.replace(/\|\<small\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'|<small>$1</small>\n|');
        myContent = myContent.replace(/\| \<small\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'| <small>$1</small>\n|');
        myContent = myContent.replace(/\| \<small\>([\d\w\,\. \—\–\'\:\#\%\(\)]*) *\n\|/g,'| <small>$1</small>\n|');

        myContent = myContent.replace(/\|( )*\<small\>([\d\w\,\.\—\–\'\:\#\%\(\)]*)( )*\|\|/g,'|$1<small>$2</small>$3||');
        myContent = myContent.replace(/\|( )*\<small\>([\d\w\,\.\—\–\'\:\#\%\(\)]*)( )*\|\|/g,'|$1<small>$2</small>$3||');

        myContent = myContent.replace(/\<small\>(\{\{\w\w\w\}\}) *\|\|/g,'<small>$1</small>||');
        myContent = myContent.replace(/\<small\>(\{\{\w\w\w\}\}) *\n/g,'<small>$1</small>\n');
        myContent = myContent.replace(/\<small\> *(\([\d\ ]*\)) *\n/g,'<small>$1</small>\n');

        myContent = myContent.replace(/\<small\>\<\/small\>/g,'');
        myContent = myContent.replace(/\<small\>w\/o *\n/g,'<small>w/o</small>\n');

        //myContent = myContent.replace(/\<center\>([\d\. \-\']*)\<center\>/g,'<center>$1</center>');

        myContent = myContent.replace(/\|\<center\>\'\'\'([\d\,\.]*)\<\/center\>\n\|/g,'|<center>\'\'\'$1\'\'\'</center>\n|');
        myContent = myContent.replace(/\| \<center\>\'\'\'([\d\,\.]*)\<\/center\>\n\|/g,'| <center>\'\'\'$1\'\'\'</center>\n|');




        if(document.getElementById('wpTextbox1').value != myContent) {
           document.getElementById('wpTextbox1').value=myContent;
           document.getElementById('wpSummary').value='tag fix';
           document.getElementById('wpMinoredit').checked = true;
        }

        if(document.getElementById('wpTextbox1').value == myContent) {
           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=\'\'\'[0-9]&ndash;[0-9])([ \n]*[\|\}])/g,'$1\'\'\'$2');
           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=\'\'\'[0-9]&ndash;[0-9])([ \n]*[\|\}])/g,'$1\'\'\'$2');
           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=\'\'\'[0-9]–[0-9])([ \n]*[\|\}])/g,'$1\'\'\'$2');
           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=\'\'\'[0-9]–[0-9])([ \n]*[\|\}])/g,'$1\'\'\'$2');

           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=[0-9]&ndash;[0-9])\'\'\'([ \n]*[\|\}])/g,'$1$2');
           myContent = myContent.replace(/(\| *[1-9]v[1-9]\=[0-9]–[0-9])\'\'\'([ \n]*[\|\}])/g,'$1$2');

           myContent = myContent.replace(/\=( *)\'\'\'([^\']*?)\n/g,'=$1\'\'\'$2\'\'\'\n');
           myContent = myContent.replace(/\| \'\'\'([\d\,\.]*) *\n/g,'| \'\'\'$1\'\'\'\n');
           myContent = myContent.replace(/\| \'\'([\d\,\.]*) *\n/g,'| \'\'$1\'\'\n');
           if(document.getElementById('wpTextbox1').value != myContent) {
              document.getElementById('wpTextbox1').value=myContent;
              document.getElementById('wpSummary').value='fix bold';
              document.getElementById('wpMinoredit').checked = true;
           }
        }

        if(document.getElementById('wpTextbox1').value == myContent) {
           myContent = myContent.replace(/ \'\'\(withdrew\) *\n/g,' \'\'(withdrew)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Withdrew\) *\n/g,' \'\'(Withdrew)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Withdrawn\) *\n/g,' \'\'(Withdrawn)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Final\) *\n/g,' \'\'(Final)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Finals\) *\n/g,' \'\'(Finals)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Semifinals\) *\n/g,' \'\'(Semifinals)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Quarterfinals\) *\n/g,' \'\'(Quarterfinals)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Semifinal\) *\n/g,' \'\'(Semifinal)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Quarterfinal\) *\n/g,' \'\'(Quarterfinal)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Semi Finals\) *\n/g,' \'\'(Semi Finals)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Quarter Finals\) *\n/g,' \'\'(Quarter Finals)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Semi Final\) *\n/g,' \'\'(Semi Final)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Quarter Final\) *\n/g,' \'\'(Quarter Final)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Fourth Round\) *\n/g,' \'\'(Fourth Round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Fourth round\) *\n/g,' \'\'(Fourth round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Third Round\) *\n/g,' \'\'(Third Round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Third round\) *\n/g,' \'\'(Third round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Second Round\) *\n/g,' \'\'(Second Round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Second round\) *\n/g,' \'\'(Second round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(First Round\) *\n/g,' \'\'(First Round)\'\'\n');
           myContent = myContent.replace(/ \'\'\(First round\) *\n/g,' \'\'(First round)\'\'\n');

           myContent = myContent.replace(/ \'\'\(Withdrew([\w ]*)\) *\n/g,' \'\'(Withdrew$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Withdrawn([\w ]*)\) *\n/g,' \'\'(Withdrawn$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Final(\, [\w ]*)\) *\n/g,' \'\'(Final$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Finals(\, [\w ]*)\) *\n/g,' \'\'(Finals$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Semifinals(\, [\w ]*)\) *\n/g,' \'\'(Semifinals$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Quarterfinals(\, [\w ]*)\) *\n/g,' \'\'(Quarterfinals$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Fourth Round(\, [\w ]*)\) *\n/g,' \'\'(Fourth Round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Fourth round(\, [\w ]*)\) *\n/g,' \'\'(Fourth round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Third Round(\, [\w ]*)\) *\n/g,' \'\'(Third Round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Third round(\, [\w ]*)\) *\n/g,' \'\'(Third round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Second Round(\, [\w ]*)\) *\n/g,' \'\'(Second Round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Second round(\, [\w ]*)\) *\n/g,' \'\'(Second round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(First Round(\, [\w ]*)\) *\n/g,' \'\'(First Round$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(First round(\, [\w ]*)\) *\n/g,' \'\'(First round$1)\'\'\n');

           myContent = myContent.replace(/ \'\'\(withdrew\) *\<\/li\> *\n/g,' \'\'(withdrew)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Withdrew\) *\<\/li\> *\n/g,' \'\'(Withdrew)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Withdrawn\) *\<\/li\> *\n/g,' \'\'(Withdrawn)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Final\) *\<\/li\> *\n/g,' \'\'(Final)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Semifinals\) *\<\/li\> *\n/g,' \'\'(Semifinals)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Quarterfinals\) *\<\/li\> *\n/g,' \'\'(Quarterfinals)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Fourth Round\) *\<\/li\> *\n/g,' \'\'(Fourth Round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Fourth round\) *\<\/li\> *\n/g,' \'\'(Fourth round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Third Round\) *\<\/li\> *\n/g,' \'\'(Third Round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Third round\) *\<\/li\> *\n/g,' \'\'(Third round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Second Round\) *\<\/li\> *\n/g,' \'\'(Second Round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Second round\) *\<\/li\> *\n/g,' \'\'(Second round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(First Round\) *\<\/li\> *\n/g,' \'\'(First Round)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(First round\) *\<\/li\> *\n/g,' \'\'(First round)\'\' </li>\n');

           myContent = myContent.replace(/ \'\'\(Withdrew([\w ]*)\) *\<\/li\> *\n/g,' \'\'(Withdrew$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Withdrawn([\w ]*)\) *\<\/li\> *\n/g,' \'\'(Withdrawn$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Final(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Final$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Semifinals(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Semifinals$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Quarterfinals(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Quarterfinals$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Fourth Round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Fourth Round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Fourth round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Fourth round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Third Round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Third Round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Third round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Third round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Second Round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Second Round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(Second round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(Second round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(First Round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(First Round$1)\'\' </li>\n');
           myContent = myContent.replace(/ \'\'\(First round(\, [\w ]*)\) *\<\/li\> *\n/g,' \'\'(First round$1)\'\' </li>\n');

          //Champion
          myContent = myContent.replace(/\'\'\'\{\{flagicon\|(\w*)\}\} \[\[([\w ]*)\]\] \(Champion(s*)\) *\n/g,'\'\'\'\{{flagicon|$1}} [[$2]] (Champion$3)\'\'\'\n');
          myContent = myContent.replace(/\{\{flagicon\|(\w*)\}\} \'\'\'\[\[([\w ]*)\]\] \(Champion(s*)\) *\n/g,'{{flagicon|$1}} \'\'\'[[$2]] (Champion$3)\'\'\'\n');
          myContent = myContent.replace(/\'\'\'\{\{flagicon\|(\w*)\}\} (.*?) \(Champions\) *\n/g,'\'\'\'{{flagicon|$1}} $2 (Champions)\'\'\'\n');
          myContent = myContent.replace(/\{\{flagicon\|(\w*)\}\} \'\'\'(.*?) \(Champions\) *\n/g,'{{flagicon|$1}} \'\'\'$2 (Champions)\'\'\'\n');

          //Qualified
          myContent = myContent.replace(/\'\'\'\{\{flagicon\|(\w*)\}\} \[\[([^\n\'\]]*?)\]\] \(Qualified\) *\n/g,'\'\'\'\{{flagicon|$1}} [[$2]] (Qualified)\'\'\'\n');
          myContent = myContent.replace(/\{\{flagicon\|(\w*)\}\} \'\'\'\[\[([^\n\'\]]*?)\]\] \(Qualified\) *\n/g,'{{flagicon|$1}} \'\'\'[[$2]] (Qualified)\'\'\'\n');
          myContent = myContent.replace(/ \'\'\(Qualifying Competition\) *\n/g,' \'\'(Qualifying Competition)\'\'\n');
          myContent = myContent.replace(/ \'\'\(Qualifying competition\) *\n/g,' \'\'(Qualifying competition)\'\'\n');

          myContent = myContent.replace(/\=\{\{flagicon\|(\w*)\}\} \'\'\'\[\[([^\n\'\]]*?)\]\] *\n/g,'={{flagicon|$1}} \'\'\'[[$2]]\'\'\'\n');

          myContent = myContent.replace(/\# *\'\'\'\{\{flagicon\|(\w*)\}\} \[\[([^\n\'\]]*?)\]\] *\n/g,'# \'\'\'\{{flagicon|$1}} [[$2]]\'\'\'\n');
          myContent = myContent.replace(/\# *\{\{flagicon\|(\w*)\}\} \'\'\'\[\[([^\n\'\]]*?)\]\] *\n/g,'# \{{flagicon|$1}} \'\'\'[[$2]]\'\'\'\n');

           myContent = myContent.replace(/ \'\'\(Round Robin\) *\n/g,' \'\'(Round Robin)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Round robin\) *\n/g,' \'\'(Round Robin)\'\'\n');
           myContent = myContent.replace(/ \'\'\(round robin\) *\n/g,' \'\'(round robin)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Round Robin(\, [\w ]*)\) *\n/g,' \'\'(Round Robin$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(Round robin(\, [\w ]*)\) *\n/g,' \'\'(Round Robin$1)\'\'\n');
           myContent = myContent.replace(/ \'\'\(round robin(\, [\w ]*)\) *\n/g,' \'\'(round robin$1)\'\'\n');

           if(document.getElementById('wpTextbox1').value != myContent) {
              document.getElementById('wpTextbox1').value=myContent;
              document.getElementById('wpSummary').value='fix italics';
              document.getElementById('wpMinoredit').checked = true;
           }
        }

        if(document.getElementById('wpTextbox1').value == myContent) {
           myContent = myContent.replace(/\|\'\'\'Event *\n/g,'|\'\'\'Event\'\'\'\n');
           myContent = myContent.replace(/\|\'\'\'W *\n/g,'|\'\'\'W\'\'\'\n');
           myContent = myContent.replace(/\|\{\{[Tt]ooltip\| *\'\'\'W *\| *Win\}\} *\n/g,'|{{Tooltip|\'\'\'W\'\'\'|Win}} \n');
           if(document.getElementById('wpTextbox1').value != myContent) {
              document.getElementById('wpTextbox1').value=myContent;
              document.getElementById('wpSummary').value='fix bold';
              document.getElementById('wpMinoredit').checked = true;
           }
        }

/*
        myContent = myContent.replace(/\n\{\{[Ss]\-start\}\} *\n/g,'\n{| class="wikitable" style="margin:0.5em auto; font-size:95%;"\n');

        if(document.getElementById('wpTextbox1').value != myContent) {
           document.getElementById('wpTextbox1').value=myContent;
           document.getElementById('wpSummary').value='no need to use {{s-start}} template, just have table directly';
           document.getElementById('wpMinoredit').checked = true;
        }

*/

    }
)}
//</syntaxhighlight>