User:Villahj Ideeut/Blocklistscript.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

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

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
// <nowiki>


if (document.implementation.createDocument) {
  var gml_xmlparser = new DOMParser();
}

function gml_XMLParse(string) {
  if (document.implementation.createDocument) {
    string = fixXML(string, false);
    return gml_xmlparser.parseFromString(string, "text/xml");
  } else if (window.ActiveXObject) {
    var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    gml_xmldoc.async = "false";
    string = fixXML(string, false);
    ret = gml_xmldoc.loadXML(string);      
    if (!ret)
      return null;
    return gml_xmldoc.documentElement;
  }
  return null;
}

function addlilink(tabs, url, name, id) {
    var na = document.createElement('a');
    na.href = url;
    na.id = id;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

function addBlockList() {
  if(wgPageName.indexOf("Blocklist") == -1) 
    return;

  var listPage = prompt("Page of list of IPs to block: ","");

  blockFromList(listPage);
}

var gml_xmlhttp;

function HTTPClient() {
  var gml_http;
  if(window.XMLHttpRequest) {
    gml_http = new XMLHttpRequest();
    gml_http.overrideMimeType("text/plain"); //Force to be parsed as plain text, not conforming to any standard.
  } else if (window.ActiveXObject) {
    try {
      gml_http = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        gml_http = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        gml_http = false;
      }
    }
  }
  return gml_http;
}

var curDate = Date().substr(4,6);

var updateDate = 0;

var page;

var comment;

var redirect;

var QVFDPage = "Uncyclopedia:QuickVFD";

function debugOutput(str,nl) {
    document.getElementById('bodyContent').innerHTML += str;
    if(nl > 0)
        document.getElementById('bodyContent').innerHTML += "<br />";
}
function debugStatus(i) {
    if(i == 0)
        debugOutput("<span style='color: red; font-weight: bold;'> [FAILED]</span>",1);
    else
        debugOutput("<span style='color: green; font-weight: bold;'> [OK]</span>",1);
}
function blockFromList(listPage) {
     document.getElementById('bodyContent').innerHTML = 'Running Block List v(Too lazy to come up with a version # atm). Depending on the number of IPs on the list, this could take a very long time.';

     gml_xmlhttp = HTTPClient();
     if (!gml_xmlhttp) return;
     debugOutput("Opening List Page...");
     try {
        gml_xmlhttp.open('GET', wgServer + wgScriptPath + '/index.php?' + 'title=' + listPage + '&action=edit' + '&section=1' + '', true);
     } catch(e) {
        debugStatus(0);
        return;
     }
     debugStatus(1);
     gml_xmlhttp.onreadystatechange = getListAsArray;
     gml_xmlhttp.send(null);
}
function getListAsArray() {
    location.href = "#top";
    if(gml_xmlhttp.readyState != 4) return;
    
    debugOutput("Getting document object...",0);
    doc = gml_XMLParse(gml_xmlhttp.responseText);    
    if(!doc) {
        debugStatus(0);
        return;
    }
    debugStatus(1);
    var listDiv = doc.getElementById('listStart');
    var Lines = listDiv.innerText.split(" ");
    alert(Lines[0]);
    alert(Lines[1]);
}
/*
function QVFDUpdate() {
    location.href = "#top";
    var form, newform, l;
    if (gml_xmlhttp.readyState != 4) return;
    debugOutput("Retrieving document object...",0);
    doc = gml_XMLParse(gml_xmlhttp.responseText);
    if(!doc) {
        debugStatus(0);
        return;
    }
    debugStatus(1);
    debugOutput("Checking QVFD for selected page...",0);
    if(doc.getElementById('bodyContent').innerHTML.indexOf(wgPageName.replace(/_/g,' ')) == -1 && doc.getElementById('bodyContent').innerHTML.indexOf("=" + wgPageName + "&amp") == -1) {
        debugOutput(" page <b>not</b> listed",1);
    }
    else {
        debugOutput(" page <b>already</b> listed.",1);
        return;
    }
    debugOutput("Retrieving edit form...");
    form = doc.getElementById('editform');
    if(!form || !form.wpTextbox1) {
        debugStatus(0); 
        return;
    }
    var lines = form.wpTextbox1.value.split('\n');
    if (redirect == 0) {
       lines.splice(1,0,' [[:' + page.replace(/_/g,' ') + ']]' + comment);
    }
    else {
       lines.splice(1,0,' {{redirect|' + page.replace(/_/g,' ') + '}}' + comment);
    };
    form.wpTextbox1.value = lines.join('\n');
    newform = document.createElement('form');
    l = form.getElementsByTagName('textarea');
    for (i = l.length; i--;) {
      var a = document.createElement('input');
      a.type = 'hidden';
      a.name = l[i].name;
      a.value = l[i].value;
      newform.appendChild(a);
    }
    l = form.getElementsByTagName('input');
    for (i = l.length; i--;) {
      if (l[i].name == 'wpSummary') {
        l[i].value = '+[[' + page.replace(/_/g,' ') + ']]';
      } else if (l[i].name == 'wpMinoredit') {
        l[i].value = '0';
      } else if (l[i].name == 'wpWatchthis') {
        if (!l[i].checked)
          continue;
        l[i].value = "on";
      } else if (l[i].name == 'wpPreview') {
        continue;
      } else if (l[i].name == 'wpDiff') {
        continue;
      }
      l[i].type = 'hidden';
      newform.appendChild(l[i]);
    }
    newform.name = form.name;
    newform.method = form.method;
    newform.id = form.id;
    newform.action = form.action;
    document.getElementById('bodyContent').innerHTML += '<br />Submitting form...';
    document.getElementById('bodyContent').appendChild(newform);
    // Submit the form
    newform.submit();
}
*/

  
addOnloadHook(addBlockList);
// </nowiki>