注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Internet Explorer / Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください
  • Opera: Ctrl-F5を押してください
/* jshint esversion: 6, undef: true */
/* globals $, apiWrapper, mw */
// <nowiki>

{
	"use strict";
	
	const action = mw.config.get("wgAction");
	
	const update = function (pageType) {
		const title = pageType === "code_to_name"
			? "モジュール:languages/code to canonical name"
			: pageType === "name_to_code"
				? "モジュール:languages/canonical names"
				: (function() { throw new TypeError("'code_to_name' または 'name_to_code' のみが有効です。")})();
		const template = "{{#invoke:languages/print|" + pageType + "|plain}}";
		const summary = "[[MediaWiki:UpdateLanguageNameAndCode.js|更新]]";
	
		return mw.loader.using("mediawiki.api", function () {
			return new mw.Api().get({
				action: "expandtemplates",
				title: title,
				text: template,
				prop: "wikitext",
			}).done(function (data) {
				var expanded = data.expandtemplates.wikitext;
				return new mw.Api().edit(title, function () {
					return {
						text: expanded,
						summary: summary,
					};
				}).done(function (data) {
					if (data.nochange) {
						mw.notify(title + " は更新の必要はありません。");
					} else {
						mw.notify(title + " を更新しました。");
					}
				}).fail(function(...args) {
					mw.notify("投稿中にエラーが発生しました。");
					console.log(...args);
				});
			});
		}); // getScript
	};
	
	const button = $("<button>");
	
	button
		.html("<code>モジュール:languages/code to canonical name</code> と <code>モジュール:languages/canonical names</code> を更新する")
		.attr("id", "update-module");
	
	button.on("click", function () {
		update("code_to_name").then(function() {
			update("name_to_code");
		});
	});
	
	// Color the button to help editors to notice it.
	// Add the following to [[Special:MyPage/common.js]] to switch back to the default styles:
	// window.plainModuleUpdateButton = true;
	if (!window.plainModuleUpdateButton)
		mw.util.addCSS("#update-module, #update-module code { background-color: orange; }");
	
	const p = $(".mw-parser-output p:first-of-type");
	p.before(button);
	
} // empty block scope
	
// </nowiki>