User:Frietjes/getteams.js

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

var myContent = document.getElementsByName('wpTextbox1')[0]; // // var linktext = "Get teams"; // //

if(mw.config.get('wgNamespaceNumber') != -1 && myContent && mw.config.get('wgUserName') == 'Frietjes') { mw.loader.using(['mediawiki.util']).done( function {	 var portletlink = mw.util.addPortletLink('p-tb', '#', linktext, 't-fgt');	  $(portletlink).click(function(e) { e.preventDefault; wpGetTeams; });	}); } // // function wpGetTeams {	function uniq(a) { return a.sort.filter(function(item, pos, ary) {       return !pos || item != ary[pos - 1];    }); }

var text = myContent.value + '|'; text = text.replace(/[\r\n\t ]*(\|[\t ]*name_)/g, '|\n$1'); text = text.replace(/\{\{[_ ]*[Nn]owrap[_ ]*\|([^{}]*)\}\}/g, '$1'); text = text.replace(/\{\{[_ ]*[Ff]lag[_ ]*icon[^{}]*\}\}/g, '');

var sections = text.match(/\|[ ]*name_[^=\[\]\{\}\r\n]*=(?:\{\{[_ ]*[Ff]lag[^{}]*\}\}|\[\^\[\*\]\]|[^\[\]\|\{\}\r\n])*/g); for (i = 0; i < sections.length; i++) { if ( sections[i].search(/^\|[ ]*name_/g) >= 0 ) { sections[i] = sections[i].replace(/^\|[ ]*/g, '|'); sections[i] = sections[i].replace(/\{\{nowrap[ ]*\|([^{}]*)\}\}/gi, '$1'); sections[i] = sections[i].replace(/\{\{[_ ]*[Ff]lagicon[^{}]*\}\}[\' ]*(\[\^\[\*\]\])[^\|\[\]\r\n]*/gi, '$1'); sections[i] = sections[i].replace(/[\t \r\n\|]*$/, ''); sections[i] = sections[i].replace(/[\t \r\n]*=[\t \r\n]*/, '='); sections[i] = sections[i].replace(/(\|[ ]*name_[^=\[\]\|][^=\[\]\|])(=)/g, '$1 $2'); sections[i] = sections[i].replace(/(\[\]*)\|[^\[\]\|]*(\]\])/g, '$1$2');			if(sections[i].search(/[\[\/g) < 0) { sections[i] = sections[i] + '|'; sections[i] = sections[i].replace(/(\|[ ]*name_[^=\[\]\|]*=)([^\r\n\[\]\|]*)\|/g, '$1$2'); }		} else { sections[i] = ''; }	}	sections = uniq(sections); for (i = sections.length; i >= 0; i--) { if( sections[i] === '') { sections.splice(i,1); }	}	text = sections.join('\n'); myContent.value = text + '\n' + myContent.value; } // // }); //