User:Writ Keeper/Scripts/cuStaleness.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | Documentation for this user script can be added at User:Writ Keeper/Scripts/cuStaleness. |
//<nowiki>
/*
Checkuser staleness checker, written by Writ Keeper. Checks contribs, deleted contribs, and user creation date, and determines whether the account has activity past the 90-day checkuser staleness mark.
*/
mw.hook( 'wikipage.content' ).add(function(){
var titleRegex = /Wikipedia:Sockpuppet_investigations\/[^\/]+/;
if(titleRegex.test(mw.config.get("wgPageName")))
{
//initialize some variables
var currentTimestamp = new Date().getTime();
var timestampDifference = 90*24*60*60*1000; //90 days in milliseconds
var contribsData = {"action":"query","list":"usercontribs","ucprop":"timestamp","ucuser":"","uclimit":"1","ucdir":"older", "format":"json"};
var deletedData = {"action":"query","list":"alldeletedrevisions","adrprop":"timestamp","adruser":"","adrlimit":"1","adrdir":"older", "format":"json"};
//for each cu entry (as defined by use of the {{checkuser}} template)...
$("span.cuEntry").each(function(index)
{
//first, retrieve the current iteration's user name from the text of the template
var sockName = $(this).children(":first").text();
//insert it into the API data packages
var contribsData.ucuser = sockName;
var deletedData.adruser = sockName;
//initialize values
var lastWasDeleted = false;
var lastTimestamp = -1;
//first search standard contribs
$.post("/w/api.php", contribsData, function(response){
if(typeof results.query !== "undefined" && response.query.usercontribs.length >0)
{
//retrieve the current stamp
lastTimestamp = new Date(results.query.alldeletedrevisions[0].revisions[0].timestamp).getTime();
if(currentTimestamp - lastTimestamp < timestampDifference)
{
}
}
else
{
}
})
});
}
});
//</nowiki>
$.post("/w/api.php", )
if(typeof results.query !== "undefined" && response.query.alldeletedrevisions.length >0)
new Date(results.query.alldeletedrevisions[0].revisions[0].timestamp).getTime();