User:Suffusion of Yellow/abusecontribs.js
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.
/*
* Highlight entries at Special:AbuseLog, as follows:
* Red: The user has some successful edits in the past 24 hours and some are NOT tagged "reverted"
* Green: The user has some successful edits in the past 24 hours, but all are tagged "reverted"
* Cyan: The user has no sucessful edits in the past 24 hours
*/
$.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();
mw.util.addCSS(".abusecontribs-live { background-color: #f99; }" +
".abusecontribs-reverted { background-color: #bf9; }" +
".abusecontribs-none { background-color: #9fd; }");
for(let line of mw.util.$content.find('ul li')) {
let cl = $(line).find('[href*="Special:Contributions"]');
$(line).removeClass("abusecontribs-live abusecontribs-reverted abusecontribs-none");
if (cl.length) {
let match = cl[0].href.match(/Special:Contributions\/(.*)/);
if (match) {
let result = await check(decodeURIComponent(match[1]));
$(line).addClass("abusecontribs-" + result);
}
}
}
}
if (mw.config.get('wgCanonicalSpecialPageName') == "AbuseLog") {
$(mw.util.addPortletLink(
"p-tb",
"#",
"Check for edits",
't-livedits',
"Check for unreverted edits from all users listed here, within the past day"
)).click(run);
}
});