User:WOSlinker/small.js

function small_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 'small edit' tab if(mw.config.get('wgArticleId') != 0 ) { $( function smallEditButton {       mw.util.addPortletLink('p-cactions', mw.util.getUrl(null,{action:'edit',small:true}), 'small', 'p-small', 'small edit');   } )}

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

myContent = myContent.replace(/(\\(\w*\))\'\' *\n/gi,'$1 \'\'\n'); //myContent = myContent.replace(/(\[^\<\|]*?\\[^\<]*?) *\n\|/gi,'$1 \n\|');

//myContent = myContent.replace(/(\.*?) *\n/gi,'$1 \n'); //myContent = myContent.replace(/\<\/small\>\<\/small\>\n/gi,' \n');

myContent = myContent.replace(/(\\{\{flag\|\w*\}\})( *\|\|)/gi,'$1 $2'); myContent = myContent.replace(/(\\{\{flagu\|\w*\}\})( *\|\|)/gi,'$1 $2'); myContent = myContent.replace(/(\\{\{\w*\}\})( *\|\|)/gi,'$1 $2');

myContent = myContent.replace(/(\| *\[^\<\|]*?) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\[^\<\|]*?) *\n\|/gi,'$1 \n\|');

myContent = myContent.replace(/(\| *\[^\<\|]*?)( *)\|\|/gi,'$1 $2\|\|'); myContent = myContent.replace(/(\| *\[^\<\|]*?)( *)\|\|/gi,'$1 $2\|\|');

myContent = myContent.replace(/(\| *\ *\) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\ *\) *\n\|/gi,'$1 \n\|');

myContent = myContent.replace(/(\| *\<small\> *\[\^\<\*?\]\]) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\<small\> *\[\^\<\*?\]\]) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\<small\> *\[\^\<\*?\]\])( *)\|\|/gi,'$1 $2\|\|'); myContent = myContent.replace(/(\| *\<small\> *\[\^\<\*?\]\])( *)\|\|/gi,'$1 $2\|\|');

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

myContent = myContent.replace(/(\| *\<small\> *\d*? *)\<small\> *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\<small\> *\d*? *)\<small\> *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\<small\> *\d*? *)\<small\>( *)\|\|/gi,'$1 $2\|\|'); myContent = myContent.replace(/(\| *\<small\> *\d*? *)\<small\>( *)\|\|/gi,'$1 $2\|\|');

myContent = myContent.replace(/(\| *\<small\> *[^\<]*?\<sup\>[^\<]*?\<\/sup\>) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\| *\<small\> *[^\<]*?\<sup\>[^\<]*?\<\/sup\>) *\n\|/gi,'$1 \n\|');

myContent = myContent.replace(/(\<small\>[^\<\n\!]*?) *\n\|/gi,'$1 \n\|'); myContent = myContent.replace(/(\<small\>[^\<\n\!]*?) *\n\!/gi,'$1 \n\!');

