User:Tentacle Monster/nostalgia.js

/* Utility functions. */

function addEvent(object, type, func) {	object.addEventListener(type, func, false); }

function addLoadEvent(func) {	addEvent(window, "load", func); }

/* Data. */

function createToolbar { var toolbarLinks = new Array; toolbarLinks["WatchList"] = "/wiki/Special:Watchlist"; toolbarLinks["MyPage"] = "/wiki/User:Philip_Nilsson"; toolbarLinks["RecentChanges"] = "/wiki/Special:Recentchanges"; var languageLinks = new Array; var categoryLinks = new Array;

var top = document.getElementById('topbar'); var footer = document.getElementById('footer');

var container = document.createElement('div'); var languageLinkCount = 0;

var links = top.getElementsByTagName('a'); for (key in links) { var link = links[key]; var hrefStr = new String(link.href); var linkText = link.innerHTML;

if (link.title == "Special:Userlogout") { toolbarLinks["LogOut"] = link.href; } else if (linkText == "Edit this page" || hrefStr.match(/=edit$/)) { toolbarLinks["EditPage"] = link.href; } else if (hrefStr.match(/=history$/)) { toolbarLinks["PageHistory"] = link.href; } else if (link.className == 'external') { languageLinkCount++; languageLinks[link.title] = [link.href, link.innerHTML]; } else if (hrefStr.match(/\/wiki\/Category:/)) { categoryLinks[link.innerHTML] = link.href; }	}	links = footer.getElementsByTagName('a'); for (key in links) { var link = links[key]; var hrefStr = new String(link.href); var linkText = link.innerHTML; if (link.title == "Special:Whatlinkshere") { toolbarLinks["WhatLinksHere"] = link.href; } else if (link.title == "Special:Movepage") { toolbarLinks["MovePage"] = link.href; } else if (link.title == "Special:Contributions") { toolbarLinks["UserContribs"] = link.href; } else if (hrefStr.match(/=watch$/)) { toolbarLinks["WatchPage"] = link.href; } else if (hrefStr.match(/=unwatch$/)) { toolbarLinks["UnwatchPage"] = link.href; } else if (linkText == "Discuss this page" /*hrefStr.match(/\/wiki\/Talk:/)*/) { toolbarLinks["DiscussPage"] = link.href; // main:, User:, Wikipedia: } else if (linkText == "View article" || linkText == "View user page" || linkText == "View project page") { toolbarLinks["ViewArticle"] = link.href; }/* else if (linkText == "Discuss this page" && hrefStr.match(/\/wiki\/User_talk:/)) { toolbarLinks["UserTalk"] = link.href; }*/	}

var strongs = top.getElementsByTagName('strong'); for (key in strongs) { if (strongs[key].parentNode == top) { // Hardcoded :p toolbarLinks["NewMessage!"] = "/wiki/User_talk:Philip_Nilsson"; }	}

// Links. var list = document.createElement('ul'); for (key in toolbarLinks) { var listItem = document.createElement('li'); var link = document.createElement('a'); link.setAttribute("href", toolbarLinks[key]); link.appendChild(document.createTextNode(key)); listItem.appendChild(link); list.appendChild(listItem); }

var dl = document.createElement('dl'); // Categories. var dt = document.createElement('dt'); dt.appendChild(document.createTextNode("Categories:")); dl.appendChild(dt); for (key in categoryLinks) { var listItem = document.createElement('dd'); var link = document.createElement('a'); link.href = categoryLinks[key]; link.appendChild(document.createTextNode(key)); listItem.appendChild(link); dl.appendChild(listItem); }

// Languages. var dt2 = document.createElement('dt'); dt2.appendChild(document.createTextNode("Languages:")); dl.appendChild(dt2); dl.id = 'languageLinks'; if (languageLinkCount > 5) { dt2.addEventListener('click',			function {				var temp = document.getElementById('languageLinks').getElementsByTagName('dd');				for (key in temp) {					var ent = temp.item(key);					if (ent.className == 'languageLink') {						if (ent.style.display == 'none') {							ent.style.display = 'block';						} else {							ent.style.display = 'none';						}					}				}			}, false); }	for (key in languageLinks) { var listItem = document.createElement('dd'); var link = document.createElement('a'); link.href = languageLinks[key][0]; link.title = languageLinks[key][1]; link.appendChild(document.createTextNode(key)); listItem.appendChild(link); listItem.className = "languageLink"; if (languageLinkCount > 5) { listItem.style.display = "none"; }		dl.appendChild(listItem); }

container.appendChild(list); container.appendChild(dl); container.appendChild(document.createElement('hr')); return container; }

/* Page functions. */ function setupmenu { var content = document.getElementById("content"); var article = document.getElementById("article");

content.insertBefore(document.getElementsByTagName('h1')[0], article); content.insertBefore(document.getElementById('specialpages'), article); content.insertBefore(createToolbar, article); }

// FIXME: Does not work. function dropdown { var select = document.getElementById('specialpages').childNodes.item(0); addEvent(select, "change",   function  {      document.getElementById('specialpages').submit;    }  ); }

addLoadEvent(setupmenu); addLoadEvent(dropdown);