User:Dixtosa/nymReferer.js

// Description        : adds several parameters to redlinks so that after clicking it //                       wikitext will be automatically filled with some initial data // Dependency         : None // UserConfig         : None // Problems/to-do     : the assumptions written below //                      UserConfig for creationrules? //                      get definition for synonyms // 						 use modules for rules?

// types of greenifying: translation, from synonym, from antonym, alternative form, // (?) related terms, etymology

//

var basicPartsOfSpeech = ["Noun", "Proper noun", "Phrase", "Adjective", "Adverb", "Verb", "Verbal noun"] .map((pos) => pos.toLowerCase + "s"); //Georgian nouns

function pasteIfReferred{ let word = mw.util.getParamValue("from"); if (word === null) return true; //sanity check let header = mw.util.getParamValue("heading"); let langname = mw.util.getParamValue("langname"); let langcode = mw.util.getParamValue("langcode"); let partOfSpeech = mw.util.getParamValue("partOfSpeech") || "PARTOFSPEECH"; let gloss = mw.util.getParamValue("gloss");

let entry = `\

${partOfSpeech}
if (header == "Translations") {		entry += "" + word + ""; if (gloss) entry += " " + gloss + ""; }	else if (header == "Alternative forms") { entry += ``; }	else if (header == "Synonyms") { entry += ``; }	else { entry += "\n\n====" + header + "===="; entry += `\n* `; }	$("#wpTextbox1").val(entry); return false; }

nymConfig = window.nymConfig || { carelangs: ["ka"] };

$( function {	if (pasteIfReferred && mw.config.values.wgAction == "view" && !mw.config.values.wgCanonicalSpecialPageName)	{		//it is assumed that nchor is in between 		$("a.new")		.filter(function{ return nymConfig.carelangs.includes($(this).parent.attr("lang"));})		.each(function{ elem = $(this); let header = elem.parentsUntil("#mw-content-text").last.prevUntil(":header").addBack.prev.filter(":header");// filter is due to andSelf if (header.length === 0) //a.new's that are without header (e.g. ) return ; //should not happen let parentOfHeader = "h" + (header.prop("tagName")[1] - 1); let headingTitle = header.children.first.text; let partOfSpeech = null; let langname = header.prevUntil("h2").last.prev.children.first.text; let langcode = elem.parent.attr("lang"); let nymData = {}; if (!["Alternative forms", "Synonyms", "Antonyms", "Translations"].includes(headingTitle)) return ; if (["Synonyms", "Antonyms", "Translations"].includes(headingTitle)) {				partOfSpeech = header.prevUntil(parentOfHeader).last.prev.children.first.text; }			if (headingTitle == "Translations") {				var nf = elem.closest(".NavFrame").children.first.clone; nf.find("span").remove; nymData.gloss = nf.text; //.slice(1, -3); try { langname = elem.closest("li").contents[0].wholeText.slice(0, -2);//trim ': ' }				catch(e) { langname = "getByCode"; }			}			if (headingTitle == "Alternative forms") {				let poses = []; $("#mw-normal-catlinks ul li a").each(function{					let catname = $(this).text;					if (catname.startsWith(langname))					{						let pos = catname.slice(langname.length + 1);						if (basicPartsOfSpeech.includes(pos)) 						{							let [first, ...rest] = pos.slice(0, -1);							poses.push(first.toUpperCase + rest.join(""));						}					}				}); partOfSpeech = poses[0]; }			nymData.from = mw.config.values.wgTitle; nymData.heading = headingTitle; nymData.langname = langname; nymData.partOfSpeech = partOfSpeech; nymData.langcode = langcode; elem.attr("href", elem.attr("href") + "&" + $.param(nymData)).css("color", "rgb(34, 204, 0)"); });	} });

//