Jump to content

User:Suffusion of Yellow/abusecontribs.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Suffusion of Yellow (talk | contribs) at 20:52, 28 January 2021 (work in progress - yuck, but still useful). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
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.
// Work in progress. Use at your own risk

$.when(mw.loader.using(["mediawiki.util", "mediawiki.api"]), $.ready).then(function() {
	async function check(name) {
		let result = await (new mw.Api()).get(
			{ action : "query",
			  list : "usercontribs",
			  ucuser : name,
			  uclimit : 50,
			  ucend : Math.floor(Date.now() / 1000) - 86400,
			  ucprop : "tags|timestamp"
			});

		if (result.query.usercontribs.length == 0)
			return "none";

		for (let c of result.query.usercontribs)
			if (!c.tags.includes("mw-reverted"))
				return "live";

		return "reverted";
	}

	async function run(e) {
		e.preventDefault();

		for(let line of mw.util.$content.find('ul li')) {
			let cl = $(line).find('[href*="Special:Contributions"]');

			if (cl.length) {
				let match =  cl[0].href.match(/Special:Contributions\/(.*)/);

				if (match) {
					result = await check(match[1]);
					if (result == "live")
						$(line).css("background-color", "#f99");
					else if (result == "reverted")
						$(line).css("background-color", "#bf9");
					else
						$(line).css("background-color", "#9fd");
				}
			}
		}
	}
	if (mw.config.get('wgCanonicalSpecialPageName') == "AbuseLog") {
        $(mw.util.addPortletLink(
            "p-tb",
            "#",
            "Live edits",
            't-livedits',
            "Check for live edits within the past day"
        )).click(run);
    }
});