注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer / Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5

/* jshint esversion: 6, undef: true, unused: true, varstmt: true */
/* globals $, mw, OO */
// <nowiki>

(function addAutoCatIIFE () {
"use strict";

if (mw.config.get("wgNamespaceNumber") !== 14)
	return;

const autoCatEditSummary = typeof window.autoCatEditSummary == "undefined"
	? false : window.autoCatEditSummary;

const $textBox = $("#wpTextbox1");
const $editSummaryBox = $("#wpSummary");

function fillAutoCat(autoSave) {
	$textBox.val("{{autocat}}");
	if ( autoCatEditSummary )
		$editSummaryBox.val(wgULS("使用[[User:EdwardAlexanderCrowley/js/addAutoCat.js|JavaScript]]创建[[T:auto cat]]",
			"使用[[User:EdwardAlexanderCrowley/js/addAutoCat.js|JavaScript]]創建[[T:auto cat]]"));
	
	$(autoSave ? "#wpSave" : "#wpPreview").click();
}
	
const action = mw.config.get("wgAction");

mw.loader.using("oojs-ui").done(() => {
	if (mw.config.get("wgCurRevisionId") === 0) { // new page
		$(() => {
			const buttons = [];
			if (action === "edit") {
				const button1 = new OO.ui.ButtonWidget({
					label: wgULS("加入autocat并保存", "加入autocat並保存"),
				});
				const button2 = new OO.ui.ButtonWidget({
					label: wgULS("autocat并预览", "autocat並預覽"),
				});
				
				button1.$element
					.click(() => fillAutoCat(true))
					.attr("title", wgULS("使用topic cat创建分类", "使用topic cat創建分類"));
				button2.$element
					.click(() => fillAutoCat(false))
					.attr("title", wgULS("使用topic cat创建分类", "使用topic cat創建分類"));
				
				buttons.push(button1.$element);
				buttons.push(button2.$element);
			} else if (action === "view") {
				const button = new OO.ui.ButtonWidget({
					label: wgULS("加入autocat并编辑", "加入autocat並編輯"),
				});
				
				button.$element.click(() => {
					location.href = new mw.Uri(location.href).extend({
						action: "edit",
						preload: "Template:$1",
						"preloadparams[]": "{{autocat}}",
					}).toString();
				});
				
				buttons.push(button.$element);
			}
			
			if (buttons.length > 0) {
				const div = $("<div>").append(buttons);
				
				$("#firstHeading").after(div);
			}
		});
	} else if (action === "edit" && !$textBox.val().includes("auto cat") && !$textBox.val().includes("autocat")) {
		$(() => {
			const button = new OO.ui.ButtonWidget({
				label: wgULS("本分类改用autocat", "本分類改用autocat"),
				id: "add-autocat",
			});
			button.$element.click(() => $textBox.val("{{autocat}}"));
			
			$("#editform").prepend(button.$element);
		});
	}
});

})();

// </nowiki>