User:Erutuon/scripts/etylCleanup.js

/*	 	If there are templates in the edit box, add a link to convert to. Beware: after using this tool, you should change some cases of to or, 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(' '); $("#wikitext-cleanup-button-wrapper").append(' replace with  ');

importStylesheetURI("//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\|[^\|\}\n]+\|([^\|\}\n]+)\}\} \{\{(?:l|m)\|([^\|\}\n]+)\|([^\}\n]+)\}\}/g,			function(wholeMatch, entryLang, sourceLang, term)			{				count += 1;				if ( entryLang === "-" )					return `🇨🇬`;				else					return ``;			}		); if ( count > 0 ) {			if ( count > 1 ) mw.notify(`${count} replacements made.`); else mw.notify(`${count} replacement made.`); $("#wpSummary").val(				function(index, summary)				{					addition = "replaced T:etyl with T:der, T:inh, or T:bor, with the help of JavaScript";					afterSectionName = summary.match(/^\/\*[^\*]+\*\/\s+(.+)/);					if ( afterSectionName && afterSectionName[1].length > 1 )						addition = "; " + addition;					if ( ( !afterSectionName || !afterSectionName[1].includes(addition) ) )						return summary + addition;				}			); }		else mw.notify("No replacements made."); $("#wpTextbox1").val(content); }; }

//