Jump to content

User:Misza13/Scripts/StubSorting

From Wikipedia, the free encyclopedia

//

//STUB SORTING FUNCTIONS

function TagAsStub (stubname) {
  //TODO: add some real content here (but that's trivial actually with Lupin's popups' autoediting)
  alert("This article would get tagged with {{"+stubname+"}}.");
}

var stub_xmlhttp;
var StubDiv;
var StubLog;

function LoadStubMenu1 () {
  //Create the <div> which will hold all related stuff...
  var content = document.getElementById('content');
  StubDiv = document.createElement('div');
  StubDiv.style.padding = "10px";
  content.insertBefore(StubDiv,content.firstChild);
  StubLog = document.createElement('div');
  StubDiv.appendChild(StubLog);
  //Fetch the tools...
  StubLog.innerHTML = 'Fetching stubs...';
  stub_xmlhttp = HTTPClient();
  if (!stub_xmlhttp) return;
  stub_xmlhttp.open('GET', 'http://en.wikipedia.org/w/index.php?title=User:Misza13/StubList', true);
  stub_xmlhttp.onreadystatechange = LoadStubMenu2;
  stub_xmlhttp.send(null);
}

function LoadStubMenu2 () {
  if (stub_xmlhttp.readyState != 4) return;
  StubLog.innerHTML += ' done.<br/>Linkifying...';
  // Hack for a MediaWiki bug
  stub_xml = stub_xmlhttp.responseText.replace(/<body.*"ns-4">/, '<body class="ns-4">');
  stub_doc = gml_XMLParse(stub_xml);
  var stublist = stub_doc.getElementById('StubList_div');
  StubDiv.appendChild(stublist);

  LIs = document.evaluate(
    "//*[@class='stubLI']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
  for (i = 0; i < LIs.snapshotLength; i++) {
    li = LIs.snapshotItem(i);
    textNode = li.firstChild;
    linkRegex = /(.*)\|(.*)/;
    data = linkRegex.exec(textNode.textContent);
    A = document.createElement('a');
    A.href = 'javascript:TagAsStub("'+data[1]+'");';
    A.appendChild(document.createTextNode(data[2]));
    li.replaceChild(A,textNode);
  }

  StubDiv.removeChild(StubLog);
  //Remove the button
  var stubloader = document.getElementById('stubloader');
  stubloader.parentNode.removeChild(stubloader);
}

$(function(){
  var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
  addlilink(tabs,'javascript:LoadStubMenu1()','Load stub types','stubloader');
});
//