Jump to content

User:Dreamy Jazz/sockpuppet-category-helper.js and User:Writ Keeper/Scripts/sockpuppet-category-helper.js: Difference between pages

From Wikipedia, the free encyclopedia
(Difference between pages)
Content deleted Content added
fix error
 
 
Line 1: Line 1:
/*
/*
Script by Dreamy Jazz
Script by Dreamy Jazz, forked by Writ Keeper
Replaces userlinks in sockpuppet categories with uses of the checkuser template.
Replaces userlinks in sockpuppet categories with uses of the checkuser template.
Version 1.3.4
Version 1.3.4
Line 10: Line 10:
] ).then( async () => {
] ).then( async () => {
if (mw.config.get('wgPageName').startsWith('Category:Wikipedia_sockpuppets_of') || mw.config.get('wgPageName').startsWith('Category:Suspected_Wikipedia_sockpuppets_of')) {
if (mw.config.get('wgPageName').startsWith('Category:Wikipedia_sockpuppets_of') || mw.config.get('wgPageName').startsWith('Category:Suspected_Wikipedia_sockpuppets_of')) {
$("div#mw-pages a.userlink").each(async function (index, element) {
$("div#mw-pages a[href^='/wiki/User:']").each(async function (index, element) {
let text = $(element).text().replace("User:", "");
let text = $(element).text().replace("User:", "");
if (mw.util.isIPAddress(text)) {
if (mw.util.isIPAddress(text)) {

Latest revision as of 19:35, 23 January 2022

/*
Script by Dreamy Jazz, forked by Writ Keeper
Replaces userlinks in sockpuppet categories with uses of the checkuser template.
Version 1.3.4
*/
$(document).ready(function() {
	mw.loader.using( [
	'mediawiki.api',
	'mediawiki.util',
] ).then( async () => {
  if (mw.config.get('wgPageName').startsWith('Category:Wikipedia_sockpuppets_of') || mw.config.get('wgPageName').startsWith('Category:Suspected_Wikipedia_sockpuppets_of')) {
    $("div#mw-pages a[href^='/wiki/User:']").each(async function (index, element) {
		let text = $(element).text().replace("User:", "");
		if (mw.util.isIPAddress(text)) {
		  text = "{{checkip|" + text + "}}";
		} else {
		  text = "{{checkuser|" + text + "}}";
		}
		let value = await getParsedTemplateText(text);
		let $new = $(value);
		$(element).parent().prepend($new);
		$(element).attr("style", "display:none");
		if ($(element).attr("class") !== undefined) {
			$new.find('.cuEntry .plainlinks:nth-child(1) a').addClass($(element).attr("class"));
		}
    });
  }
});
});

async function getParsedTemplateText(wikitext) {
	const api = new mw.Api();
	const response = await api.get({
		action: "parse",
		format: "json",
		prop: "text",
		text: wikitext,
		wrapoutputclass: "",
		disablelimitreport: 1,
		disableeditsection: 1,
		contentmodel: "wikitext"
	});
	return response.parse.text["*"];
}