User:AuburnPilot/Sleeper/monobook.js

From Wikipedia, the free encyclopedia

If a message on your talk page led you here, please be wary of who left it. Code that you insert on this page could contain malicious content capable of compromising your account. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. If this is a .js page, the code will be executed when previewing the page.
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
//<pre><nowiki>
//Helper tools
 
addOnloadHook(newlogcheck)
function newlogcheck()
{
if (document.title.indexOf("New pages") != -1 && location.href.search(/username=/) ==-1)
  {
addTab("javascript:nootheredits()", "check editcounts", "ca-sleepers", "Show edit # for accounts", "");
  }
else if (location.href.indexOf('Special:Listusers') != -1)
  {
addTab("javascript:checkinactive()", "check for inactives", "ca-inactives", "Show inactive accounts", "");
addTab("/w/index.php?title=Special:Listusers&group=sysop&limit=5000", "(all sysops)", "ca-sysops", "Show sysops", "");
  }
}
 
//Globals
NewUPcount = 0;
NewUPcount10 = 0;
inactiveu = 0;
inactive_user_num = 0;
active_user_num = 0;
c_active_user_num = 0;
//
 
//
function checkinactive()
{
if (!document.getElementsByTagName('ul')[0])
{alert('There are no elements in this list.'); return;}
if (!document.getElementsByTagName('ul')[0].getElementsByTagName('li')[0])
{alert('There are no elements in this list.'); return;}
var ls = document.getElementsByTagName('ul')[0].getElementsByTagName('li');
if (document.getElementById('contentSub').innerHTML.indexOf('Checking account activity levels.') !=-1)
  {alert('Results already shown.'); return;}
document.getElementById('contentSub').innerHTML += '<br>Checking account activity levels.';
consec_inactivecheck();
}
 
function consec_inactivecheck()
{
if (document.getElementsByTagName('ul')[0].getElementsByTagName('li')[inactiveu])
  {
var name = document.getElementsByTagName('ul')[0].getElementsByTagName('li')[inactiveu].getElementsByTagName('a')[0].innerHTML;
var URL = '/w/index.php?title=Special:Contributions&limit=1&target=' + escape(name) + '&useskin=standard';
  xml_http = HTTPClient();
  xml_http.open("GET", URL, true);
  xml_http.onreadystatechange = partial_inactivecheck;
  xml_http.send(null);
  }
else 
  {
  var editaverage = active_user_num/inactiveu;
  var ceditaverage = c_active_user_num/inactiveu;
  var ineditaverage = inactive_user_num/inactiveu;
  ceditaverage = 100*ceditaverage;
  editaverage = 100*editaverage;
  ineditaverage = 100*ineditaverage;
  ceditaverage = Math.round((100)*ceditaverage)/100;
  editaverage = Math.round((100)*editaverage)/100;
  ineditaverage = Math.round((100)*ineditaverage)/100;
  document.getElementById('bodyContent').innerHTML = '<strong><span style="color:darkblue;">Edit count completed:</span>' + '<br>' + Math.round((100)*editaverage)/100 + '% (' + active_user_num + ') <span style="color:darkblue;">of these users are active (last edited 29 days ago at most)</span><br>' + Math.round((100)*ceditaverage)/100 + '% (' + c_active_user_num + ') <span style="color:darkgreen;">of these users are currently active (last edited 3 days ago at most)</span><br>' + Math.round((100)*ineditaverage)/100 + '% (' + inactive_user_num + ') <span style="color:darkred;">of these users are long-term inactive (last edited 1+ years ago)</strong></span><br>' + document.getElementById('bodyContent').innerHTML;
  }
}
 
function partial_inactivecheck()
{
  if (xml_http.readyState != 4) return;
  var Done=0;
  var xmlpage = xml_http.responseText.split('<!-- end content -->')[0];
//UTC done
  if (xmlpage.indexOf('<ul>') == -1)
  {
  document.getElementsByTagName('li')[inactiveu].innerHTML += '<span style="color:red;"><strong> (error)</strong></span>';
  Done=1;
  }
  if (Done == 0)
  {
//Current time
  var now = new Date();
  var curtime = now.toUTCString().replace(/GMT/, "UTC");
  var lasttime = xmlpage.split('<li>')[1].split('</li>')[0].split(' (<a href=')[0].split(' (<A href=')[0].split('(<a href=')[0].split('(<A href=')[0];
  var totdays = getElapsedTime(curtime,lasttime);
//
  if (totdays < 4)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:blue;"> (active)</span>';
  c_active_user_num += 1;
  active_user_num += 1;
     }
  else if (totdays > 728)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')<span style="color:red;"> (inactive -- 2+ years)</span></strong>';
  inactive_user_num += 1;
     }
  else if (totdays > 364)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:red;"> (inactive -- 1 year)</span>';
  inactive_user_num += 1;
     }
  else if (totdays > 89)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:darkred;"> (inactive -- 3-11 months)</span>';
     }
  else if (totdays > 59)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:purple;"> (inactive -- ~2 months)</span>';
     }
  else if (totdays > 29)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:darkorange;"> (away -- ~1 month)</span>';
     }
  else if (totdays > 3)
     {
  document.getElementsByTagName('li')[inactiveu].innerHTML += ' <strong>(</strong>last edit: <strong>' + lasttime + ')</strong><span style="color:green;"> (away)</span>';
  active_user_num += 1;
     }
  }
  inactiveu += 1;
  consec_inactivecheck();
}
//END
 
