User:Erutuon/scripts/etylCleanup.js

Hello, you have come here looking for the meaning of the word User:Erutuon/scripts/etylCleanup.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word User:Erutuon/scripts/etylCleanup.js, but we will also tell you about its etymology, its characteristics and you will know how to say User:Erutuon/scripts/etylCleanup.js in singular and plural. Everything you need to know about the word User:Erutuon/scripts/etylCleanup.js you have here. The definition of the word User:Erutuon/scripts/etylCleanup.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofUser:Erutuon/scripts/etylCleanup.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
/*	<nowiki>
	If there are {{etyl}} templates in the edit box,
	add a link to convert {{etyl}} to {{der}}.
	Beware: after using this tool, you should change some cases of {{der}}
	to {{inh}} or {{bor}}, as appropriate.
*/

var namespaceNumber = mw.config.values.wgNamespaceNumber;
var action = mw.config.values.wgAction;

if ( ( namespaceNumber === 0 || namespaceNumber === 118 ) &&
		action === "edit"		&& /\{\{etyl\|/.test($("#wpTextbox1").val()) )
{
	if ( !$("#wikitext-cleanup-button-wrapper").length )
		$("#editform").prepend('<div id="wikitext-cleanup-button-wrapper"></div>');
	
	$("#wikitext-cleanup-button-wrapper").append('<div id="etyl-cleanup" class="wikitext-cleanup-button"><a href="javascript:etylToDer()">replace {{etyl}} with {{der}}</a></div>');

	importStylesheetURI("//en.wiktionary.orghttps://en.wiktionary.org/w/index.php?title=User:Erutuon/styles/wikitext-cleanup.css&action=raw&ctype=text/css");
	
	var count = 0;
	
	var etylToDer = function()
	{
		var content = $("#wpTextbox1").val();
		
		content = content.replace(
			/\{\{etyl\|+\|(+)\}\} \{\{(?:l|m)\|(+)\|(+)\}\}/g,
			function(wholeMatch, entryLang, sourceLang, term)
			{
				count += 1;
				if ( entryLang === "-" )
					return `{{cog|${sourceLang}|${term}}}`;
				else
					return `{{der|${entryLang}|${sourceLang}|${term}}}`;
			}
		);
		
		if ( count > 0 )
		{
			if ( count > 1 )
				mw.notify(`${count} replacements made.`);
			else
				mw.notify(`${count} replacement made.`);
		
			$("#wpSummary").val(
				function(index, summary)
				{
					addition = "replaced ] with ], ], or ], with the help of ]";
					
					afterSectionName = summary.match(/^\/\*+\*\/\s+(.+)/);
					
					if ( afterSectionName && afterSectionName.length > 1 )
						addition = "; " + addition;
					
					if ( ( !afterSectionName || !afterSectionName.includes(addition) ) )
						return summary + addition;
				}
			);
		}
		else
			mw.notify("No replacements made.");
		
		$("#wpTextbox1").val(content);
	};
}

// </nowiki>