User:Erutuon/scripts/TemplateScript.js

//

$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function {	pathoschild.TemplateScript.add([ {			name: 'root cat ', isMinorEdit: true, enabled: false, category: 'templates', script: function(editor) { var ArabicLetter = '[ءبت-غف-وي]'; var ArabicRoot = RegExp('(' + ArabicLetter + ') (' + ArabicLetter + ') (' + ArabicLetter + ')', 'g'); editor .replace(						ArabicRoot,						'\n'						) .appendEditSummary('add root category'); }		},		{			name: 'convert to non-gloss def', isMinorEdit: true, category: 'templates', script: function(editor) { editor .replace(/# ?(\{\{senseid[^\}]+\}\}) ?(\{\{(?:lb|label)[^\}]+\}\}) ?(.+)/g, '# $1 $2 ') .replace(/# ?(\{\{(?:lb|label)[^\}]+\}\}) ?(.+)/g, '# $1 ') .replace(/# ?([^\:\*].+)/g, '# ') .appendEditSummary('add T:non-gloss definition'); }		},		{			name: 'selection to non-gloss def', isMinorEdit: true, category: 'templates', script: function(editor) { editor .replaceSelection(function(selected) {						var hasNumberedList = selected.includes('#');						if ( hasNumberedList ) { return selected							.replace(/# ?(\{\{senseid[^\}]+\}\}) ?(\{\{(?:lb|label)[^\}]+\}\}) ?(.+)/g, '# $1 $2 ')							.replace(/# ?(\{\{(?:lb|label)[^\}]+\}\}) ?(.+)/g, '# $1 ')							.replace(/# ?(.+)/g, '# ');						} else {							return '';						}					}) .appendEditSummary('add T:non-gloss definition'); }		},		{			name: 'combine POS cats', category: 'templates', isMinorEdit: true, script: function(editor) { editor .replace(/\[\[Category:((?:[A-Z][\w]+ ?)+) ([a-z][^\]]+)\]\]/g, '') .replace(/(.*getByCanonicalName\|([^\|\}]+)}}(?:\|[^\|\}]+)+)}}\n?.*getByCanonicalName\|\2}}((?:\|[^\|\}]+)+)/g, '$1$3') .replace(/(.*getByCanonicalName\|([^\|\}]+)}}(?:\|[^\|\}]+)+)}}\n?.*getByCanonicalName\|\2}}((?:\|[^\|\}]+)+)/g, '$1$3') .replace(/(.*getByCanonicalName\|([^\|\}]+)}}(?:\|[^\|\}]+)+)}}\n?.*getByCanonicalName\|\2}}((?:\|[^\|\}]+)+)/g, '$1$3'); }		},		{			name: '\'\'\' → ;', category: 'formatting', isMinorEdit: true, enabled: false, script: function(editor) { editor.replace(/\'\'\'([^\']+)\'\'\'/g, '; $1'); }		},		{			name: 'chars (grc)', category: 'templates', script: function(editor) { editor.replaceSelection(					function(selected)					{						var hasEquals = selected.includes("=");						var param = '';						selected = selected.replace(/\|/g, "!");						if ( hasEquals ) {							param = '2=' + selected;						} else {							param = selected;						}						return 'grc';					}				); }		},		{			name: 'templatize categories', category: 'templates', enabled: false, script: function(editor) { editor .replace(/\[\[Category:(\w+)\:([\w ]+)\]\]\n\[\[Category:\1\:([\w ]+)\]\]\n\[\[Category:\1\:([\w ]+)\]\]/g, '') .replace(/\[\[Category:(\w+)\:([\w ]+)\]\]\n\[\[Category:\1\:([\w ]+)\]\]/g, ''); }		},		{			name: 'ar-root nocat', isMinorEdit: true, enabled: false, category: 'templates', script: function(editor) { editor .replace(/(\{\{ar-root\|[^\}]+)/g, '$1|nocat=1') .appendEditSummary('removed from Arabic category'); }		},		{			name: 'grc verb', editSummary: '', enabled: false, script: function(editor) { editor .replace(/conj-present(\|form=[^\|\}]+)\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+/g, 'conj|pres$1$2') .replace(/conj-present\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+/g, 'conj|pres$1') .replace(/-(perf)ect[^\|\}]*(\|form[^\|\}]+)\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)/g, '|$1$2$3$4') .replace(/-(perf)ect[^\|\}]*\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)/g, '|$1$2$3') .replace(/-(perf)ect[^\|\}]*/g, '|$1') .replace(/conj-(imperf)ect(\|form=[^\|\}]+)\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)/g, 'conj|$1$2$3') .replace(/conj-(imperf)ect\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+)/g, 'conj|$1$2') .replace(/-aorist-(\d\|form[^\|\}]+)\|[^\|\}]*\|[^\|\}]*(\|[^\|\}]*)\|[^\|\}]*(\|[^\|\}]+)\|[^\|\}]+\|[^\|\}]+(\|[^\|\}]+\|[^\|\}]+)\|[^\|\}]+/g, '|aor-$1$2$3$4') .replace(/-aorist-(\d)\|[^\|\}]*\|[^\|\}]*(\|[^\|\}]*)\|[^\|\}]*(\|[^\|\}]*)\|[^\|\}]*\|[^\|\}]+(\|[^\|\}]+\|[^\|\}]+)\|[^\|\}]+/g, '|aor-$1$2$3$4') .replace(/-aorist-(\d)/g, '|aor-$1') .replace(/-pluperfect[^\|\}]*(\|form[^\|\}]+)\|[^\|\}]+(\|[^\|\}]+\|[^\|\}]+\|[^\|\}]+)/g, '|plup$1$2') .replace(/-pluperfect[^\|\}]*\|[^\|\}]+(\|[^\|\}]+\|[^\|\}]+\|[^\|\}]+)/g, '|plup$1') .replace(/-pluperfect[^\|\}]*/g, '|plup') .replace(/-(fut)ure(\|form[^\|\}]+)\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+((?:\|[^\|\}]+)?)/g, '|$1$2$3$4') .replace(/-(fut)ure\|[^\|\}]+(\|[^\|\}]+)\|[^\|\}]+(\|[^\|\}]+)/g, '|$1$2$3') .replace(/-future-/g, '|fut-') .replace(/-future ?(p?)[a-z]*(?=\|)/g, '|fut$1') .replace(/([a-z]+)σ/g, '$1') .replace(/grc-alt/g, 'alter|grc') .replace(/etyl(\|[\w\-]+)\|grc}} {{m\1/g, 'der|grc$1') .replace(/grc-cite/g, 'Q|grc') .replace(/(\{\{m\|[^\|\}]+\|[^\|\}]+\|)\|/g, '$1t=') .replace(/ I /g, ' to ') .replace(/\{\{prefix\|([^\|\}]+\|[^\|\}]+)/g, '{{affix|$1-') .replace(/\|sc=Deva/g, '') .replace(/\{\{grc-ipa.*/g, '{{grc-IPA|}}') .replace(/\|gloss/g, '|t') .replace(/(\{\{...?fix)(\|[^\}]+)\|lang=([\w-]+)/g, '$1|$3$2') .replace(/titleapp\=\(\{\{grc\-(\w+)\}\}\)/g, 'dial=$1') .replace(/m\|grc\|([^\|\}]+)\|(?:\||t\=)([^\|\}]+)\}\} \+ \{\{m\|grc\|([^\|\}]+)\|(?:\||t=)([^\|\}]+)/g, 'affix|grc|$1|t1=$2|$3|t2=$4') .replace(/([^\.] |\(?:[A-Z][a-z]+ )?[A-Z][a-z]+ \{\{m(\|[^\|\}]+)/g, '$1{{cog$2')					.replace(/con-ε/g, 'con-e')					.replace(/con-α/g, 'con-a')					.replace(/con-ο/g, 'con-o')					.replace(/-νυμι/g, '-numi')					.replace(/-((?:pres|imperf))(?:ent|ect)/g, '|$1')					.replace(/(pres[^\|\}]+)((?:\|form[^\|\}]+)?)(\|[^\|\}]+)\|[^\|\}]+/g, '$1$2$3')					.replace(/(imperf[^\|\}]+)((?:\|form[^\|\}]+)?)\|[^\|\}]+(\|[^\|\}]+)/g, '$1$2$3')					.replace(/(grc-verb)[^\}]+/g, '$1')					.replace(/grc-pron(?:(\|)(?:w=)?)?/g, 'grc-IPA$1')					.replace(/(grc-conj.+)\|[^\}\|]+η[θτ][ιῐ](?=\W)/g, '$1')					.replace(/to am(?=\W)/g, 'to be')					.appendEditSummary('updated conjugation tables and other cleanup, with the help of TemplateScript');			}		},		{			name: 'etym link cleanup',			isMinorEdit: true,			enabled: false,			category: 'templates',			script: function(editor) {				editor .replace(/\{\{etyl\|([^\|\}]+)\|([^\|\}]+)\}\} (?:\'\')?\[\[([^\]]+)\]\](?:\'\')?/g, '') .appendEditSummary('fix link with the help of TemplateScript'); }		},		{			name: 'Lua code', isMinorEdit: true, enabled: false, category: 'templates', script: function(editor) { editor.replaceSelection(function(selected) {					var hasEquals = selected.includes("=");					var param = '';					if ( hasEquals ) {						param = '2=' + selected;					} else {						param = selected;					}					return 'lua';				}); },		},		{			name: 'swung dash', enabled: false, category: 'characters', script: function(editor) { editor.replace(/~/g, '⁓'); }		},		{			name: 'subst', category: 'templates', enabled: false, script: function(editor) { editor.replaceSelection(function (selected) {					return selected						.replace(/\{\{(?:subst:)?/g, '{{subst:');				}); }		},		{			name: 'der and rel', category: 'templates', enabled: false, script: function(editor) { editor.replaceSelection(					function (selected) {						var sectionType = ( selected.match(/=((?:Der|Rel))/)[1].toLowerCase || 'der' );						// Use lang in first l template.						var langCode = selected.match(/\{\{l\|([a-z-]+)\|[^\|\}]+/)[1];						var numberOfColumns = ( selected.match(/\{\{top(\d)\}\}/)[1] || '3' );						return selected								.replace(/\n\* ?\{\{l\|[^\|\}]+\|([^\|\}]+)\}\}/g, '\n|$1')								.replace(/\n\{\{[^\}]+\}\}/g, '')								.replace( /((?:\n\|[^\|\}\n]+)+)/g, '\n' );					}				);			}		},		{			name: 'letters template', enabled: false, category: 'templates', script: function(editor) { var content = editor.get; var hasDoc = content.includes('list doc'); var lang = content.match(/l(?:-self)\|([^\|\}]+)/)[1]; var nativeName = content.match(/\|hypernym=(?:\{\{l(?:-self)?\|[^\|\}]+\|)?([^\|\}\n]+)(?:\|[^\|\}]+)?(?:\}\})?/); var nativeNameParameter = ''; if ( nativeName ) { nativeNameParameter = '|native name=' + nativeName[1] + '\n'; } else { nativeNameParameter = ''; }				editor .replace(						/list helper 2(?:\n\|.+)+\n\|list=/g,						'letters\n|lang=' + ( lang || '' ) + '|sc=Latn\n' + nativeNameParameter						) .replace(						/(?:)?(\(?)\{\{l(?:-self)?\|[^\|\}]+\|([^\|\}]+)(?:\|[^\|\}]+)?\}\}\s*\{\{l(?:-self)?\|[^\|\}]+\|([^\|\}]+)(?:\|[^\|\}]+)?\}\}(\)?)(?:,? )?/g,						'|$1$2/$3$4'						) .replace(						/(?:)?(\(?)\{\{l(?:-self)?\|[^\|\}]+\|([^\|\}]+)(?:\|[^\|\}]+)?\}\}(\)?)(?:,? )?/g,						'|$1$2$3'						) .replace(/\|([^\/])\/([^\/])/g, '|$1$2') .replace(/(?=\}\})/g, '') .replace(/(\}\})/, '$1$2') .replace(/\s+$/, '') .appendEditSummary('converted to Template:letters with the help of TemplateScript'); if ( !hasDoc ) { editor .append(' \n\n ') .appendEditSummary('added Template:list doc for documentation'); }			}		},		{			name: 'fix T:lang', enabled: false, script: function(editor) { editor .replace(/\{\{(lang\|[^\|\}]+\|[^\|\}]+)\|\}\}/g, '') .replace(/\{\{(lang[^\}]+)\|lang=[^\|\}]+([^\}]*)\}\}/g, '') .appendEditSummary('fixing parameters of Template:lang with the help of TemplateScript') .options({ minor: true }); }		},		{			name: 'temporary', isMinorEdit: true, //			enabled: false, script: function(editor) { editor .replace(/\[\[adverbial accusative\|Adverbial accusative\]\]/g, '') .replace(/Adverbial accusative/g, '') .appendEditSummary('adding T:adverbial accusative, which also categorizes'); }		},		{			name: 'related and derived cleanup', category: 'templates', enabled: false, script: function(editor) { editor .replace .replace; }		},	]); });

//