User:Skyld/monobook.js

/*Created by the Z. Credit here where due. You're welcome to do whatever you want with anything here. If you take something for use in your own scripts, I'd appreciate a mention, but it's not required. Bear in mind, however, that I   accept no responsibility for anything bad that might happen as a result of you using this. */ function getArticle(articleName) { /* This almost certainly assumes a Gecko-based browser, but, hey, such is life. */ var requestURL = "/wiki/" + articleName; var requestObject = new XMLHttpRequest; var articleObject; requestObject.onload = function { if (this.readyState == 4) { if (this.status == 200) { articleObject = this.responseXML; } else { articleObject = NULL; }  }  };  requestObject.open("GET", requestURL, false); // Wait for a response before we proceed requestObject.send(""); return articleObject; } function getCurrentArticleName { var thisURL = window.location.href; thisURL = thisURL.substring(24); if (thisURL.substring(0, 2) == "w/") { // Special page! return thisURL.match(/title\=[\w:\.\/]+/)[0].substring(6); } else if (thisURL.substring(0, 5) == "wiki/") { return thisURL.substring(5).split("?")[0]; } } function getUsersReferenced { var returnValue = new Array; var allLinks = document.getElementsByTagName("a"); for (i = 0; i < allLinks.length; i++) { if (allLinks[i].title.substring(0, 5) == "User:") { var userIdentifier = allLinks[i].title.substring(5).split("/")[0]; // This is an untidy trick to distinguish between, say, User:Fredbob and User:Fredbobvexatious var tmpJoined = "/" + returnValue.join("/") + "/"; if (tmpJoined.indexOf("/" + userIdentifier + "/") == -1) { returnValue[returnValue.length] = userIdentifier; }  }  }  return returnValue; } function getCurrentLanguage { return window.location.href.split(".")[0].substring(7); } function basicElement(type) { return document.createElement(type); } function linkElement(linkText, linkTarget) { var returnValue = basicElement("a"); returnValue.textContent = linkText; returnValue.href = linkTarget; return returnValue; } function wikilinkElement(linkText, linkTarget) { return linkElement(linkText, "http://" + getCurrentLanguage + ".wikipedia.org/wiki/" + linkTarget); } function subheaderElement(headerText) { var returnValue = basicElement("h5"); returnValue.textContent = headerText; return returnValue; } function textElement(text) { var returnValue = basicElement("span"); returnValue.textContent = text; return returnValue; } function listElement(entryElementArray) { var returnValue = basicElement("ul"); for (i = 0; i < entryElementArray.length; i++) { var tmp_i = basicElement("li"); tmp_i.appendChild(entryElementArray[i]); returnValue.appendChild(tmp_i); } return returnValue; } function jsPopElement(popText, popChildren) { var returnValue = basicElement("span"); var popLabel = basicElement("span"); popLabel.textContent = popText; var popPanel = basicElement("div"); popPanel.style.display = "none"; popLabel.onclick = function { popPanel.style.display = (popPanel.style.display == "block" ? "none" : "block"); }; for (i = 0; i < popChildren.length; i++) { popPanel.appendChild(popChildren[i]); } returnValue.appendChild(popLabel); returnValue.appendChild(popPanel); return returnValue; } function jsLinkElement(linkText, linkFunction) { var returnValue = basicElement("a"); returnValue.textContent = linkText; returnValue.href = "#"; returnValue.onclick = linkFunction; return returnValue; } function lazyCreate(type, cls, children) { var returnValue = basicElement(type); returnValue.className = cls; for (i = 0; i < children.length; i++) { returnValue.appendChild(children[i]); } return returnValue; } function oid { alert(getUsersReferenced); return false; } var sidebar; var addedPanelContent = listElement(new Array( textElement("This is a test"), linkElement("Google", "http://www.google.com"), jsPopElement("Ideologies...", new Array( listElement(new Array( wikilinkElement("Communism", "Communism"), wikilinkElement("Capitalism", "Capitalism"), wikilinkElement("Anarchism", "Anarchism") )),  jsLinkElement("Get the Nintendo article", function {    var article = getArticle("Nintendo");    alert(getArticle("Nintendo").getElementsByTagName("head")[0].getElementsByTagName("title")[0].textContent);    return false;   }) )) )); var addedPanel = lazyCreate("div", "pBody", new Array( addedPanelContent )); var panelContainer = lazyCreate("div", "portlet", new Array( subheaderElement("more"), addedPanel )); window.onload = function { /* The actual setup work goes inside this event because, before that, we can't be sure if the page has been appropriately rendered. */ sidebar = document.getElementById("column-one"); sidebar.appendChild(panelContainer); };