User:So9q/TranslationAdder-InputFiller.js

function processor(object) { //console.log("processor fired"); //console.log($(object).text); // only fire in translation-cell if ($(object).parent.parent.parent.prop("tagName") == "TD" ||	// needed for nested ones like bokmål	$(object).parent.parent.parent.parent.parent.prop("tagName") == "TD") { // extract data from the entry var lang = $(object).attr("lang"); // find the next sibling that has a gender. var gender = $(object).nextUntil("span.Latn").filter(".gender").last.text; // object only supports qualifiers that come after the term var qualifier = $(object).nextUntil("span.Latn").filter(".qualifier-content").text; var literal = $(object).nextUntil("span.Latn").filter(".mention-gloss").text;

// find input objects for TranslationAdder var common = $(object).parentsUntil("table").find("form").find("[name=c]"); var cpl = $(object).parentsUntil("table").find("form").find("[name=c-p]"); var neuter = $(object).parentsUntil("table").find("form").find("[name=n]"); var npl = $(object).parentsUntil("table").find("form").find("[name=n-p]"); var qual = $(object).parentsUntil("table").find("form").find("[name=qual]"); var lit = $(object).parentsUntil("table").find("form").find("[name=lit]"); var word = $(object).parentsUntil("table").find("form").find("[name=word]");

// insert the data switch (lang) { case "de": word.val($(object).text.toLowerCase); break; case ("nb" || "no"): var str = $(object).text; str = str.replace(/gj/gi, "g"); str = str.replace(/ggi/gi, "gni"); str = str.replace(/(.*)sj/gi, "$1si"); str = str.replace(/skj/gi, "sk"); str = str.replace(/kj/gi, "k"); str = str.replace(/farg/gi, "farv"); str = str.replace(/eil/gi, "ejl"); str = str.replace(/ei(.*)/gi, "ej$1"); str = str.replace(/ff$/gi, "f"); str = str.replace(/kk$/gi, "k"); str = str.replace(/ll$/gi, "l"); str = str.replace(/rt$/gi, "ret"); str = str.replace(/ss$/gi, "s"); str = str.replace(/tt$/gi, "t"); str = str.replace(/het$/gi, "hed"); str = str.replace(/rsk$/gi, "risk"); str = str.replace(/^uut/gi, "uud"); str = str.replace(/^uopp/gi, "uop"); str = str.replace(/^opp/gi, "op"); word.val(str); break; case "sv": var str = $(object).text; str = str.replace(/Ö/g, "Ø"); str = str.replace(/Ä/g, "Æ"); str = str.replace(/ö/g, "ø"); str = str.replace(/ä/g, "æ"); str = str.replace(/a$/gi, "e"); str = str.replace(/ck$/gi, "k"); str = str.replace(/ll$/gi, "l"); str = str.replace(/rn$/gi, "ren"); word.val(str); break; default: word.val($(object).text); }		qual.val(qualifier); lit.val(literal); // Fill in gender only for a subset of the languages if (lang == "da" || lang == "de" || lang == "fr"			|| lang == "nb" || lang == "nl"			|| lang == "no" || lang == "sv") { if (gender == "c" || gender == "m" || gender == "f"				// Support nb double genders				|| gender == "m or f" || gender == "m or n") { common.prop('checked', true); neuter.prop('checked', false); npl.prop('checked', false); cpl.prop('checked', false); }			if (gender == "n") { common.prop('checked', false); neuter.prop('checked', true); npl.prop('checked', false); cpl.prop('checked', false); }			// Note, these have invisible nbsp; in them if (gender == "c pl"				// support erroneous plural also				|| gender == "pl") { common.prop('checked', false); neuter.prop('checked', false); cpl.prop('checked', true); npl.prop('checked', false); }			if (gender == "n pl") { common.prop('checked', false); neuter.prop('checked', false); npl.prop('checked', true); cpl.prop('checked', false); }		}		var log = "Fired ".concat(lang," Gender: ",gender); console.info(log); word.focus; } } function customize { if (typeof window.CustomInputFillerLanguages == 'undefined') { // CustomInputFillerLanguages is not defined, set to defaults window.CustomInputFillerLanguages = "[lang=da], [lang=de], [lang=fo], [lang=fr], [lang=nb], [lang=nn], [lang=nl], [lang=no], [lang=sv]"; } }

function helper { // enable customization customize; // setup timer var timer; var delay = 750; // ms	//console.log("helper fired") $(CustomInputFillerLanguages).not(".interlanguage-link-target") .hover(				// pass 2 functions to hover				function {					window.$thiz = $(this);					// on mouse in, start a timeout					timer = setTimeout(function { // do your stuff here processor(window.$thiz); }, delay);				}, function {					// on mouse out, cancel the timer					clearTimeout(timer);				}); } //close helper // main $(document).ready(helper);