User:Ais523/sandbox.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

// Request by Essjay on [[WP:US]] talk: RfA closing script without feature creep
// by [[User:ais523]]
// <pre><nowiki>
addOnloadHook(function(){
  if(location.href.indexOf("Wikipedia:Requests_for_adminship/")!=-1&&
     location.href.indexOf("?")==-1)
  {
    addTab(location.href+"?action=edit&rfa=rfap","rfa p","ca-rfap","Close RfA as passed","");
    addTab(location.href+"?action=edit&rfa=rfaf","rfa f","ca-rfaf","Close RfA as failed","");
  }
  if(location.href.indexOf("?action=edit&rfa=rfa")!=-1)
  {
    var wtb1=document.getElementById('wpTextbox1');
    var a;
    // Add rfab at the bottom of the page
    wtb1.value+='{'+'{subst:rfab}}';
    // Code so that the initial === header is ignored when looking for external links
    a=wtb1.value.split('===');
    // Change the first external link to 'Final'
    var x=a[2].indexOf('[');
    var y=a[2].indexOf(']');
    a[2]=a[2].substr(0,x)+'Final'+a[2].substr(y+1);
    // Change everything between the first semicolon and the first time string to 'Ended'
    x=a[2].indexOf(';');
    y=a[2].search(/[0-2][0-9]:[0-9][0-9]/);
    a[2]=a[2].substr(0,x)+'; Ended '+a[2].substr(y);
    wtb1.value=a.join('===');
    if(location.href.indexOf('&rfa=rfaf')!=-1)
    {
      //failed
      //Add rfaf
      wtb1.value='{'+'{subst:rfaf}}'+wtb1.value;
      //Auto-summary
      document.getElementById('wpSummary').value='Closed, not promoted.';
      //Open normal view of Wikipedia:Unsuccessful adminship candidacies
      window.open('http://en.wikipedia.org/wiki/Wikipedia:Unsuccessful adminship candidacies','_blank');
    }
    else
    {
      //passed
      //Add rfap
      wtb1.value='{'+'{subst:rfap}}'+wtb1.value;
      //Auto-summary
      document.getElementById('wpSummary').value='Closed, promoted.';
      //Open edit view of Recently created admins (NOTE: THIS NEEDS CHANGING IF THAT PAGE IS RENAMED)
      window.open('http://en.wikipedia.org/wiki/Wikipedia:Recently created admins?action=edit','_blank');
    }
    // Open RfA's edit view in a new window
    window.open('http://en.wikipedia.org/wiki/Wikipedia:Requests for adminship?action=edit','_blank');
  }
});
// </nowiki></pre>