myContent = myContent.replace(/(\<span style\=\"color\:\w*)\>/gi,'$1">'); myContent = myContent.replace(/(\<span style\=)\'(color\:\w*)\'\>/gi,'$1"$2">'); myContent = myContent.replace(/(\<span style\=\"color\:) (\w*\"\>)/gi,'$1$2');

myContent = myContent.replace(/(\<span style\=\"color\:\#\w*\;*\"\>[^\<\n\]]*?)( *)\|\|/gi,'$1 $2||'); myContent = myContent.replace(/(\<span style\=\"color\:\w*\;*\"\>[^\<\n\]]*?)( *)\|\|/gi,'$1 $2||');

myContent = myContent.replace(/(\<span style\=\"color\:\#\w*\;*\"\>[^\<\n\]]*?)\]/gi,'$1 ]'); myContent = myContent.replace(/(\<span style\=\"color\:\w*\;*\"\>[^\<\n\]]*?)\]/gi,'$1 ]');

myContent = myContent.replace(/(\<span style\=\"color\:\w*\;*\"\>[^\<\n\]]*\<br\>\d*)\]/gi,'$1 ]'); myContent = myContent.replace(/(\<span style\=\"color\:\w*\;*\"\>[^\<\n\]]*\<br *\/\>\d*)\]/gi,'$1 ]');

myContent = myContent.replace(/(\'\'\'\<span style\=\"color\:\w*\"\>[\−\+\w\d\'\'\,\%]*)\'\'\' *\n/gi,'$1 \'\'\'\n'); myContent = myContent.replace(/(\'\'\'\<span style\=\"color\:\w*\;\"\>[\−\+\w\d\'\'\,\%]*)\'\'\' *\n/gi,'$1 \'\'\'\n'); myContent = myContent.replace(/(\<span style\=\"color\:\w*\"\>[\−\+\w\d\'\'\,\%]*) *\n/gi,'$1 \n'); myContent = myContent.replace(/(\<span style\=\"color\:\w*\;\"\>[\−\+\w\d\'\'\,\%]*) *\n/gi,'$1 \n');

myContent = myContent.replace(/\|\| *\<small\> *\|\|!/gi,'|| ||'); myContent = myContent.replace(/\|\| *\<\/small\> *\|\|!/gi,'|| ||');

myContent = myContent.replace(/(\<span [^\>]*\>\'\'\'\w*\'\'\') *\|/gi,'$1 |');

myContent = myContent.replace(/(\<span style\=\"font\-size\:[\w\d\%]*)\>/gi,'$1">'); myContent = myContent.replace(/(\<span style\=)\'(font\-size\:[\w\d\%]*)\'\>/gi,'$1"$2">'); myContent = myContent.replace(/(\<span style\=\"font\-size\:) ([\w\d\%]*\"\>)/gi,'$1$2');

myContent = myContent.replace(/(\<span style\=\"font\-size\:[\w\d\%]*\;*\"\>[^\<\n\]]*?)( *)\|\|/gi,'$1 $2||');

myContent = myContent.replace(/(\'\'\'\<span style\=\"font\-size\:[\w\d\%]*\"\>[\−\+\w\d\'\'\,\%]*)\'\'\' *\n/gi,'$1 \'\'\'\n'); myContent = myContent.replace(/(\'\'\'\<span style\=\"font\-size\:[\w\d\%]*\;\"\>[\−\+\w\d\'\'\,\%]*)\'\'\' *\n/gi,'$1 \'\'\'\n'); myContent = myContent.replace(/(\<span style\=\"font\-size\:[\w\d\%]*\"\>[\−\+\w\d\'\'\,\%\{\}\[\]\$\/\(\) ]*?) *\n/gi,'$1 \n'); myContent = myContent.replace(/(\<span style\=\"font\-size\:[\w\d\%]*\;\"\>[\−\+\w\d\'\'\,\%\{\}\[\]\$\/\(\) ]*?) *\n/gi,'$1 \n');

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

var smallmatches1 = myContent.match(/\<small\>/gi)?.length ?? 0;       var smallmatches2 = myContent.match(/\<\/small\>/gi)?.length ?? 0;       var spanmatches1 = myContent.match(/\<span/gi)?.length ?? 0;       var spanmatches2 = myContent.match(/\<\/span\>/gi)?.length ?? 0;

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value=myContent; if (smallmatches1 == smallmatches2 && spanmatches1 == spanmatches2) { document.getElementById('wpSummary').value='fix small tags'; if (spanmatches1 !== 0) { document.getElementById('wpSummary').value='fix span tags'; }; if (smallmatches1 !== 0) { document.getElementById('wpSummary').value='fix small tags'; }; document.getElementById('wpSaveWidget').style.visibility = 'visible'; } else { document.getElementById('wpSummary').value='fix small tags (MISMATCH: ' + smallmatches1 + ' - ' + smallmatches2 + ', ' + spanmatches1 + ' - ' + spanmatches2 + ')'; document.getElementById('wpSaveWidget').style.visibility = 'hidden'; }          document.getElementById('wpMinoredit').checked = true;

document.getElementById('wpTextbox1').addEventListener('change', function {             var myContent = document.getElementById('wpTextbox1').value;              var smallmatches1 = myContent.match(/\<small\>/gi)?.length ?? 0;               var smallmatches2 = myContent.match(/\<\/small\>/gi)?.length ?? 0;               var spanmatches1 = myContent.match(/\<span/gi)?.length ?? 0;               var spanmatches2 = myContent.match(/\<\/span\>/gi)?.length ?? 0;                  if (smallmatches1 == smallmatches2 && spanmatches1 == spanmatches2) {                    document.getElementById('wpSummary').value='fix small tags';                    if (spanmatches1 !== 0) { document.getElementById('wpSummary').value='fix span tags'; };                    if (smallmatches1 !== 0) { document.getElementById('wpSummary').value='fix small tags'; };                    document.getElementById('wpSaveWidget').style.visibility = 'visible'; } else { document.getElementById('wpSummary').value='fix small tags (MISMATCH: ' + smallmatches1 + ' - ' + smallmatches2 + ', ' + spanmatches1 + ' - ' + spanmatches2 + ')'; document.getElementById('wpSaveWidget').style.visibility = 'hidden'; }           }, false );

}

} )}

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

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

myContent = myContent.replace(/\<small\> *\n(\*[^]*?)\n\<\/small\>\n/gi,'\n$1\n\n'); myContent = myContent.replace(/\<small\> *\n(\#[^]*?)\n\<\/small\>\n/gi,'\n$1\n\n');

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value=myContent; document.getElementById('wpSummary').value='change small tags to smalldiv template'; document.getElementById('wpMinoredit').checked = true; }

} )}