User:Frietjes/fbmt.js

// jQuery(document).ready(function($) {

var myContent = document.getElementsByName('wpTextbox1')[0]; // // myfbmtsummary = "Convert fb match tables"; var linktext = "Convert fb match table"; // //

if(mw.config.get('wgNamespaceNumber') != -1 && myContent && (mw.config.get('wgUserName') == 'Jolicnikola' || mw.config.get('wgUserName') == 'Frietjes')) { mw.loader.using(['mediawiki.util']).done( function {	 var portletlink = mw.util.addPortletLink('p-tb', '#', linktext, 't-ffbm');	  $(portletlink).click(function(e) { e.preventDefault; wpFbmt; });	}); }

// // function wpFbmtsec(s) {	// clean up old attempted conversions s = s.replace(//g, ''); // mark end of section s = s + '\n'; // move mark up to the end of the table var lt=''; while(s != lt) { lt = s;		s = s.replace(/([\r\n][\t ]*)([\r\n])/g, '$2$1'); s = s.replace(/([\r\n][A-Z0-9\*;:][^\r\n]*)([\r\n])/g, '$2$1'); }	// preformat conversions s = s.replace(/([\r\n])[\t ]+[0-9]+\.[\t ]+/g, '$1 '); s = s.replace(/([\r\n])[\t ]+(?:↓Home[\t ]*[\\\/][\t ]*Away→[\t ]*|Hemma[\t ]*[\\\/][\t ]*Borta[\t ]*)([\t ]+[^\r\n\t \{\}][^\r\n\t \{\}][^\r\n\t \{\}][^\r\n\t \{\}]?[\t ]+)/g, '$1$2'); lt=''; while(s != lt) { lt = s;		s = s.replace(/([\r\n])((?:\{\{fb[^{}]*\}\}|[\t ]+)[^\r\n]*[^\r\n\t ])[\t ]+([0-9]+)[:–\-]([0-9]+)/g, '$1$2$1{'+'{fb r|gf=$3|ga=$4}'+'}'); s = s.replace(/([\r\n])((?:\{\{fb[^{}]*\}\}|[\t ]+)[^\r\n]*[^\r\n\t ])[\t ]+[●—\-]/g, '$1$2$1{'+'{fb r|r=null}'+'}'); s = s.replace(/([\r\n])((?:\{\{fb[^{}]*\}\}|[\t ]+))[\t ]+([0-9]+)[:–\-]([0-9]+)/g, '$1$2$1{'+'{fb r|gf=$3|ga=$4}'+'}'); s = s.replace(/([\r\n])((?:\{\{fb[^{}]*\}\}|[\t ]+))[\t ]+[●—\-]/g, '$1$2$1{'+'{fb r|r=null}'+'}'); }	lt = ''; while(s != lt) { lt = s;		s = s.replace(/([\r\n])[\t ]+([^\r\n]*)([\r\n]\{\{fb r\|)/g, '$1{'+'{fb r2 team|t=$2}'+'}$3'); s = s.replace(/([\r\n])[\t ]*([\t ]+[^\r\n\t \{\}][^\r\n\t \{\}][^\r\n\t \{\}][^\r\n\t \{\}]?[\t ]+[^\r\n]*[\r\n]\{\{fb r2 team\|)/g, '$1{'+'{fb r2 header|nt=0}'+'}$2'); s = s.replace(/(\{\{fb r2 header\|nt=0\}\}[^\r\n]*[^\r\n\t \{\}])[\t ]+([^\r\n \t\{\}]+)[\t ]*([\r\n])/g, '$1$3| $2$3'); s = s.replace(/(\{\{fb r2 header\|nt=0\}\})[\t ]+([^\r\n\t \{\}]+)[\t ]*([\r\n])/g, '$1$3| $2$3'); }

