Dalībnieks:Edgars2007/swimming.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.
var myContent = document.getElementsByName( 'wpTextbox1' )[0];

function replaceSelection( replace ) {
	// Replace currently selected text with the replace variable. The replace
	// variable can be a string or a callback function. The callback function
	// takes the selection text as its first and only argument, and must return
	// the string to replace the selection with.
	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 padDigits( number ) {
  return ( number.length < 2 ? "0" : "" ) + number;
}

dictionary={ 
	"Athènes":"Atēnas",
	"Pékin":"Pekina",
	"Londres":"Londona",
	"Montréal":"Monreāla",
	"Melbourne":"Melburna",
	"Rome":"Roma",
	"Shanghai":"Šanhaja",
	"Barcelone":"Barselona",
	"Kazan":"Kazaņa",
	"Indianapolis":"Indianapolisa",
	"Manchester":"Mančestra",
	"Dubaï":"Dubaija",
	"Istanbul":"Stambula",
	"Doha":"Doha"
};

function swimFix() {
	replaceSelection( function ( sel ) {
		sel = sel.replace( /\t/g, ' ' );
		sel = sel.replace( /<ref>.*?<\/ref>/g, '' );
		//1 min 53 s 94 -> 1:57,00
		sel = sel.replace( /(\d+)\s*min\s*(\d+)\s*s\s*(\d+)/g, function( match, group1, group2, group3 ) {

			var string = group1+":"+padDigits( group2 )+","+padDigits( group3 );
			  return string;
			} );
		//53 s 50
		sel = sel.replace( /(\d+)\s*s\s*(\d+)/g, function( match, group1, group2 ) {

			var string = padDigits( group1 )+","+padDigits( group2 );
			  return string;
			} );
		//[[Natation aux Jeux olympiques d'été de 2004|Athènes 2004]]
		sel = sel.replace( /\[\[Natation aux Jeux olympiques d'été de ([^\|]+)\|([^\d]+)(\d+)\]\]/g, '{{oss|V=$3}}' );//dictionary[$2]
		//[[Championnats du monde de natation 2005|Montréal 2005]]
		sel = sel.replace( /\[\[([^\|]+)\|([^\d]+)(\d+)\]\]/g, '$3' );
		//+pilsētas apstrādāt
		//{{GRE-d}}
		sel = sel.replace( /\{\{(\w{3})-d\}\}/g, '{{flaga|$1}}' );
		//Pas.rek.
		sel = sel.replace( /\[\[Record du monde ([^\|]+)\|([^\]]+)\]\]/g, '{{icon|wr}}' );
		sel = sel.replace( / – '''\{\{icon\|wr\}\}'''/g, " '''{{icon|wr}}'''" );
		//Rek.
		sel = sel.replace( /\[\[Record ([^\|]+)\|([^\]]+)\]\]/g, '' );
		sel = sel.replace( / – '''RC'''/g, '' );
		sel = sel.replace( / RC/g, '' );

		sel = sel.replace( /(===?) *Palmarès *(===?)/g, '$1 Sasniegumi $2' );
		sel = sel.replace( /(===?) *Championnats du monde *(===?)/g, '$1 Pasaules čempionāts $2' );
		sel = sel.replace( /(===?) *Jeux olympiques *(===?)/g, '$1 Olimpiskās spēles $2' );

		sel = sel.replace( /'''Or'''/g, "'''Zelts'''" );
		sel = sel.replace( /'''Argent'''/g, "'''Sudrabs'''" );
		sel = sel.replace( /'''Bronze'''/g, "'''Bronza'''" );
		sel = sel.replace( /'''Édition'''/g, "'''Olimpiskās spēles'''" );
		sel = sel.replace( /'''Épreuve'''/g, "'''Distance'''" );
		sel = sel.replace( /'''Épreuve \/ Édition'''/g, "'''Distance / gads'''" );
		sel = sel.replace( /'''\[\[Championnats du monde de natation\|\{\{Blanc\|Grand bassin\}\}\]\]'''/g, "'''[[Pasaules čempionāts ūdens sporta veidos|<span style=\"color:white;\">Garais baseins</span>]]'''" );
		sel = sel.replace( /'''\[\[Championnats du monde de natation en petit bassin\|\{\{Blanc\|Petit bassin\}\}\]\]'''/g, "'''[[Pasaules čempionāts peldēšanā īsajā baseinā|<span style=\"color:white;\">Īsais baseins</span>]]'''" );
		
		sel = sel.replace( /{{(\d+)e}}/g, '$1. vieta' );
		sel = sel.replace( /(\d+){{e}}/g, '$1. vieta' );
		
		sel = sel.replace( /m\}?\}?\s*nage libre/g, 'm brīvajā stilā' );
		sel = sel.replace( /m\}?\}?\s*dos/g, 'm uz muguras' );
		sel = sel.replace( /m\}?\}?\s*(quatre|4) nages/g, 'm kompleksajā stilā' );
		sel = sel.replace( /m\}?\}?\s*papillon/g, 'm tauriņstils' );
		sel = sel.replace( /m\}?\}?\s*brasse/g, 'm brass' );
		return sel;
	} );
}

function addUrlPortletLink() {
	var portletLink = mw.util.addPortletLink(
		'p-tb',
		'#',
		'Peldēšana',
		't-swimfix'
	);
	$( portletLink ).click( function ( e ) {
		e.preventDefault();
		swimFix();
	});
}

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