User:Phoenix/monobook.js

function setCookie(c_name, value, expiredays) { var exdate = new Date; exdate.setDate(exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString); } function getCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); }	}	return ""; } var ajaxPages = new Array("Special:RecentChanges"); var ajaxRCOverride = false; var rcRefresh = 20000; function ajaxRC { appTo = $(".firstHeading"); appTo.append('   AUTO-REFRESH:   '); $("#autoRefreshToggle").click(function {		setCookie("ajaxRC", $("#autoRefreshToggle").is(":checked") ? "on" : "off")		loadRCData	}); $("#autoRefreshProgress").hide; if (getCookie("ajaxRC") == "on" || ajaxRCOverride) { $("#autoRefreshToggle").attr("checked", "checked"); setTimeout("loadRCData;", rcRefresh); } } function loadRCData { if (!$("#autoRefreshToggle").is(":checked")) return; $('#autoRefreshProgress').show $(article).load(location.href + " " + article + " > *", function (data) {		$(article + " .mw-collapsible").makeCollapsible;		$('#autoRefreshProgress').hide		if ($("#autoRefreshToggle").is(":checked")) setTimeout("loadRCData;", rcRefresh);	}); } $(function {	article = "#bodyContent";	for (x in ajaxPages) {		if (wgPageName == ajaxPages[x] && $("#autoRefreshToggle").length == 0) ajaxRC;	} });

function addInfoTab { //do things mw.util.addPortletLink(		'p-cactions', 		wgScript + "?title=" + wgPageName + "&action=info",		'Info',		'ca-info',		'Information and statistics about this page',		'i',		document.getElementById('ca-history').nextSibling	);

//fix the excessively stupid visual bug document.getElementById('ca-info').parentNode.insertBefore(document.createTextNode("\n"), document.getElementById('ca-info'));

//if this is the info page, highlight it	if (wgAction == "info") { document.getElementById('ca-info').className += "selected"; }

}

addOnloadHook( addInfoTab );

if (document.getElementsByClassName("mw-special-Recentchanges").length >= 0) { var lists = document.getElementsByClassName("mw-special-Recentchanges")[0] .getElementsByClassName("special");

for (var i = 0; i < lists.length; i++) { var listitems = lists[i].getElementsByTagName("li"); for (var j = 0; j < listitems.length; j++) { processListItem(listitems[j]); } } }

function processListItem (item) { var firstLinkRef = item.getElementsByTagName("a")[0].getAttribute("href"); if (firstLinkRef == "/Special:Log/block") { processBlockLog(item); } else if (firstLinkRef == "/Special:Log/delete") { processDeleteLog(item); } else if (firstLinkRef == "/Special:Log/move") { processMoveLog(item); } else if (firstLinkRef == "/Special:Log/protect") { processProtectLog(item); } }

function processBlockLog(item) { var pageTitle; var children = item.childNodes; for (var i = 0; i < children.length; i++) { if (children[i].data == " blocked ") { pageTitle = children[i + 1].innerHTML; break; } }  var logevent = document.createElement("span") logevent.setAttribute("class", "mw-logevent-actionlink"); logevent.appendChild(document.createTextNode(" (")); var link = document.createElement("a");  link.appendChild(document.createTextNode("unblock"));  link.setAttribute("title", "Special:Unblock/" + pageTitle);  var hrefTarget = "/Special:Unblock/"  hrefTarget += encodeURIComponent(pageTitle);  link.setAttribute("href", hrefTarget);  logevent.appendChild(link);  logevent.appendChild(document.createTextNode(" | "));  link = document.createElement("a");  link.appendChild(document.createTextNode("change block"));  link.setAttribute("title", "Special:Block/" + pageTitle);  var hrefTarget = "/Special:Block/"  hrefTarget += encodeURIComponent(pageTitle);  link.setAttribute("href", hrefTarget);  logevent.appendChild(link);  logevent.appendChild(document.createTextNode(")")); item.appendChild(logevent); }

function processDeleteLog(item) { var pageTitle; var children = item.childNodes; for (var i = 0; i < children.length; i++) { if (children[i].data == " deleted page ") { pageTitle = children[i + 1].getAttribute("href").split("=")[1].split("&")[0]; break; } }  var logevent = document.createElement("span") logevent.setAttribute("class", "mw-logevent-actionlink"); logevent.appendChild(document.createTextNode(" (")); var link = document.createElement("a");  link.appendChild(document.createTextNode("view/restore"));  link.setAttribute("title", "Special:Undelete");  var hrefTarget = "/index.php?title=Special:Undelete&target=";  hrefTarget += encodeURIComponent(pageTitle);  link.setAttribute("href", hrefTarget);  logevent.appendChild(link);  logevent.appendChild(document.createTextNode(")")); item.appendChild(logevent); }

function processMoveLog(item) { var oldTitle; var newTitle; var children = item.childNodes; for (var i = 0; i < children.length; i++) { if (children[i].data == " moved page ") { newTitle = encodeURIComponent(children[i + 1].getAttribute("href").split("=")[1].split("&")[0]); oldTitle = encodeURIComponent(children[i + 3].getAttribute("href").substr(1)); break; } }  var logevent = document.createElement("span") logevent.setAttribute("class", "mw-logevent-actionlink"); logevent.appendChild(document.createTextNode(" (")); var link = document.createElement("a");  link.appendChild(document.createTextNode("revert"));  link.setAttribute("title", "Special:MovePage");  var hrefTarget = "/index.php?title=Special:MovePage&wpOldTitle=";  hrefTarget += oldTitle;  hrefTarget += "&wpNewTitle=";  hrefTarget += newTitle;  hrefTarget += "&wpReason=revert&wpMovetalk=0";  link.setAttribute("href", hrefTarget);  logevent.appendChild(link)  logevent.appendChild(document.createTextNode(")")); item.appendChild(logevent); }

function processProtectLog(item) { var dateString; var pageTitle; var children = item.childNodes; for (var i = 0; i < children.length; i++) { if (i == 0) { var date = new Date(children[i]); dateString = date.getFullYear; dateString += (date.getMonth + 1); dateString += date.getDate; dateString += date.getHours; dateString += date.getMinutes; dateString += date.getSeconds; }   if (children[i].data == " changed protection level for \"") {      pageTitle = children[i + 1].getAttribute("href").substr(1);      break;    }  }  var logevent = document.createElement("span")  logevent.setAttribute("class", "mw-logevent-actionlink");  logevent.appendChild(document.createTextNode(" ("));  var link = document.createElement("a");  link.appendChild(document.createTextNode("hist"));  link.setAttribute("title", pageTitle);  var hrefTarget = "/index.php?title="  hrefTarget += encodeURIComponent(pageTitle);  hrefTarget += "&action=history&offset="  hrefTarget += date;  link.setAttribute("href", hrefTarget);  logevent.appendChild(link);  logevent.appendChild(document.createTextNode(" | "));  link = document.createElement("a");  link.appendChild(document.createTextNode("change"));  link.setAttribute("title", pageTitle);  var hrefTarget = "/index.php?title="  hrefTarget += encodeURIComponent(pageTitle); hrefTarget += "&action=protect" link.setAttribute("href", hrefTarget); logevent.appendChild(link); logevent.appendChild(document.createTextNode(")")); item.appendChild(logevent); }