Benutzer:Prog/EditExtensionFunctions.js

Aus Wikibooks

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
// <nowiki>

function fixWhitespaces(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	text = text.replace(/[ \t]+\n/g, '\n');
	text = text.replace(/\n+[ \t]*(=+)[ \t]*(([^= \t\n]|[ \t]+[^ \t\n=])+)[ \t]*(=+)\n+/g, '\n\n$1 $2 $1\n\n');
	wpTextbox.val(text);
}

function deleteDoubleNewline(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	text = text.replace(/\n\n+/g, '\n\n');
	wpTextbox.val(text);
}

function deleteText(text){
	var wpTextbox = $('#wpTextbox1');
	wpTextbox.val(wpTextbox.val().replace(new RegExp(maskRegex(text), 'g'), ''));
}

function resortMetadata(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	var regex = new RegExp('([\\[][\\[]' + wgFormattedNamespaces[14] + ':[^\\]]+[\\]][\\]])', 'g');
	var matches = text.match(regex);
	var append = '';
	if(matches){
		text = text.replace(regex, '');
		append = '<noinclude>\n' + matches.join('\n') + '\n';
	}
	regex = /([\[][\[](af|als|ang|ar|ast|az|be|bg|bn|bs|ca|co|cs|cv|cy|da|de|el|en|eo|es|et|eu|fa|fi|fr|fy|gl|he|hi|hr|hu|hy|ia|id|ie|is|it|ja|ka|kk|km|ko|ku|ky|la|li|lt|mg|mk|ml|mr|ms|ne|nl|no|oc|pa|pl|pt|ro|ru|sa|si|sk|sl|sq|sr|su|sv|ta|te|tg|th|tk|tl|tr|tt|uk|ur|uz|vi|vo|zh|zh-min-nan):[^\]]+[\]][\]])/g;
	matches = text.match(regex);
	if(matches){
		text = text.replace(regex, '');
		if(append == '') append += '<noinclude>';
		append += '\n' + matches.join('\n') + '\n';
	}
	if(append == '') return;
	append += '</noinclude>';
	text = text.replace(/([ \t\n]*|<noinclude>[\n \t]*<\/noinclude>)*$/g, '');
	wpTextbox.val(text + '\n\n' + append);
}

function fixLists(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	text = text.replace(/\n+([\*#:]+)[ \t]*([^\n]+)/g, '\n$1 $2');
	wpTextbox.val(text);
}

function extendHeadlines(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	text = text.replace(/^[ \t]*(=+)[ \t]*(([^= \t\n]|[ \t]+[^ \t\n=])+)[ \t]*(=+)$/gm, '$1= $2 $1=');
	wpTextbox.val(text);
}

function deleteEmptyElements(){
	var wpTextbox = $('#wpTextbox1');
	var text = wpTextbox.val();
	text = text.replace(/<[ \t]*[_a-zA-Z][_a-zA-Z0-9]*[ \t]*>[ \t\n]*<[ \t]*\/[ \t]*[_a-zA-Z][_a-zA-Z0-9]*[ \t]*>/g, '');
	wpTextbox.val(text);
}

// </nowiki>