Jump to content

User:Plastikspork/test.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>
jQuery(document).ready(function($) {
	var txt = document.getElementsByName('wpTextbox1')[0];
	if( document.getElementsByClassName("infobox").length > 0 ) {
		document.getElementsByClassName("infobox")[0].setAttribute('id', 'infobox');
		if( document.getElementsByClassName("mw-revision").length > 0) {
			document.location.hash = "#infobox";
		}
	}
	function wpTest()
	{
		var config = mw.config.get(['wgNamespaceNumber', 'wgTitle', 'wgUserGroups', 'skin']);
		var old = txt.value;
//		txt.value = txt.value + '♦' + '₳' + '฿';
//		txt.value = txt.value.replace(/(<)(noinclude>)[\t \r\n]*♦[\t ]*₳[\t ]*฿/gim, '$1/$2');
//		txt.value = txt.value.replace(/<includeonly>[\t\r\n ]*<\/includeonly>/gi, '');
//		txt.value = txt.value.replace(/(<noinclude>(?:[^<>]|[\r\n])*)<noinclude>[\t ]*[\r\n]*((?:[^<>]|[\r\n])*<\/noinclude>)/gi, '$1$2');
//		txt.value = txt.value.replace(/♦[\t ]*₳[\t ]*฿/g, '');
		if (mw.config.get('wgNamespaceNumber') == 0) {
		txt.value = txt.value.replace(/[\t ]*[\r\n][\t ]*[\r\n][\t ]*[\r\n]/g, '\n\n');
		txt.value = txt.value.replace(/[\t ]*[\r\n][\t ]*[\r\n][\t ]*[\r\n]/g, '\n\n');
		txt.value = txt.value.replace(/[\t ]*[\r\n][\t ]*[\r\n][\t ]*[\r\n]/g, '\n\n');
		txt.value = txt.value.replace(/[\t ]*[\r\n][\t ]*[\r\n][\t ]*[\r\n]/g, '\n\n');
		}
		txt.value = txt.value.replace(/(\]\][\t ]*[\r\n])[\t ]*[\r\n]*[\t ]*[\r\n]*(\{\{[^{}]*\-stub\}\})/g, '$1\n\n$2');
		txt.value = txt.value.replace(/(\}\})[\t ]*[\r\n][\t ]*([\r\n]\{\{[Aa]uthority)/g, '$1$2');
		txt.value = txt.value.replace(/(\{\{[Hh]istorical populations[^{}]*\|[ ]*align[ ]*=[ ]*)left([^{}]*\}\}[\t\r\n ]*)\{\{[Cc]lear[^{}]*\}\}[\t \r\n]*/g, '$1none$2');
		for (var i=0; i<10; i++) {
			txt.value = txt.value.replace(/(\{\{[Hh]istorical populations[^{}]*)(\|)[\t ]*([\r\n])/g, '$1$3$2');
		}
		txt.value = txt.value.replace(/\{\{[_ ]*([Hh]ttps?:[^{}\|]*)\}\}/g, '$1');
		txt.value = txt.value.replace(/(\{\{)[_ ]*[Cc]ita[_ ]*(\|[^{}]*\|)[ ]*(p|pp)\.[ ]*([^{}\|]*\}\})/g, '$1harvnb$2$3=$4');
		txt.value = txt.value.replace(/(\{\{(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*\|(?:[^{}\|=\[\]]|\[\[[^\[\]]*\]\])*)\|[\| ]*(\|[ ]*11[ ]*=)/g, '$1$2');
		txt.value = txt.value.replace(/(\{\{)(?:[\t ]*Template:[\t_ ]*|)([^:\{\}\|]*)\/meta\/color[\t_ ]*(\}\})/g, '$1party color|$2$3');
		txt.value = txt.value.replace(/(\{\{[\t_ ]*use[\t_ ]+(?:dmy|mdy)[\t_ ]+dates[^{}]*\}\})([\r\n\t ]*)(\{\{[\t ]*short description[^{}]*\}\})/gi, '$3$2$1');

		txt.value = txt.value.replace(/(\{\{coord[^{}]*\}\})([\t\r\n ]*)(\{\{authority control[^{}]*\}\})/gi, '$3$2$1');
		txt.value = txt.value.replace(/(\|[ ]*leader_name[ ]*=[^\r\n]*[\r\n])((?:\{\{(?:\{\{(?:\{\{[^{}]*}}|[^{}])*}}|[^{}])*}}|[^{}])*)(\|[ ]*leader_party[ ]*=[^\r\n]*[\r\n])/g, '$1$3$2');
		txt.value = txt.value.replace(/(\|[ ]*native_name_lang[ ]*=[^\r\n]*[\r\n])((?:\{\{(?:\{\{(?:\{\{[^{}]*}}|[^{}])*}}|[^{}])*}}|[^{}])*)(\|[ ]*official_name[ ]*=[^\r\n]*[\r\n])/g, '$1$3$2');
		txt.value = txt.value.replace(/(km2[ ]*=)[ ]*\{\{#expr:\{\{formatnum[^\r\n]*/g, '$1 auto');
		txt.value = txt.value.replace(/(density_metro_km2[ ]*=)[ ]*$/g, '$1 auto');
		txt.value = txt.value.replace(/(<[ ]*nowiki[ ]*>(?:<ref[^<>]*>|[^<])*\{\{)([^<\|\{\}]*https?:)/gi, '$1<' + '/nowiki><' + 'nowiki>$2');
		txt.value = txt.value.replace(/\{\{\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}\}/gi, '<' + 'nowiki>$1<' + '/nowiki>');
		txt.value = txt.value.replace(/\*[\t\r\n ]*\{\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}[\t\r\n ]([\r\n])/gi, '* $1$2');
		txt.value = txt.value.replace(/[\r\n][\t ]*\{\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}[\t\r\n ]([\r\n])/gi, '$2$1$2');
		txt.value = txt.value.replace(/(<!--)[\t\r\n ]*\{\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}[\t\r\n ]*(-->)/gi, '$1 $2 $3');
		txt.value = txt.value.replace(/>[\t\r\n ]*\{\{(?:cite|web|[_\r\n\t ])*(https?:[^ \|\{\}]*)[_ ]*\}\}[\t\r\n ]*</gi, '>$1<');
		txt.value = txt.value.replace(/>[\t\r\n ]*\{\{(?:cite|web|[_\r\n\t ])*(https?:[^ \|\{\}]*)[_ ]*\}?[\t\r\n ]*</gi, '>$1<');
		txt.value = txt.value.replace(/(=[\t ]*\{\{)[_ ]*(https?:[^ \|\{\}]*)/g, '$1URL|$2');
		txt.value = txt.value.replace(/\{\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}/gi, '[$1]');
		txt.value = txt.value.replace(/(\{\{)[_ ]*(https?:[^ \|\{\}=]*)[\t ]*\|([^\|{}]*\}\})/gi, '$1URL|$2|$3');
		txt.value = txt.value.replace(/(\{\{)[_ ]*(https?:[^ \|\{\}]*)[\t ]*\|([^\|{}]*\}\})/gi, '$1URL|1=$2|2=$3');
		txt.value = txt.value.replace(/(\{\{)[_ ]*(https?:[^ \|\{\}]*)/gi, '$1cite web|url=$2');
		txt.value = txt.value.replace(/\*[\t\r\n ]*\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}?[\t\r\n ]([\r\n])/gi, '* $1$2');
		txt.value = txt.value.replace(/[\r\n][\t ]*\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}?[\t\r\n ]([\r\n])/gi, '$2$1$2');
		txt.value = txt.value.replace(/(<!--)[\t\r\n ]*\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}?[\t\r\n ]*(-->)/gi, '$1 $2 $3');
		txt.value = txt.value.replace(/>[\t\r\n ]*\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}[\t\r\n ]*</gi, '>$1<');
		txt.value = txt.value.replace(/>[\t\r\n ]*\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}?[\t\r\n ]*</gi, '>$1<');
		txt.value = txt.value.replace(/(=[\t ]*)(\{)[_ ]*(https?:[^ \|\{\}]*)/g, '$1$2$2URL|$3');
		txt.value = txt.value.replace(/\{[_ ]*(https?:[^ \|\{\}]*)[_ ]*\}\}/gi, '[$1]');
		txt.value = txt.value.replace(/(\{)[_ ]*(https?:[^ \|\{\}=]*)[\t ]*\|([^\|{}]*\}\})/gi, '$1$1URL|$2|$3');
		txt.value = txt.value.replace(/(\{)[_ ]*(https?:[^ \|\{\}]*)[\t ]*\|([^\|{}]*\}\})/gi, '$1$1URL|1=$2|2=$3');
		txt.value = txt.value.replace(/(\{)[_ ]*(https?:[^ \|\{\}]*)/gi, '$1$1cite web|url=$2');
		
		txt.value = txt.value.replace(/(\{\{[_ ]*[Cc]it[ae][^{}]*)\{\{frac(?:tion|)\|([0-9]+)\|1\|([234])\}\}/gi, '$1$2&frac1$3;');
		txt.value = txt.value.replace(/(\{\{[_ ]*[Cc]it[ae][^{}]*)\{\{frac(?:tion|)\|1\|([234])\}\}/gi, '$1&frac1$2;');
		txt.value = txt.value.replace(/(\{\{[_ ]*[Cc]it[ae][^{}]*)\{\{frac(?:tion|)\|([0-9]+)\|([0-9]+)\|([0-9]+)\}\}/gi, '$1$2&nbsp;$3&frasl;$4');
		txt.value = txt.value.replace(/(\{\{[_ ]*[Cc]it[ae][^{}]*)\{\{frac(?:tion|)\|([0-9]+)\|([0-9]+)\}\}/gi, '$1$2&frasl;$3');
		
		// txt.value = txt.value.replace(/(\[\[Category:[^\[\]\{\}]*\]\])[\t ]*(\[\[Category:)/gi, '$1\n$2');
		txt.value = txt.value.replace(/(\[\[Category:[^\[\]\{\}]*\]\])[\t ]*(\{\{collapsible[^{}]*\}\})/gi, '$2\n$1');
		txt.value = txt.value.replace(/([\r\n]\[\[Category:[^<>\r\n]*)(<\/noinclude>)/gi, '$1\n$2');
		txt.value = txt.value.replace(/(Navbox)[_ ]+M(usical)[_ ]+[Aa](rtist)/gi, '$1 m$2 a$3');
		
		txt.value = txt.value.replace(/(<)(ref[^<>\/]*>[^<>]*\{\{)subst:/gi, '$1{' + '{subst:void}' + '}$2subst:');
		
		if(txt.value != old ) {
		var editsummary = document.getElementsByName('wpSummary')[0];
		if (editsummary.value == '') {
			editsummary.value = 'Format';
		}
		document.forms.editform.wpDiff.click();
		}

	}	
	if(txt) {
		mw.loader.using(['mediawiki.util']).done( function() {
		wpTest();
		});
	}
});
// </syntaxhighlight>