User:Villahj Ideeut/QVFD.js

From Uncyclopedia, the content-free encyclopedia

Jump to: navigation, 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 = fixWikiaBugs(string);
    return gml_xmlparser.parseFromString(string, "text/xml");
  } else if (window.ActiveXObject) {
    var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    gml_xmldoc.async = "false";
    string = fixWikiaBugs(string);
    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 addQVFD() {
  //If there's no history, page isn't QVFD-able...
  if (document.getElementById('ca-history')) {
     var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
     var title = document.title;
     var i = title.indexOf(" - Uncyclopedia");
     var pagename = title.substring(0, i);
     addlilink(tabs, 'javascript:QVFD("' + pagename + '")', 'QVFD', 'td-qvfd');
  };
}
 
var gml_xmlhttp;
 
function HTTPClient() {
  var gml_http;
  if(window.XMLHttpRequest) {
    gml_http = new XMLHttpRequest();
  } 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 QVFDPage = "Uncyclopedia:QuickVFD";
 
function debugOutput(str) {
    document.getElementById('bodyContent').innerHTML += str + '<br />';
}
function QVFD(PageToQVFD) {
     document.getElementById('bodyContent').innerHTML = 'Running... <br /><br />';
     debugOutput("Called...");
      gml_xmlhttp = HTTPClient();
      if (!gml_xmlhttp)
        return;
     page = PageToQVFD;
     debugOutput("Opening Page...");
//   if(netscape)
//      netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
     try {
        gml_xmlhttp.open('GET', wgServer + wgScriptPath + '/index.php?' + 'title=' + QVFDPage + '&action=edit' + '&section=1' + '', true);
     } catch(e) {
        debugOutput("Could not open page!");
        return;
     }
     gml_xmlhttp.onreadystatechange = QVFDUpdate;
     gml_xmlhttp.send(null);
}
function QVFDUpdate() {
    var form, newform, l;
    if (gml_xmlhttp.readyState != 4) return;
    doc = gml_XMLParse(gml_xmlhttp.responseText);
    form = doc.getElementById('editform');
    var lines = form.wpTextbox1.value.split('\n');
    lines.splice(1,0,' [[' + page + ']]');
    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;
      } else if (l[i].name == 'wpMinoredit') {
        l[i].value = '1';
      } 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();
}
 
function fixWikiaBugs(text)
{
   var footer1 = text.indexOf('<div id="footer">');
   var footer2 = text.lastIndexOf('</div>');
   if (footer1 != -1 || footer2 != -1) var text = text.substring(0, footer1) + text.substring(footer2 + 6);
 
//   var ads1 = text.indexOf('<!-- PATCH: Begin addons -->');
//   var ads2 = text.indexOf('<!-- END addons -->');
//   if (ads1 != -1 || ads2 != -1) var text = text.substring(0, ads1) + text.substring(ads2);
 
   return text;
}
 
addOnloadHook(addQVFD);
// </nowiki>
Personal tools
projects