User:Technical 13/Scripts/ACCHelp/CentralAuth.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.
if(mw.config.get("wgCanonicalSpecialPageName") === "CentralAuth"){
	function checkActive(){
		var existsAgoDate = new Date($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().slice($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().indexOf('</strong>')+9, $('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().indexOf('(')).trim());
		var existsAgoTime = Date.now() - existsAgoDate;
		var existsEditsEn = 0;
		if($('td a:contains("en.wikipedia.org")').length ){
			existsEditsEn = parseInt($('td a:contains("en.wikipedia.org")').closest('tr').find('td').eq(4).html().replace(/<\/?a(.*?)>/gi, ''),10);
		}
		var existsEditsGlobal = $('fieldset#mw-centralauth-info').find('li:nth-child(5)').html().substr(34);
		var existsNotActive = true;
		if(existsEditsEn > 0){
			var aYearAgo = new Date();
			var aYearAgoDay = aYearAgo.getUTCDate();
			var aYearAgoMonth = aYearAgo.getUTCMonth();
			var aYearAgoYear = aYearAgo.getUTCFullYear() - 1;
			aYearAgo = new Date(aYearAgoYear, aYearAgoMonth, aYearAgoDay);
			if(existsAgoTime < aYearAgo){
				if(existsEditsGlobal < 15){ existsNotActive = "SUL";/* Assume active (will need to check for activity) */ }
				else { existsNotActive = false;/* More than 15 global edits. */ }
			} else { existsNotActive = false;/* More than a year old. */ }
		} else {
			var sixMonthsAgo = new Date();
			var sixMonthsAgoDay = sixMonthsAgo.getUTCDate();
			var sixMonthsAgoMonth = sixMonthsAgo.getUTCMonth() - 6;
			var sixMonthsAgoYear = sixMonthsAgo.getUTCFullYear();
			if(sixMonthsAgoMonth < 0){
				sixMonthsAgoYear -= 1;
				sixMonthsAgoMonth += 6;
			}
			sixMonthsAgo = new Date(sixMonthsAgoYear, sixMonthsAgoMonth, sixMonthsAgoDay);
			if(existsAgoTime < sixMonthsAgo){
				if(existsEditsGlobal > 15){ existsNotActive = false;/* Too many global edits */ }
			} else { existsNotActive = "SUL";/* Assume active (will need to check for activity) */ }
		}
		return existsNotActive;
	}
	if(typeof($("div#mw-content-text div.error:contains('There is no global account for')").html()) === "undefined"){
		var existsInactive = checkActive();
		var existsName = '"' + $('fieldset#mw-centralauth-info').find('li:nth-child(1)').html().substr(27).replace(' ', '_') + '"';
		var existsAgo = $('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().substr($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().indexOf('(')).replace(/[\(\)]/g, '');
		var existsEditsGlobal = $('fieldset#mw-centralauth-info').find('li:nth-child(5)').html().substr(34);
		if(existsEditsGlobal === "0"){ existsEditsGlobal = 'no global edits'; }
		else if(existsEditsGlobal === "1"){ existsEditsGlobal = '1 global edit'; }
		else { existsEditsGlobal = existsEditsGlobal + ' global edits'; }
		if (!existsInactive || existsInactive === "SUL"){
			if (existsInactive === "SUL"){
				var existsInactiveCheckSUL = confirm("WARNING!\n\t\t" + existsName + ' may be an ACTIVE account that was created ' + existsAgo + ' and has ' + existsEditsGlobal + ',\n\t\tbut you will need to check https://tools.wmflabs.org/quentinv57-tools/tools/sulinfo.php?showinactivity=1&showblocks=1&username=' + existsName + ' to be sure.');
				if (existsInactiveCheckSUL === false/* change this back to null when switched back to prompt when read to send in date to test */){
					$('fieldset#mw-centralauth-info').find('li:nth-child(3)').html($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().replace('(' + existsAgo + ')', '(' + existsName + ' is an <b class="error">ACTIVE</b> account that was created ' + existsAgo + ' and has ' + existsEditsGlobal + '.)'));
				} else {
					$('fieldset#mw-centralauth-info').find('li:nth-child(3)').html($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().replace('(' + existsAgo + ')', '(' + existsName + ' is an <b style="color: #0A0;">INACTIVE</b> account that was created ' + existsAgo + ' and has ' + existsEditsGlobal + '.)'));
				}
			} else {
				$('fieldset#mw-centralauth-info').find('li:nth-child(3)').html($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().replace('(' + existsAgo + ')', '(' + existsName + ' is an <b class="error">ACTIVE</b> account that was created ' + existsAgo + ' and has ' + existsEditsGlobal + '.)'));
			}
			$("h1#firstHeading").html(tickBad + " " + $("h1#firstHeading").html());
			document.title = Ucross + document.title;
		} else {
			$('fieldset#mw-centralauth-info').find('li:nth-child(3)').html($('fieldset#mw-centralauth-info').find('li:nth-child(3)').html().replace('(' + existsAgo + ')', '(' + existsName + ' is an <b style="color: #0A0;">INACTIVE</b> account that was created ' + existsAgo + ' and has ' + existsEditsGlobal + '.)'));
			$("h1#firstHeading").html(tickGood + " " + $("h1#firstHeading").html());
			document.title = Ucheck + document.title;
		} 
	} else {
		$("h1#firstHeading").html(tickGood + " " + $("h1#firstHeading").html());
		document.title = Ucheck + document.title;
	}
}