User:Dixtosa/minorEdits.js

// Description is at: User:Dixtosa/minorEdit // see the description to see what this script assumes //

importScript("User:Dixtosa/XMLize.js");

function doGeorgian(wikitext) {	//START of FUNCTIONS function removeHead(wikitext) { wikitext = wikitext.replace(/head\|ka\|noun([^ ])/, "ka-noun$1"); wikitext = wikitext.replace(/head\|ka\|adverb([^ ])/, "ka-adv$1"); wikitext = wikitext.replace(/head\|ka\|adjective([^ ])/, "ka-adj$1"); wikitext = wikitext.replace(/head\|ka\|proper[ _]noun([^ ])/, "ka-proper noun$1"); return wikitext; }	function addPronunciation(wikitext) {		var exceptionList = ["ალო"]; if ($.inArray(mw.config.values.wgTitle, exceptionList) >= 0) return wikitext; var wikixml = WikiXml.parseWikitext(wikitext); if (wikixml === undefined) return wikitext; //maybe XMLize can handle this itself if (wikixml.find(".Georgian .Pronunciation").find("data").text.indexOf("audio") != -1) return wikitext; wikixml.find(".Georgian .Pronunciation").remove; var first_h3 = wikixml.find (".Georgian > section").first; if (first_h3.attr("class") == "Alternative forms") first_h3 = first_h3.next; if (first_h3.attr("class") == "Etymology") first_h3 = first_h3.next; var hyphen = "\n* "; if ((mw.config.values.wgTitle.match(/[აეიოუ]/g) || "").length <= 1) hyphen = ""; first_h3.before(" "); return WikiXml.toWikitext(wikixml); }	function fixDeclension(wikitext) {		//remove erroneously added declension tables wikitext = wikitext.replace (/====[ ]?Declension[ ]?====\n\n/, ""); wikitext = wikitext.replace (/====[ ]?Declension[ ]?====\n\n/, "");

wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace(//, ""); wikitext = wikitext.replace("Declension", "Inflection"); return wikitext; }	//END of FUNCTIONS wikitext = fixDeclension(wikitext); var regexReplace = { "" :  ""	};	var templateNames = ["ka-noun", "ka-adj", "ka-pron", "ka-adv", "ka-proper noun", "ka-verbal noun", "head\\|ka\\|noun form"]; ["ka", "hy", "xcl"].forEach(function(lang, ind, arr) {		templateNames.push("l\\|" + lang);		templateNames.push("m\\|" + lang);	}); templateNames.forEach(function(element, index, array){		var regex="(" + element + "[^\\}]*?)\\|tr\\=.+?(\\||\\}\\})(.*?)";		regexReplace[regex] = "$1$2$3";	});

wikitext = removeHead(wikitext); //replaces redundant transliterations in headword and l. also corrects IPA. for (var element in regexReplace){ var re = new RegExp(element, "g"); wikitext = wikitext.replace(re, regexReplace[element]); }	wikitext = addPronunciation(wikitext); return wikitext; //document.editform.submit; }

function doForAll(wikitext) {	function brackets_2_l(wikitext) {		//var lang2code = {'Georgian' : 'ka', 'Russian' : 'ru', 'Armenian' : 'hy'}; var possibleHeaders = ["Alternative forms", "Synonyms", "Antonyms", "Derived terms", "Related terms", "See also", "Hypernyms"]; var wikixml = WikiXml.parseWikitext(wikitext, {"wrapTemplate": true}); if (wikixml === undefined) return wikitext; var data = wikixml.find("notemplate"); data.each( function {			var elem = $(this);			if ($.inArray(elem.closest("section").attr("class"), possibleHeaders) == -1) return;			var datatext = elem.text;			var language = elem.closest('[level="2"]').attr("class");			if (language == "English") return;			var langcode = 'getByName';			datatext = datatext.replace(/\[\[([^:]*?)\]\]/g, function(whole, captured, line) { var ans = '") == -1) return ans + captured + '';				captured = captured.split("|");				var showWord = captured[1];				var linkWord = captured[0];				if (linkWord.indexOf("#") != -1)				{					var lineLanguage = linkWord.split("#")[1];					linkWord = linkWord.split("#")[0];					if (lineLanguage != language) return whole;				}				return ans + linkWord + '|' + showWord + '}}';			});

elem.text(datatext); });		return WikiXml.toWikitext(wikixml);	}	return brackets_2_l(wikitext); }

function clean(wikitext) {	wikitext = doForAll(wikitext); if (new RegExp("[ა-ჰ ]").test(mw.config.values.wgPageName)) wikitext = doGeorgian(wikitext);//need to change to also understand svan and others using XMLize return wikitext; } function cleanup {	var wikitext = $("#wpTextbox1").val; $("#wpTextbox1").val(clean(wikitext)); }

function initMinorEdit { $ ("#wpDiffWidget") .after ($(" ")		.html("")); }

if (	(mw.config.values.wgAction == "edit" || mw.config.values.wgAction == "submit") &&	(mw.config.values.wgPageName == "User:Dixtosa/minorEdits/test" || mw.config.values.wgNamespaceNumber === 0)	) {	$(document).ready(initMinorEdit); }

//