User:NxBot/vector.js

From RationalWiki
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
function gettoken_api() {
  var api = sajax_init_object();
  api.open('GET', wgServer + wgScriptPath + '/api.php?format=json&action=query&prop=info&indexpageids=1&intoken=edit&titles=Whatever', false);
  api.send(null);
  if(api.status==200) {
    var response = eval('(' + api.responseText + ')');
    var token = response['query']['pages'][response['query']['pageids'][0]]['edittoken'];
  } else {
    alert('The token query returned an error.');
  }
  return token;
}


function hotban(target)
{
  var req = sajax_init_object();
  req.open('POST', wgServer + wgScriptPath + '/index.php?title=Special:Block&action=submit&wpBlockAddress=' + encodeURIComponent(target) + '&wpBlockOther=1+day&wpAnonOnly=1&wpEnableAutoblock=1&wpCreateAccount=1&wpAllowUsertalk=1&wpBlockReasonList=other&wpBlockReason=Unfunny%20vandalism&wpEditToken=' + encodeURIComponent(gettoken_api()) , true);
  req.onreadystatechange = function() {
    if(req.readyState==4) {
      if(req.status==200) {
        alert('B&');
      } else {
        alert('Oh noes! ' + req.responseText);
      }
    }
  };
  req.send(null);
}

function qbonc(stuff,target)
{
  stuff.onclick = function() {hotban(target);}
}

function setuphotban() {
  var anchors = document.getElementsByTagName('a');
  for ( i in anchors ) {
    if (anchors[i].title != undefined && anchors[i].title.indexOf("Special:Block/") != -1) {
      target = anchors[i].title.substring(14,anchors[i].title.length);
      var qba = document.createElement('a');
      qba.innerHTML = "quick block";
      qba.style.cursor = "pointer";
      qbonc(qba,target);
      if (anchors[i].nextSibling == undefined) {
        anchors[i].parentNode.appendChild(document.createTextNode(" "));
        anchors[i].parentNode.appendChild(qba);
      } else {
        anchors[i].parentNode.insertBefore(qba,anchors[i].nextSibling);
        anchors[i].parentNode.insertBefore(document.createTextNode(" "),qba);
      }
    }
  }
}

addOnloadHook(setuphotban);