User:Erutuon/scripts/addAutoCat.js

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

(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(""); if ( autoCatEditSummary ) $editSummaryBox.val("added T:auto cat with JavaScript"); $(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: "Add auto cat and save",				}); const button2 = new OO.ui.ButtonWidget({					label: "or preview",				}); button1.$element .click( => fillAutoCat(true)) .attr("title", "Create this category using topic cat"); button2.$element .click( => fillAutoCat(false)) .attr("title", "Create this category using topic cat"); buttons.push(button1.$element); buttons.push(button2.$element); } else if (action === "view") { const button = new OO.ui.ButtonWidget({					label: "Add auto cat and edit",				}); button.$element.click( => {					location.href = new mw.Uri(location.href).extend({ action: "edit", preloadtext: "", }).toString;				}); buttons.push(button.$element); }			if (buttons.length > 0) { const div = $(" ").append(buttons); $("#firstHeading").after(div); }		});	} else if (action === "edit" && !$textBox.val.includes("auto cat")) {		$( => { const button = new OO.ui.ButtonWidget({				label: "Replace with autocat",				id: "add-autocat",			}); button.$element.click( => $textBox.val("")); $("#editform").prepend(button.$element); });	} });

});

//