Wikipedysta:Malarz pl/wp sk.js

Z Wikipedii, wolnej encyklopedii

Uwaga: aby zobaczyć zmiany po opublikowaniu, może zajść potrzeba wyczyszczenia pamięci podręcznej przeglądarki.

  • Firefox / Safari: Przytrzymaj Shift podczas klikania Odśwież bieżącą stronę, lub naciśnij klawisze Ctrl+F5, lub Ctrl+R (⌘-R na komputerze Mac)
  • Google Chrome: Naciśnij Ctrl-Shift-R (⌘-Shift-R na komputerze Mac)
  • Internet Explorer / Edge: Przytrzymaj Ctrl, jednocześnie klikając Odśwież, lub naciśnij klawisze Ctrl+F5
  • Opera: Naciśnij klawisze Ctrl+F5.
// <nowiki>
mw.hook('userjs.wp_sk.ready').add(function (wp_sk)
{
		//console.log( "Attaching to WP:SK" );
		// własne [[WP:SK]]
		wp_sk.pre_malarz_cleaner = wp_sk.cleaner;
		wp_sk.extension += "+[[WP:SK/mSK|mSK]]";

		wp_sk.cleaner = function( str ) {
			// linki zewnętrzne do wiki na [[linki]]
			str = str.replace( /\[https?:\/\/pl\.wikipedia\.org\/wiki\/([^\[\] ]+) ([^\[\]]+)\]/g, '[[$1|$2]]' );

			//rozpoczęte <b><i> w pustych parametrach szablonów
			str = str.replace( /([^=]=\s*)''+(\s*(\||\}\}))/g, '$1$2' );

			//czyścimy ISBN'y dla [[Specjalna:Książki]]
			str = str.replace( /ISBN-1(0|3):* */g, 'ISBN ' );

			//dekodowanie niektórych sekwencji specjalnych HTML
			str = str.replace( /&auml;/g, 'ä' );
			str = str.replace( /&ouml;/g, 'ö' );
			str = str.replace( /&uuml;/g, 'ü' );
			str = str.replace( /&Auml;/g, 'Ä' );
			str = str.replace( /&Ouml;/g, 'Ö' );
			str = str.replace( /&Uuml;/g, 'Ü' );
			str = str.replace( /&szlig;/g, 'ß' );

			str = str.replace( /&Aring;/g, 'Å' );
			str = str.replace( /&aring;/g, 'å' );

			str = str.replace( /&aelig;/g, 'æ' );
			str = str.replace( /&ccedil;/g, 'ç' );
			str = str.replace( /&ntilde;/g, 'ñ' );
			str = str.replace( /&acirc;/g, 'â' );
			str = str.replace( /&aacute;/g, 'á' );
			str = str.replace( /&agrave;/g, 'à' );
			str = str.replace( /&AElig;/g, 'Æ' );
			str = str.replace( /&Ccedil;/g, 'Ç' );
			str = str.replace( /&Ntilde;/g, 'Ñ' );
			str = str.replace( /&Acirc;/g, 'Â' );
			str = str.replace( /&Aacute;/g, 'Á' );
			str = str.replace( /&Agrave;/g, 'À' );

			str = str.replace( /&hellip;/g, '…' );
			str = str.replace( /&quot;/g, '"' );
			str = str.replace( /&minus;/g, '−' );
			str = str.replace( /&oline;/g, '‾' );
			str = str.replace( /&cent;/g, '¢' );
			str = str.replace( /&pound;/g, '£' );
			str = str.replace( /&euro;/g, '€' );
			str = str.replace( /&sect;/g, '§' );
			str = str.replace( /&dagger;/g, '†' );

			str = str.replace( /&lsquo;/g, '‘' );
			str = str.replace( /&rsquo;/g, '’' );
			str = str.replace( /&middot;/g, '·' );
			str = str.replace( /&bull;/g, '•' );
			str = str.replace( /&times;/g, '×' );
			str = str.replace( /&copy;/g, '©' );
			str = str.replace( /&reg;/g, '®' );
			str = str.replace( /&trade;/g, '™' );
			str = str.replace( /&iquest;/g, '¿' );
			str = str.replace( /&iexcl;/g, '¡' );

			str = str.replace( /&darr;/g, '↓' );
			str = str.replace( /&uarr;/g, '↑' );
			str = str.replace( /&crarr;/g, '↵' );
			str = str.replace( /&rarr;/g, '→' );
			str = str.replace( /&larr;/g, '←' );
			str = str.replace( /&harr;/g, '↔' );
			str = str.replace( /&dArr;/g, '⇓' );
			str = str.replace( /&uArr;/g, '⇑' );
			str = str.replace( /&rArr;/g, '⇒' );
			str = str.replace( /&lArr;/g, '⇐' );
			str = str.replace( /&hArr;/g, '⇔' );

			str = str.replace( /&mdash;/g, '—' );
			str = str.replace( /&ndash;/g, '–' );

			str = str.replace( /&isin;/g, '∈' );
			str = str.replace( /&notin;/g, '∉' );
			str = str.replace( /&empty;/g, '∅' );
			str = str.replace( /&sub;/g, '⊂' );
			str = str.replace( /&sube;/g, '⊆' );
			str = str.replace( /&nsub;/g, '⊄' );

			str = str.replace( /&Lambda;/g, 'Λ' );
			str = str.replace( /&not;/g, '¬' );
			str = str.replace( /&sim;/g, '∼' );

			str = str.replace( /&alpha;/g, 'α' );
			str = str.replace( /&beta;/g, 'β' );
			str = str.replace( /&gamma;/g, 'γ' );
			str = str.replace( /&delta;/g, 'δ' );
			str = str.replace( /&epsilon;/g, 'ε' );
			str = str.replace( /&zeta;/g, 'ζ' );
			str = str.replace( /&eta;/g, 'η' );
			str = str.replace( /&theta;/g, 'θ' );
			str = str.replace( /&iota;/g, 'ι' );
			str = str.replace( /&kappa;/g, 'κ' );
			str = str.replace( /&lambda;/g, 'λ' );
			str = str.replace( /&mu;/g, 'μ' );
			str = str.replace( /&nu;/g, 'ν' );
			str = str.replace( /&xi;/g, 'ξ' );
			str = str.replace( /&omicron;/g, 'ο' );
			str = str.replace( /&pi;/g, 'π' );
			str = str.replace( /&rho;/g, 'ρ' );
			str = str.replace( /&sigma;/g, 'σ' );
			str = str.replace( /&tau;/g, 'τ' );
			str = str.replace( /&upsilon;/g, 'υ' );
			str = str.replace( /&phi;/g, 'φ' );
			str = str.replace( /&chi;/g, 'χ' );
			str = str.replace( /&psi;/g, 'ψ' );
			str = str.replace( /&omega;/g, 'ω' );

			str = str.replace( /&Alpha;/g, 'Α' );
			str = str.replace( /&Beta;/g, 'Β' );
			str = str.replace( /&Gamma;/g, 'Γ' );
			str = str.replace( /&Delta;/g, 'Δ' );
			str = str.replace( /&Epsilon;/g, 'Ε' );
			str = str.replace( /&Zeta;/g, 'Ζ' );
			str = str.replace( /&Eta;/g, 'Η' );
			str = str.replace( /&Theta;/g, 'Θ' );
			str = str.replace( /&Iota;/g, 'Ι' );
			str = str.replace( /&Kappa;/g, 'Κ' );
			str = str.replace( /&Lambda;/g, 'Λ' );
			str = str.replace( /&Mu;/g, 'Μ' );
			str = str.replace( /&Nu;/g, 'Ν' );
			str = str.replace( /&Xi;/g, 'Ξ' );
			str = str.replace( /&Omicron;/g, 'Ο' );
			str = str.replace( /&Pi;/g, 'Π' );
			str = str.replace( /&Rho;/g, 'Ρ' );
			str = str.replace( /&Sigma;/g, 'Σ' );
			str = str.replace( /&Tau;/g, 'Τ' );
			str = str.replace( /&Upsilon;/g, 'Υ' );
			str = str.replace( /&Phi;/g, 'Φ' );
			str = str.replace( /&Chi;/g, 'Χ' );
			str = str.replace( /&Psi;/g, 'Ψ' );
			str = str.replace( /&Omega;/g, 'Ω' );

			// + wolne linie przed nagłówkami
			str = str.replace( /\n=/g, '\n\n=' );

			// dekodowanie nazw szablonów
			str = str.replace( /\{\{([^\|\}]*)(\||\}\})/g, wp_sk.mm_rTempldecode );

			// usuwam spacje na końcach linii
			str = str.replace( /[ \t]*\n/g, '\n' );

			// unifikacja nagłówka
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n'''? *Bibliografia:* *'''?[ \n\t]*/gi, '$1\n\n== Bibliografia ==\n' );
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n(=+) *Bibliografia:* *=+[ \n\t]*/gi, '$1\n\n$2 Bibliografia $2\n' );
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n'''? *Referencje:* *'''?[ \n\t]*/gi, '$1\n\n== Przypisy ==\n' );
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n(=+) *Referencje:* *=+[ \n\t]*/gi, '$1\n\n$2 Przypisy $2\n' );
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n'''? *Piśmiennictwo:* *'''?[ \n\t]*/gi, '$1\n\n== Przypisy ==\n' );
			str = str.replace( /([^ \n\t\}])[ \n\t]*\n(=+) *Piśmiennictwo:* *=+[ \n\t]*/gi, '$1\n\n$2 Przypisy $2\n' );

			// niepotrzebna kropka kropka z liczebników w datach
			str = str.replace( /([0-9])\. *(stycznia|lutego|marca|kwietnia|maja|czerwca|lipca|sierpnia|września|października|listopada|grudnia)/g, '$1 $2' )
			// ale u [[hr: w listopadzie potrzebna
			str = str.replace( /\[\[ *hr *: *([0-9]{1,2}) listopada/g, '[[hr:$1. listopada' )

			// oryginalny cleaner
			str = wp_sk.pre_malarz_cleaner( str );

			// usuwam entery, spacje i tabulatory po infoboksie
			str = str.replace( /\{\{([^|}]+[ _]infobo[^|}]+)((?:[^{}]|[^{}][{}][^{}]|\{\{(?:[^{}]|[^{}][{}][^{}]|\{\{[^{}]+\}\})+\}\})+)}\}[\n\t ]*/g, '{{$1$2}}\n' );
			// i usuwam entery na końcu (jeżeli są np. dodane przez powyższy)
			str = str.replace( /[\n\t ]*$/g, '' );

			// usuwam entery na początku artykułu
			str = str.replace( /^\n*/, '' );

			// usuwam BR'y na końcach list i akapitów
			str = str.replace( /( *<\/?br ?\/?>)* *\n(\*|\#|\n|\:)/ig, '\n$2' );

			// usuwam spacje przy BR'ach
			str = str.replace( / *<\/?br ?\/?> */ig, '<br />' );

			// czyszczę przypisy z cytuj cośtam
			str = str.replace(/== *\n\s*\n*\{\{[Cc]ytuj/g, '==\n\* \{\{Cytuj');
			str = str.replace(/\n?(\{\{([Cc]ytuj[^|}]+)((?:[^{}]|[^{}][{}][^{}]|\{\{(?:[^{}]|[^{}][{}][^{}]|\{\{[^{}]+\}\})+\}\})+)\}\})/g, wp_sk.mm_rFriendlyCytuj);
			str = str.replace(/\n+<\/ref>/g, '</ref>');

			return str;
		};
		wp_sk.mm_rTempldecode = function( a, name, end ) {
			try {
				name = decodeURIComponent( name )
				a = '{{' + name + end;
			} catch ( err ) {}

			return a.replace( /_/g, ' ' );
		};
		wp_sk.mm_rFriendlyCytuj = function( a ) {
			return a.replace( /\s+/g, ' ' );
		};
});
// </nowiki>