Uživatel:Auvajs/AKU.js

Z Wikislovníku
Skočit na navigaci Skočit na vyhledávání

Poznámka: Po zveřejnění musíte vyprázdnit cache vašeho prohlížeče, jinak změny neuvidíte.

  • Firefox / Safari: Při kliknutí na Aktualizovat držte Shift nebo stiskněte Ctrl-F5 nebo Ctrl-R (na Macu ⌘-R)
  • Google Chrome: Stiskněte Ctrl-Shift-R (na Macu ⌘-Shift-R)
  • Internet Explorer / Edge: Při kliknutí na Aktualizovat držte Ctrl nebo stiskněte Ctrl-F5
  • Opera: Stiskněte Ctrl-F5.
/*global mediaWiki, jQuery */
/*jslint browser: true, plusplus: true, white: true */
/*jshint browser:true, laxbreak:false, plusplus:false, white:false, undef:true, unused:true */

( function ( mw, $ ) {
	
	'use strict';
	
	
	if ( /*mw.config.get( 'wgNamespaceNumber' ) || */ !/^(edit|submit)$/.test( mw.config.get( 'wgAction' ) ) ) {
		return;
	}
	
	
	$( document ).ready( function () {
		
		var replacements = [
			[
				/(^|\n)(==+)([^=]+)(\2) *(?=\n)/g,
				function ( $0, $1, $2, $3, $4 ) {
					return $1 + '\n' + $2 + ' ' + $.trim( $3 ) + ' ' + $4;
				}
			], [
				/\n\{\{\s*[Ss][Uu][Bb][Ss][Tt]\s*:\s*Vzor /g,
				'\n\n{{subst:Vzor '
			], [
				/\n([#\*]+)([^\n]*)/g,
				function ( $0, $1, $2 ) {
					return '\n' + $1 + ' ' + $.trim( $2 );
				}
			], [
				/# [-–] */g,
				'# —'
			], [
				/# \{\{Překlady *\}\}/g,
				'# {{Překlady\n}}'
			], [
				/\[\[ *Kategorie *:([^\]]+)\]\]/gi,
				function ( $0, $1 ) {
					return '\n[[Kategorie:' + $.trim( $1 ) + ']]\n';
				}
			], [
				/(\[\[Kategorie:[^\]]+\]\])\n+(?!\[\[[a-z])/g,
				'$1\n'
			], [
				/\n+ *\|([^=\n]+)=(?![^\n\|]*\|\|[^\n]*\n)([^\n]*)(?=\n)/g,
				function ( $0, $1, $2 ) {
					return '\n  | ' + $.trim( $1 ) + ' = ' + $.trim( $2 );
				}
			], [
				/([^=]) +\n/g,
				'$1\n'
			], [
				/([^\n]) +/g,
				'$1 '
			], [
				/\n{3,}/g,
				'\n\n'
			], [
				/=== starší varianta zápisu ===/g,
				'=== varianty ==='
			], [
				/=== novější varianta zápisu ===/g,
				'=== varianty ==='
			], [
				/=== varianta zápisu ===/g,
				'=== varianty ==='
			], [
				/(snom|sgen|sdat|sacc|svoc|sloc|sins|pnom|pgen|pdat|pacc|pvoc|ploc|pins|spre1|spre2|spre3|ppre1|ppre2|ppre3|sfut1|sfut2|sfut3|pfut1|pfut2|pfut3|simp2|pimp1|pimp2|sactm|sactf|sactn|pactm|pactf|actn|ptram|ptraf|ptrap|mtram|mtraf|mtrap|spasm|spasf|spasn|ppasm|ppasf|ppasn|snomma|snomm|snomf|snomn|pnomma|pnomm|pnomf|pnomn|sgenma|sgenm|sgenf|sgenn|pgenma|pgenm|pgenf|pgenn|sdatma|sdatm|sdatf|sdatn|pdatma|pdatm|pdatf|pdatn|saccma|saccm|saccf|saccn|paccma|paccm|paccf|paccn|slocma|slocm|slocf|slocn|plocma|plocm|plocf|plocn|sinsma|sinsm|sinsf|sinsn|pinsma|pinsm|pinsf|pinsn|snomma-jm|snomm-jm|snomf-jm|snomn-jm|pnomma-jm|pnomm-jm|pnomf-jm|pnomn-jm|saccma-jm|saccm-jm|saccf-jm|saccn-jm|paccma-jm|paccm-jm|paccf-jm|paccn-jm) *= *((({{Příznak2\|[^}]*}} *)?[^[\]{}\/\n]+)( *\/ *({{Příznak2\|[^}]*}} *)?[^[\]{}\/\n]+)*)$/gm,
				function ($0,$1,$2) {
					var pageName = mw.config.get( 'wgPageName' );
					var innerRe = /({{Příznak2\|[^}]*}})? *([^[\]{}\/\n]+)( \/ |$)/gm;
					var text = $1 + " = " + $2.replace( innerRe, function($0,$1,$2,$3) {
						if ($2 === pageName) return $1 ? $1 + " " + $2 : $2;
						var result = $1 ? $1 + " [[" + $2 + "]]" : "[[" + $2 + "]]";
						if ($3) result += " / ";
						return result;
					});
					return text;
				}
			], 
		];

		var $button = $('<button>');
		$button.text('AKÚ');
		$('#wpDiff').after($button);
		$button.click( function () {
			
			$( '#wpTextbox1' ).val( function ( index, oldPageText ) {
				
				var newPageText = oldPageText;
				
				$.each( replacements, function ( index, replacement ) {
					newPageText = newPageText.replace( replacement[0], replacement[1] );
				});
				
				newPageText = $.trim( newPageText ) + '\n';
				
				if ( newPageText !== oldPageText ) {
					$( '#wpSummary' ).val( function ( index, summary ) {
						var summarySeparator = '';
						summary = $.trim( summary );
						if ( summary !== '' ) {
							summarySeparator = /^\/\*.*\*\/$/.test( summary ) ? ' ' : '; ';
						}
						return summary + summarySeparator + '[[WS:AKÚ|AKÚ]]+';
					});
				}
				
				return newPageText;
				
			});
			
			return false;
			
		});
		
	});
	
}( mediaWiki, jQuery ) );