Jump to content

User:Saph/cleanup.js

From Wiktionary, the free dictionary

Note: You may have to bypass your browser’s cache to see the changes. In addition, after saving a sitewide CSS file such as MediaWiki:Common.css, it will take 5-10 minutes before the changes take effect, even if you clear your cache.

  • Mozilla / Firefox / Safari: hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (Command-R on a Macintosh);
  • Konqueror and Chrome: click Reload or press F5;
  • Opera: clear the cache in Tools → Preferences;
  • Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5.


/* Adds buttons, using [[User:Erutuon/scripts/CleanupButtons.js]], to perform various cleanups including replacing uder with more specific templates */
/* jshint boss: true, esversion: 6, eqeqeq: true, varstmt: true, unused: true, undef: true */
/* globals $, CleanupButtons, mw */
// <nowiki>
if ( [ "edit", "submit" ].includes(mw.config.get("wgAction"))
		&& mw.config.get("wgPageContentModel") === "wikitext"
		// Not in edit conflict view.
		&& !document.querySelector(".mw-twocolconflict-changes-col")) {
$.when(
	$.getScript("//en.wiktionary.org/w/index.php?title=User:Erutuon/scripts/CleanupButtons.js&action=raw&ctype=text/javascript"),
	$.ready
).done(function () {

"use strict";

const cleanupFunctions = [
	{
		textBoxIncludes: `uder`,
		button: { text: "to bor" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace("{{uder", "{{bor");
				CleanupButtons.addSummary(oldContent !== content, "uder > bor");
				return content;
			}
	},
	{
		textBoxIncludes: `uder`,
		button: { text: "to der" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace("{{uder", "{{der");
				CleanupButtons.addSummary(oldContent !== content, "uder > der");
				return content;
			}
	},
	{
		textBoxIncludes: `uder`,
		button: { text: "to lbor" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/{{uder([^}]+)}}/, "{{lbor$1|notext=1}}");
				CleanupButtons.addSummary(oldContent !== content, "uder > lbor");
				return content;
			}
	},
	{
		textBoxIncludes: `uder`,
		button: { text: "to ubor" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/{{uder([^}]+)}}/, "{{ubor$1|notext=1}}");
				CleanupButtons.addSummary(oldContent !== content, "uder > ubor");
				return content;
			}
	},
	{
		textBoxIncludes: /(?<====Etymology===\n)(?!from)([^\n.]+)/i,
		button: { text: "missing from" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/(?<====Etymology===\n)(?!from)([^\n.]+)/i, "From $1.");
				content = content.replace("..", ".");
				CleanupButtons.addSummary(oldContent !== content, "add missing from");
				return content;
			}
	},
	{
		textBoxIncludes: `uder`,
		button: { text: "to translit" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/{{uder([^}]+)}}/, "{{translit$1|notext=1}}");
				CleanupButtons.addSummary(oldContent !== content, "uder > translit");
				return content;
			}
	},
	{
		textBoxIncludes: /(\[\[w:([^\]|]+)(?:\|\1)?\]\]|\[\[w:([^\|]+)\|([^\]]+)\]\])/,
		button: { text: "templatise w" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/\[\[w:([^\]|]+)(?:\|\1)?\]\]/g, "{{w|$1}}");
				content = content.replace(/\[\[w:([^\|]+)\|([^\]]+)\]\]/g, "{{w|$1|$2}}");
				CleanupButtons.addSummary(oldContent !== content, "templatise wikipedia links");
				return content;
			}
	},
	{
		textBoxIncludes: /\[\[category:[a-z\-]{1,11}:/i,
		button: { text: "topic cleanup" },
		minorEdit: true,
		func:
			function(content) {
				const oldContent = content;
				content = content.replace(/\[\[category:([a-z\-]{1,11}):([^\]]+)\]\]/gi, "{{C|$1|$2}}");
				const rawRemoved = content;
				content = content.replace(/({{C\|en)(\|.*?)}}(?:\n\1(\|.*?)}})?(?:\n\1(\|.*?)}})?(?:\n\1(\|.*?)}})?/gi, "$1$2$3$4$5}}");
				CleanupButtons.addSummary(oldContent !== rawRemoved, "templatise raw topic cat links");
				CleanupButtons.addSummary(rawRemoved !== content, "topic cat cleanup");
				return content;
			}
	}
];

const buttons = new CleanupButtons();

for ( const buttonInfo of cleanupFunctions )
	if (CleanupButtons.evaluateConditions(buttonInfo.condition, buttonInfo.textBoxIncludes))
		buttons.addButton(buttonInfo);

});

}
// </nowiki>