User:JJPMaster/Scripts/checkRedirectAutopatroller.js

This is an old revision of this page, as edited by JJPMaster (talk | contribs) at 04:24, 2 January 2025 (run function). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
const redList = "Wikipedia:New pages patrol/Redirect autopatrol list";

const relevantUn = mw.config.get("wgRelevantUserName") ? mw.config.get("wgRelevantUserName") : null;

async function getFullList() {
	const params = {
		action: "parse",
		page: redList,
		prop: "wikitext",
		format: "json"
	},
	api = new mw.Api();
	
	const data = await api.get(params);
	return data.parse.wikitext["*"].split("<!-- DannyS712 bot III: autopatrol list start -->")[1].split("<!--")[0];
}

async function onList(username) {
	return getFullList().includes(new RegExp(`{{[Uu]ser2|${username}}}`));
}

async function addRALLink() {
	if (relevantUn) {
		var present = await onList(relevantUn);
		$(mw.util.addPortletLink("p-cactions", "#", "Redirect autopatrol?", "pt-ral", "Check if this user is on the redirect autopatrol list")).click(() => {
			if (present) {
				alert(`${relevantUn} IS on the redirect autopatrol list.`);
				return;
			}
			alert(`${relevantUn} is NOT on the redirect autopatrol list.`);
		});
	}
}
addRALLink();