Dalībnieks:Edgars2007/futbolista infokaste.js

Vikipēdijas lapa

Piezīme: Lai redzētu izmaiņas, pēc publicēšanas var nākties iztīrīt sava pārlūka kešatmiņu.

  • Firefox / Safari: Pieturi Shift un klikšķini uz Pārlādēt vai nospied Ctrl-F5 vai Ctrl-R (⌘-R uz Mac)
  • Google Chrome: Nospied Ctrl-Shift-R (⌘-Shift-R uz Mac)
  • Internet Explorer / Edge: Pieturi Ctrl un klikšķini uz Pārlādēt vai nospied Ctrl-F5
  • Opera: Nospied Ctrl-F5.
/*
todo:
* klubi -> {{fk}}?
* wgTitle -> |name=
*/
var myContent = document.getElementsByName( 'wpTextbox1' )[0];

function replaceSelection( replace ) {
	var len = myContent.value.length;
	var start = myContent.selectionStart;
	var end = myContent.selectionEnd;
	var sel = myContent.value.substring( start, end );

	if ( typeof( replace ) == 'function' ) {
		replace = replace( sel );
	}

	myContent.value = myContent.value.substring( 0, start )
		+ replace
		+ myContent.value.substring( end, len );
}

function futbolsFix() {
	replaceSelection( function ( sel ) {
		sel = sel.replace( /\{\{Infobox [Ff]ootball [Bb]iography/g, '{{Futbolista infokaste' );
		sel = sel.replace( /\|(\s*)name(\s*)=(\s*)([^\n]*)/g, "|$1name$2=$3" + mw.config.get( 'wgTitle' ) + "\n|$1origname$2=$3''$4''" );
		sel = sel.replace( /(nationalteam-|club-|pc|nt)update(\s*)=(\s*)\d*:\d*, (\d*)\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s*(\d*) \(UTC\)/g, '$1update$2=$3{{dat|$6|--$5--|$4|SK|bez}}' );
		sel = sel.replace( /(nationalteam-|club-|pc|nt)update(\s*)=(\s*)(\d*)\s*(January|February|March|April|May|June|July|August|September|October|November|December)\s*(\d*)/g, '$1update$2=$3{{dat|$6|--$5--|$4|SK|bez}}' );
		sel = sel.replace( /--January--/g, '1' );
		sel = sel.replace( /--February--/g, '2' );
		sel = sel.replace( /--March--/g, '3' );
		sel = sel.replace( /--April--/g, '4' );
		sel = sel.replace( /--May--/g, '5' );
		sel = sel.replace( /--June--/g, '6' );
		sel = sel.replace( /--July--/g, '7' );
		sel = sel.replace( /--August--/g, '8' );
		sel = sel.replace( /--September--/g, '9' );
		sel = sel.replace( /--October--/g, '10' );
		sel = sel.replace( /--November--/g, '11' );
		sel = sel.replace( /--December--/g, '12' );
		sel = sel.replace( /clubs(\d*)(\s*)=(\s*)→/g, 'clubs$1$2=$3{{īre}}' );
		sel = sel.replace( / \(loan\)/g, '' );
		sel = sel.replace( /height(\s*)=(\s*)\{\{(height|convert)\|(m=)?(\d)\.?(\d*)[^\}]*\}\}/g, 'height$1=$2$5$6' );
		sel = sel.replace( /years(\d*)(\s*)=(\s*)(\d*)(\s*)[-–—](\s*)(\d*)/g, 'years$1$2=$3$4$5—$6$7' );
		sel = sel.replace( /years(\d*)(\s*)=(\s*)(\d*)(\s*)[-–—](\s*)([^\d\|])/g, 'years$1$2=$3$4$5—pašlaik$6$7' );
		sel = sel.replace( /\[\[Great Britain Olympic football team\|Great Britain\]\]/g, '{{fb|GBR}}' );
		sel = sel.replace( /nationalteam(\d*)(\s*)=(\s*)\[\[Czech Republic\snational under-(\d*) football team\|[^\]]+\]\]/g, 'nationalteam$1$2=$3{{fb|Čehija}} U-$4' );
		sel = sel.replace( /nationalteam(\d*)(\s*)=(\s*)\[\[Czech Republic\snational football team\|[^\]]+\]\]/g, 'nationalteam$1$2=$3{{fb|Čehija}}' );
		sel = sel.replace( /nationalteam(\d*)(\s*)=(\s*)\[\[[^\s]+\snational youth football team\|([^\s]+) U(\d*)\]\]/g, 'nationalteam$1$2=$3{{fb|$4}} U-$5' );
		sel = sel.replace( /nationalteam(\d*)(\s*)=(\s*)\[\[([^\s]+)\snational under-(\d*) football team\|[^\]]+\]\]/g, 'nationalteam$1$2=$3{{fb|$4}} U-$5' );
		sel = sel.replace( /nationalteam(\d*)(\s*)=(\s*)\[\[([^\s]+)\snational football team\|[^\]]+\]\]/g, 'nationalteam$1$2=$3{{fb|$4}}' );
		sel = sel.replace( /\[\[[Mm]idfielder#[Ww]inger\|[Ww]inger\]\]/g, 'malējais pussargs' );
		sel = sel.replace( /\[\[[Mm]idfielder#[Aa]ttacking [Mm]idfielder\|[Aa]ttacking [Mm]idfielder\]\]/g, 'uzbrūkošais pussargs' );
		sel = sel.replace( /\[\[[Mm]idfielder#[Cc]entral [Mm]idfielder\|[Cc]entral [Mm]idfielder\]\]/g, 'centrālais pussargs' );
		sel = sel.replace( /\[\[[Mm]idfielder(\|[Mm]idfielder)?\]\]/g, 'pussargs' );
		sel = sel.replace( /\[\[[Dd]efender \(association football\)\|[Dd]efender\]\]/g, 'aizsargs' );
		sel = sel.replace( /\[\[[Dd]efender \(association football\)\|[Cc]entre back\]\]/g, 'centra aizsargs' );
		sel = sel.replace( /\[\[[Gg]oalkeeper \(association football\)\|[Gg]oalkeeper\]\]/g, 'vārtsargs' );
		sel = sel.replace( /\[\[[Ff]orward \(association football\)\|[Ff]orward\]\]/g, 'uzbrucējs' );
		sel = sel.replace( /([^~]+)~futb/g, '[\[Kategorija:$1 futbolisti]]\n[\[Kategorija:$1 izlases futbolisti]]' );
		sel = sel.replace( /(\d\d\d\d)EK/g, '[\[Kategorija:$1. gada Eiropas čempionāta futbolā spēlētāji]]' );
		sel = sel.replace( /(\d\d\d\d)PK/g, '[\[Kategorija:$1. gada FIFA Pasaules kausa spēlētāji]]' );
		return sel;
	} );
}

function addUrlPortletLink() {
	var portletLink = mw.util.addPortletLink(
		'p-tb',
		'#',
		'futbols',
		't-futbolsfix'
	);
	$( portletLink ).click( function ( e ) {
		e.preventDefault();
		futbolsFix();
	});
}

if ( mw.config.get( 'wgNamespaceNumber' ) != -1 && myContent ) {
	jQuery( document ).ready( addUrlPortletLink );
}