// wikitable conversions s = s.replace(/([\r\n]\|[^\r\n]*)'''/g, '$1 '); s = s.replace(/([\r\n]\|[^\r\n]*)'''/g, '$1 '); s = s.replace(/[ ]*\|\|[ ]*/g, '\n| '); s = s.replace(/[\r\n]\|[ ]*([0-9\+][0-9]*)[:\-–]([0-9\-][0-9]*)/g, '\n{'+'{fb r|gf=$1|ga=$2}'+'}'); s = s.replace(/[\r\n]\|[^\[\]\|\{\}]*\|[ ]*([0-9\+][0-9]*)[:\-–]([0-9\-][0-9]*)/g, '\n{'+'{fb r|gf=$1|ga=$2}'+'}'); s = s.replace(/(\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])\|[ ]*—[ ]*([\r\n])/g, '$1{'+'{fb r|s=—}'+'}$2'); s = s.replace(/(\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])\|[^\[\]\|\{\}\r\n]*\|[ ]*—[ ]*([\r\n])/g, '$1{'+'{fb r|s=—}'+'}$2'); s = s.replace(/([\r\n])\|[ ]*—[ ]*([\r\n]\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])/g, '$1{'+'{fb r|s=—}'+'}$2'); s = s.replace(/([\r\n])\|[^\[\]\|\{\}\r\n]*\|[ ]*—[ ]*([\r\n]\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])/g, '$1{'+'{fb r|s=—}'+'}$2'); s = s.replace(/(\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])\|[ ]*([\r\n])/g, '$1{'+'{fb r|r=null}'+'}$2'); s = s.replace(/(\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])\|[^\[\]\|\{\}\r\n]*\|[ ]*([\r\n])/g, '$1{'+'{fb r|r=null}'+'}$2'); s = s.replace(/([\r\n])\|[ ]*([\r\n]\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])/g, '$1{'+'{fb r|r=null}'+'}$2'); s = s.replace(/([\r\n])\|[^\[\]\|\{\}\r\n]*\|[ ]*([\r\n]\{\{fb r[^{}]*\}\}[^\r\n]*[\r\n])/g, '$1{'+'{fb r|r=null}'+'}$2'); s = s.replace(/\|\-[^\r\n]*[\r\n]\|(?:[^\[\]\|\{\}]*\||)[\t ]*([^\r\n]*)([\r\n]\{\{fb r)/g, '{'+'{fb r2 team|t=$1}'+'}$2'); s = s.replace(/\{\|[^\r\n]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)![^\[\]\r\n]*/g, '{'+'{fb r2 header|nt=0}'+'}'); s = s.replace(/\{\|[^\r\n]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)\|[^\r\n\-\[\]][^\[\]\r\n]*/g, '{'+'{fb r2 header|nt=0}'+'}'); s = s.replace(/\{\|[^\r\n]*[\r\n](?:\|\-[^\r\n]*[\r\n]|)\|[' ]*Home[ ]*.[ ]*Away[' ]*[^\r\n\|]*/g, '{'+'{fb r2 header|nt=0}'+'}'); s = s.replace(/(\{\{fb r2 header[^{}]*\}\})[\t ]*\|\|/g, '$1\n|'); s = s.replace(/(\{\{fb r2 header[^{}]*\}\})[\t ]*[\r\n]\|[ ]*width[ ]*=[ ]*[^\|]*/g, '$1\n'); lt=''; while(s != lt) { lt = s;		if(s.search(/\{\{fb r2 header\|nt=[0-9]+[^{}]*\}\}[\t ]*[\r\n][!\|](?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n\-\}])(?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n])*(?:\|\||[\r\n])/) >=0 ) { var nt = (s.match(/\{\{fb r2 header\|nt=([0-9]+)[^{}]*\}\}[\t ]*[\r\n][!\|](?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n\-\}])(?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n])*(?:\|\||[\r\n])/))[1]; nt = Number(nt) + 1; s = s.replace(/(\{\{fb r2 header\|nt)=[0-9]+([^{}]*)(\}\})[\t ]*[\r\n][!\|]((?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n\-\}])(?:\[\^\[\*\]\]|\{\{[^{}]*\}\}|[^\[\]\{\}\|\r\n])*)((?:\|\||[\r\n]))/, '$1=' + nt + '$2|$4$3$5'); }	}	s = s.replace(/(\{\{fb r2 header[^{}]*)'''/g, '$1'); s = s.replace(/(\{\{fb r2 header[^{}]*)\|\|/g, '$1|'); s = s.replace(/(\{\{fb r2 team\|t=)[ ]*\|?[ ]*align[ ]*=[" ]*left[" ]*\|/g, '$1'); s = s.replace(/(\{\{fb[^\r\n]*[\r\n])\|\}/g, '$1{'+'{end}'+'}'); s = s.replace(/(\{\{fb r[^{}]*)(\}\})[\t ]* ([^<>]*)<\/sup>/gi, '$1|nt=$3$2'); // check and repair s = s.replace(/(\{\{fb r2 header\|nt=)([1-9][0-9]?)(\|[^{}\r\n]*\}\})[\t ]*([\r\n])/g, '$1$2$3$4'); lt = ''; while(s != lt) { lt = s;		s = s.replace(/[\t ]*([\r\n]\{\{fb r2 team\|[^{}]*\}\})[\t ]*([\r\n])/g, '$3$1 1 $2$4'); if(s.search(//) >= 0) { var nc = (s.match(//))[1]; for(var i=1; i=0) { s = s.replace(/[\t ]*([\r\n]\{\{fb r\|[^{}]*\}\})/gi, '$2$1'); }		if(s.search(/[\t ]*[\r\n]\{\{fb r2 team/) >= 0) { var nr = (s.match(/[\t ]*[\r\n]\{\{fb r2 team/))[1]; var re2 = new RegExp('[\t ]*([\\r\\n]\\{\\{fb r2 team)'); s = s.replace(re2, '$2'); }		s = s.replace(/[\t ]*([\r\n]\{\{end\}\})/g, '$2'); s = s.replace(/[\t ]*([\r\n])/g, '\n{'+'{end}'+'}$2'); s = s.replace(/[\t ]*([\r\n])/g, '{'+'{fb r|r=null}'+'}\n{'+'{end}'+'}$2'); }	s = s.replace(/[\r\n]/g, ''); return s; } // // function wpFbmt {	var oldtext = myContent.value; var sections = myContent.value.split(/([\r\n]==[^\r\n]*)/g); // begin convoluted loop var i=0; function myLoop { if ( sections[i].search(/[\r\n]==[^\r\n]*/g) >= 0 ) { if ((i+1) < sections.length) { sections[i] = sections[i] + sections[i+1]; sections[i+1] = ''; }		}		sections[i] = wpFbmtsec(sections[i]); i++; if(i<sections.length) { myLoop; }	}	myLoop; // end convoluted loop myContent.value = sections.join(''); if(myContent.value != oldtext) { var editsummary = document.getElementsByName('wpSummary')[0]; document.forms.editform.wpMinoredit.checked = true; editsummary.value = myfbmtsummary; document.forms.editform.wpDiff.click; } } // // }); //