User:Whedonette/monobook.js

document.write('' +   ' .xdiff { width: 100%; background: white; }' +    ' .xdiff-row { width: 100%; margin: 0 0 3px 0; overflow: hidden; }' +    ' .xdiff-col { width: 49%; margin: 0; float: left; clear: none; position: relative; }' +    ' .xdiff-sign, .xdiff-outer, .xdiff-inner { display: block; margin: 0; }' +    ' .xdiff-sign { position: absolute; top: 0; left: 0; width: 2em; text-align: center; }' +    ' .xdiff-outer { padding: 0 0 0 2em; }' +    ' .xdiff-inner { overflow: auto; overflow-y: visible; width: 100%; }' +    ' .xdiff-inner.diff-addedline { font-size: 85%; background: #cfc; }' +    ' .xdiff-inner.diff-deletedline { font-size: 85%; background: #ffa; }' +    ' .xdiff-inner.diff-context { font-size: 85%; background: #eee; }' +    (!document.recalc ? '' : // IE kluge: ' * html .xdiff-inner { padding-bottom: expression(this.scrollWidth > this.offsetWidth ? "16px" : 0); }' + ' * html .xdiff-sign { top: expression((this.parentNode.clientHeight - this.offsetHeight)/2 + "px"); }') +   '<'+'/style>');

if (false) addOnloadHook(function { // OBSOLETE!!!    var diffSigns = new Array;    var fixDiffWidth = function  {        var tables = document.getElementsByTagName('table');

for (var i = 0; i < tables.length; i++) { if (tables[i].className != 'diff') continue; var rows = tables[i].getElementsByTagName('tr');

var diffDiv = document.createElement('div'); diffDiv.className = 'xdiff';

for (var j = 0; j < rows.length; j++) { var rowDiv = document.createElement('div'); rowDiv.className = 'xdiff-row';

var colDiv = null; var cols = rows[j].getElementsByTagName('td'); for (var k = 0; k < cols.length; k++) { if (!colDiv) { colDiv = document.createElement('div'); colDiv.className = 'xdiff-col'; rowDiv.appendChild(colDiv); }                   if (cols[k].getAttribute('colspan') == 2 || cols[k].className.substring(0,5) == 'diff-') { // use spans instead of divs so that an eventual non-js solution will look nice in lynx! var outerSpan = document.createElement('span'); var innerSpan = document.createElement('span'); outerSpan.className = 'xdiff-outer'; innerSpan.className = 'xdiff-inner ' + cols[k].className; innerSpan.style.textAlign = cols[k].getAttribute('align'); for (var node = cols[k].firstChild; node; node = node.nextSibling) innerSpan.appendChild(node.cloneNode(true)); innerSpan.appendChild(document.createTextNode(String.fromCharCode(0xa0))); // add nbsp outerSpan.appendChild(innerSpan); colDiv.appendChild(outerSpan); colDiv = null; // start new column }                   else if (cols[k].firstChild && (cols[k].firstChild.nextSibling || cols[k].firstChild.nodeType != 3 || cols[k].firstChild.nodeValue.match(/\S/))) { // use spans instead of divs so that an eventual non-js solution will look nice in lynx! var signSpan = document.createElement('span'); signSpan.className = 'xdiff-sign'; if (!signSpan.style.setExpression) diffSigns[diffSigns.length] = signSpan; for (var node = cols[k].firstChild; node; node = node.nextSibling) signSpan.appendChild(node.cloneNode(true)); colDiv.appendChild(signSpan); }               }                diffDiv.appendChild(rowDiv); }           tables[i].parentNode.replaceChild(diffDiv, tables[i]); }   };    // finally, a kluge to vertically center the +/- signs var centerDiffSigns = function { for (var i = 0; i < diffSigns.length; i++) { var parentHeight; if (!( parentHeight = diffSigns[i].parentNode )) continue; if (!( parentHeight = parentHeight.clientHeight )) continue; diffSigns[i].style.top = ((parentHeight - diffSigns[i].offsetHeight)/2) + "px"; }   };    fixDiffWidth; if (diffSigns.length) { hookEvent('resize', centerDiffSigns); setTimeout(centerDiffSigns, 250); } });

function addTab(url, name, id, title, key){ var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; return addlilink(tabs, url, name, id, title, key) };

function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) {       if(key && title) {           ta[id] = [key, title]; }       else if(key) {           ta[id] = [key, '']; }       else if(title) {           ta[id] = ['', title]; }   }    // re-render the title and accesskeys from existing code in wikibits.js    akeytt; return li; }

function addSinceTab { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if (window.location.href.indexOf("&action=history&gotosince=true")!=-1) { do_since_I_last_edited }   else if (!/wiki\/Special:|w\/index.php?title=Special:/.test(window.location.href)) { var thetitle=document.title.slice(0, String(document.title).indexOf(" - ")); var l=addlilink(tabs, "/w/index.php?title="+thetitle+"&action=history&gotosince=true", 'Since', ''); l.lastChild.title="Since"; } } function do_since_I_last_edited { var csub=document.getElementById("contentSub"); var msg=document.createElement("p"); msg.appendChild(document.createTextNode                       ("Parsing history... please wait...")); msg.className="error"; csub.insertBefore(msg, csub.firstChild)

var username=document.getElementById("pt-userpage").textContent; var hists=document.getElementById("pagehistory").getElementsByTagName('li'); for (n=0;n<hists.length;n++) { if (hists[n].getElementsByTagName("span")[0].getElementsByTagName('a')[0].textContent==username) { document.location=hists[n].childNodes[1].href; return; }       }

msg.replaceChild(document.createTextNode                        ("You have not edited this page! (recently)"),                         msg.firstChild); }

$(addSinceTab);

addOnloadHook(function {  if (document.title.search("/") != -1 || document.title.search("- History -") != -1) { //no subpages or history      return;   }   if (document.title.indexOf("User:") == 0 || document.title.indexOf("User talk:") == 0) {      username_a = document.URL.match(/:.*:(.*)/);      username=username_a[1];      addTab("http://en.wikipedia.org/wiki/Special:Contributions/" + username, "contrib", "ca-contrib", "contribs", "");      addTab("http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A" + username, "block log", "ca-blog", "blog", "");      addTab("http://tools.wikimedia.de/~interiot/cgi-bin/Tool1/wannabe_kate?site=en.wikipedia.org&username=" + username, "edit count", "ca-kate", "kate", "");      addTab("http://en.wikipedia.org/w/index.php?title=Special:Log&type=rights&page=User:" + username, "rights", "ca-rights", "rights", "");   } });

$(function {    var query_prefix = "title=Special:Watchlist&action=submit&remove=1&id[]=";    //var query_prefix = "action=unwatch&title=";

if (window.location.href.indexOf("Special:Watchlist") < 0) return; if (window.location.href.indexOf("Special:Watchlist/edit") >= 0) return;

var links = document.getElementById('content').getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { if (links[i].href.substring(links[i].href.length-15) != '&action=history') continue; var unwatch = document.createElement('a'); unwatch.href = "/w/index.php?" + query_prefix + encodeURIComponent(links[i].title); unwatch.title = "Unwatch "+links[i].title; unwatch.appendChild(document.createTextNode("unwatch")); links[i].parentNode.insertBefore(unwatch, links[i].nextSibling); // kluge to handle case where "diff" is unlinked: var delim = links[i].previousSibling; delim = (delim.nodeType == 3 ? delim.nodeValue : ""); links[i].parentNode.insertBefore(document.createTextNode(delim.replace(/^.*diff/, "")), unwatch); } });

function getPname { z=document.getElementById("content").childNodes; for (var n=0;n<z.length;n++) { if (z[n].className=="firstHeading") return z[n].textContent; }; }

function openAdahLinks(kk) { var as = document.getElementsByTagName('a'); var k = 0; for (n=0; n<as.length; n++) { if (as[n].innerHTML == 'diff') { if (k <= kk) { window.open(as[n].href, '_blank'); }     k++; } } }

function addAdahLinks { if (getPname == 'My watchlist') { var as = document.getElementsByTagName('a'); var k = 0; for (n=0; n<as.length; n++) { if (as[n].innerHTML == 'diff') { var tn = document.createTextNode(') ('); var link = document.createElement('a'); link.href = 'javascript:openAdahLinks(' + (k++) + ')'; link.appendChild(document.createTextNode('adah'), null); as[n].parentNode.insertBefore(tn, as[n].nextSibling.nextSibling); as[n].parentNode.insertBefore(link, as[n].nextSibling.nextSibling); }   }  } }

$(addAdahLinks);

function numToMonth(num) { if (num==0) {return "January";} else if (num==1) {return "February";} else if (num==2) {return "March";} else if (num==3) {return "April";} else if (num==4) {return "May";} else if (num==5) {return "June";} else if (num==6) {return "July";} else if (num==7) {return "August";} else if (num==8) {return "September";} else if (num==9) {return "October";} else if (num==10) {return "November";} else if (num==11) {return "December";} } function monthToNum(month) { var tmp = new Date(month + " 1, 2006"); return tmp.getMonth; } function adjustTime(str, hour, minute, day, month, year, offset, s) { var time = new Date; time.setUTCHours(hour); time.setUTCMinutes(minute); time.setUTCDate(day); time.setUTCMonth(monthToNum(month)); time.setUTCFullYear(year); var timeStr = ""; if (time.getHours<10) {timeStr += "0";} timeStr += parseInt(time.getHours) + ":"; if (time.getMinutes<10) {timeStr += "0";} timeStr += parseInt(time.getMinutes); timeStr += ", "; timeStr += time.getDate; timeStr += " "; timeStr += numToMonth(time.getMonth); timeStr += " "; timeStr += time.getFullYear; timeStr += " (CDT)"; // var offset = -1*time.getTimezoneOffset/60; // if (offset >= 0) {timeStr += "+";} // timeStr += offset + ")";   return timeStr; } function adjustTime2(str, hour, minute, month, day, year,  offset, s) {    return adjustTime(str, hour, minute, day, month, year, offset, s); } addOnloadHook(function { if (document.title.indexOf("Editing ") == 0) { return; }      if (document.location.href.indexOf("action=history") != -1) { return; }   if (document.title.indexOf("Talk:") == 0 || document.title.indexOf("talk:") != -1 || document.title.indexOf("Wikipedia:") == 0) { var newDoc = document.getElementById("column-content").innerHTML.replace(/(\d\d):(\d\d), (\d{1,2}) ([A-Z][a-z]+) (\d{4}) \(UTC\)/g, adjustTime); document.getElementById("column-content").innerHTML = newDoc; } /*  if (document.location.href.indexOf("&action=history") != -1) { var newDoc = document.getElementById("bodyContent").innerHTML.replace(/(\d\d):(\d\d), ([A-Z][a-z]+) (\d{1,2}), (\d{4})/g, adjustTime2); document.getElementById("bodyContent").innerHTML = newDoc; }*/ });

function externISBN {

var magicURL = "http://www.amazon.com/exec/obidos/ASIN/MAGICNUMBER"; var magicRegex = /MAGICNUMBER/ig; if(wgPageName != "Special:Booksources" && wgPageName != "Wikipedia:Book_sources"){ for (var i = 0; i < document.links.length; i++) {              if( document.links[i].href.match(/isbn=(.*)/) ) { document.links[i].href=magicURL.replace(magicRegex, RegExp.$1); }   }  } }

$(externISBN);

/**** afd helper ****/ document.write(' ');

/* This is to keep track of who is using this extension: User:Jnothman/afd_helper/script.js */