//
function nootheredits()
{
if (document.getElementById('contentSub').innerHTML.indexOf('Checking for account activity levels for page authors.') !=-1)
  {alert('Results already shown.'); return;}
var ls = document.getElementsByTagName('ol')[0].getElementsByTagName('li');
if (ls[0].innerHTML.indexOf(' edit)</strong>') != -1 || ls[0].innerHTML.indexOf(' edits)</strong>') != -1)
  {alert('Results already shown.'); return;} 
document.getElementById('contentSub').innerHTML += "<br><strong>Checking for account activity levels for page authors.</strong>";
consec_newcontribcheck();
}
 
function consec_newcontribcheck()
{
if (document.getElementsByTagName('ol')[0].getElementsByTagName('li')[NewUPcount])
  {
var name = document.getElementsByTagName('ol')[0].getElementsByTagName('li')[NewUPcount].getElementsByTagName('a')[2].innerHTML;
var URL = '/w/index.php?title=Special:Contributions&limit=10&target=' + escape(name) + '&useskin=standard';
  xml_http = HTTPClient();
  xml_http.open("GET", URL, true);
  xml_http.onreadystatechange = NU_editcheck;
  xml_http.send(null);
  }
else 
  {
  var countaverage = Math.round((100)*NewUPcount10/NewUPcount)/100;
  countaverage = 100*countaverage;
//get time frame
  var newtime = document.getElementsByTagName('li')[0].innerHTML.split(' <a href="')[0].split(' <A href="')[0];
  var lasttime = document.getElementsByTagName('li')[NewUPcount-1].innerHTML.split(' <a href="')[0].split(' <A href="')[0];
  var totdays = getElapsedTime(newtime,lasttime);
  var caverage = NewUPcount/totdays;
  document.getElementById('bodyContent').innerHTML = '<strong>' + countaverage + '%<span style="color:darkblue;"> of these pages where made by users with 10+ edits.</span></strong>' + '<br>' + '<strong>' + Math.round((100)*caverage)/100 + ' pages created per day (average).</strong>' + '<br>' + document.getElementById('bodyContent').innerHTML;
   document.getElementById('contentSub').innerHTML += "<br><strong><span style='color: blue'>Edit count completed.</span></strong>";
  var body = document.getElementById('bodyContent');
  body.ranSetupTooltipsAlready=false;
  setupTooltips(body);
  }
}
 
function NU_editcheck()
{
  if (xml_http.readyState != 4) return;
  var xmlpage = xml_http.responseText;
if (xmlpage.indexOf('No changes were found matching these criteria.') !=-1)
  {
  document.getElementsByTagName('li')[NewUPcount].innerHTML += '<span style="color:red;"><strong> (edits deleted)</strong></span>';
  NewUPcount += 1;
  }
else
{
  xmlpage = xmlpage.split('<ul>')[1].split('</ul>')[0];
  if (xmlpage.split('<li>').length-1 == 1)
  {
  document.getElementsByTagName('li')[NewUPcount].innerHTML += '<span style="color:red;"><strong> (1 edit)</strong></span>';
  NewUPcount += 1;
  }
  else if (xmlpage.split('<li>').length-1 > 1 && xmlpage.split('<li>').length-1 < 5)
  {
  var num = xmlpage.split('<li>').length - 1;
  document.getElementsByTagName('li')[NewUPcount].innerHTML += '<span style="color:darkred;"><strong> (' + num + ' edits)</strong></span>';
  NewUPcount += 1;
  }
  else if (xmlpage.split('<li>').length-1 > 4 && xmlpage.split('<li>').length-1 < 10)
  {
  var num = xmlpage.split('<li>').length - 1;
  document.getElementsByTagName('li')[NewUPcount].innerHTML += '<strong> (' + num + ' edits)</strong>';
  NewUPcount += 1;
  }
  else if (xmlpage.split('<li>').length-1 > 9)
  {
  document.getElementsByTagName('li')[NewUPcount].innerHTML += '<span style="color:blue;"> (10+ edits)</span>';
  NewUPcount10 += 1;
  NewUPcount += 1;
  }
}
consec_newcontribcheck();
}
//END
 
//block stuff
addOnloadHook(IPblock)
function IPblock()
{
if (location.href.search(/&(wpBlockExpiry|wpBlockOther)=/) !=-1) return;
if (document.title.indexOf('Block user') != -1 && document.getElementById('wpBlockExpiry'))
  {
var option = document.getElementById('wpBlockOther').getElementsByTagName('input')[0];
option.value='indefinite';
  }
}
 
if (document.implementation.createDocument)
 {var gml_xmlparser = new DOMParser();}
 
function standard_XMLParse(string) 
{
  if (document.implementation.createDocument)
 {
    return gml_xmlparser.parseFromString(string, "text/xml");
  } 
  else if (window.ActiveXObject) 
  {
    string = string.replace(/<body .*\"ns-(.*)\">/, '<body class="ns-$1">');
    rer = string.match(/<h1 .*<\/h1>/)[0].replace(/&/g, '&');
    if (rer) {string = string.replace(/<h1 .*<\/h1>/, rer);}
    var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    gml_xmldoc.async = false;
    ret = gml_xmldoc.loadXML(string);
    myErr = gml_xmldoc.parseError;
		if (myErr.errorCode || !ret)
                {
			showError("Error: " + ERROR_XML + myErr.reason);
			return null;
		}
		return gml_xmldoc.documentElement
  }
  return null;
}
 
function HTTPClient()
{
  var xml_http = false;
  if(window.XMLHttpRequest)
    xml_http = new XMLHttpRequest();
  else if (IE){
    try{
      xml_http = new ActiveXObject("Msxml2.XMLHTTP")
    } catch (e){
      try{
        xml_http = new ActiveXObject("Microsoft.XMLHTTP")
      } catch (e){}
    }
  }
	if (!xml_http) showError(ERROR_XML);
  return xml_http
};
//END
//</nowiki></pre>