User:Wayoshi/monobook.js

From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*
<pre><nowiki>
*/

function addTab(id, after, caption, url) {
  if (!document.getElementById(id)) {
    var edit = document.getElementById(after);
    if (!edit) return; //If the previous tab doesn't exist, don't add this one
    var editparent = edit.parentNode;
    var aseclinkcaption = document.createTextNode(caption)
    var aseclink = document.createElement('a');
    aseclink.setAttribute('href',url);
    var addsectionlinkcaption = aseclink.appendChild(aseclinkcaption);
    var asec = document.createElement('li');
    asec.setAttribute('id',id);
    var addsectionlink = asec.appendChild(aseclink);
    var addsection = editparent.insertBefore(asec,edit.nextSibling);
  }
}

function addEditSection() {
	var arti = wgPageName;
	addTab("ca-addsection", 'ca-edit', '+', wgScriptPath+"/index.php?title="+escape(arti)+"&action=edit&section=new");
	addTab("ca-editfirst" , 'ca-edit', '0', wgScriptPath+"/index.php?title="+escape(arti)+"&action=edit&section=0");
}
if (window.addEventListener) window.addEventListener("load",addEditSection,false);
else if (window.attachEvent) window.attachEvent("onload",addEditSection);
function addEditSection() {
	var arti = wgPageName;
	addTab("ca-addsection", 'ca-edit', '+', wgScriptPath+"/index.php?title="+escape(arti)+"&action=edit&section=new");
	addTab("ca-editfirst" , 'ca-edit', '0', wgScriptPath+"/index.php?title="+escape(arti)+"&action=edit&section=0");
}
if (window.addEventListener) window.addEventListener("load",addEditSection,false);
else if (window.attachEvent) window.attachEvent("onload",addEditSection);

// credit: http://en.wikipedia.org/wiki/User:Alex_Smotrov/histcomb.js

var histComb = new function(){
 
if (!window.histCombMyBg) histCombMyBg = '#77beea'
if (!window.histCombTalk) histCombTalk = 't'
if (!window.histCombContrib) histCombContrib = 'c'
 
var pagehis, histRow, histSize, isCombEdits = false
 
 
this.onLoad = function(){
 
 if (!(pagehis = document.getElementById('pagehistory'))) return
 histRow = pagehis.getElementsByTagName('li')
 histSize = new Array (histRow.length)
 //histSumm = new Array (histRow.length)
 var row, spans, i, aa, author, author_p = '',  size_digits  
 var sameAuthor = 0, thisMinor, allMinor = true
 
 for (var rr=histRow.length-1; rr>=0; rr--){ //main loop: bottom to top
  row = histRow[rr]
  thisMinor = false
  spans = row.getElementsByTagName('span')
  //check all spans
  for (i=0; i<spans.length; i++) 
    switch (spans[i].className){
    case 'history-size':
      size_digits = spans[i].innerHTML.match(/\d+/g)
      histSize[rr] = size_digits ? size_digits.join('') : '0'
      if (histSize[rr+1]){ 
        spans[i].title = spans[i].innerHTML.replace(/&nbsp;/g,' ')
        insertDiffValue(spans[i], histSize[rr] - histSize[rr+1])
      }
      break
    case 'minor':
      thisMinor = true
      break
    case 'history-user': // get user name and shorten talk/contribs
      aa = spans[i].getElementsByTagName('a')
      author = aa[1].title.split(':')[1]
      aa[1].innerHTML = histCombTalk 
      if (aa.length >= 3 && (aa[2].title.indexOf(':Contributions/') != -1)) //for anons this could be 'block'
        aa[2].innerHTML = histCombContrib 
      break
    case 'mw-history-undo':
      aa = spans[i].getElementsByTagName('a')[0]
      aa.title = aa.innerHTML 
      aa.innerHTML = '×'
      break
    //case 'comment':  histSumm = spans[i].innerHTML  break 
    }//end switch inside for 
 
    if (!histSize[rr] && histSize[rr+1]) histSize[rr] = histSize[rr+1] //assume it was '(un)protect' edit
 
  if (wgUserName == author) histRow[rr].style.backgroundColor = histCombMyBg
  //check how many consequent edits
  if (author == author_p) 
    sameAuthor++
  else {
    if (sameAuthor > 1) createCombineEdit(rr+1, sameAuthor, allMinor)
    sameAuthor = 1 
    author_p = author
    allMinor = thisMinor
  }
  if (!thisMinor) allMinor = false
 }//main loop
 if (sameAuthor>1) createCombineEdit(0, sameAuthor, allMinor)
 
 if (isCombEdits) { //add all expand/collapse link
   var togAll = document.createElement('a')
   togAll.appendChild(document.createTextNode('[±]'))
   togAll.href = 'javascript:histComb.toggleAll()'
   //togAll.style.marginLeft = '0.2em'
   pagehis.parentNode.insertBefore(togAll, pagehis.previousSibling)   
 }
 
 //bonus: link to toоlserver
 var lnk = document.createElement('a')
 lnk.style.marginLeft = '20px'
 lnk.href = 'http://www.mariowiki.com/index.php?title=Special%3AContributors&target='+encodeURIComponent(wgPageName)
 lnk.appendChild(document.createTextNode('Contributors'))
 lnk.title = 'All authors sorted by edits (on toolserver)'
 if (i=document.getElementById('contentSub')) i.appendChild(lnk)
 
 
}
 
 
this.toggleAll = function(){
 var links = getElementsByClassName(pagehis, 'a', 'collapsedEdits')
 for (var i=0; i<links.length; i++)
   if (isCombEdits != (links[i].innerHTML == '[–]'))
     eval(links[i].href)
 isCombEdits = ! isCombEdits
}
 
 
this.toggle = function (m, len, isMinor){ //handler for collapsing link
 var row = histRow[m]
 var spans = row.getElementsByTagName('span')
 var plus = row.lastChild
 var radios = row.getElementsByTagName('input')
 var diffLastLnk = row.getElementsByTagName('a')[ m > 0 ? 1 : 0] // "last" link
 var i, oldid, clss
 var isHiding = (plus.innerHTML == '[–]')
 if (isHiding) {//need to collapse −
   plus.innerHTML = '[' + len + ']'
   row.style.borderLeft = '1px solid transparent'
   //hide other rows
   for (i=m+1; i<m+len; i++) histRow[i].style.display = 'none'
   //get values for left radio button and "diff from last"  link from the lowest collapsed edit
   radios[0].value = histRow[m+len-1].getElementsByTagName('input')[0].value
   diffLastLnk['old'] = diffLastLnk.href
   oldid = histRow[m+len-1].getElementsByTagName('a')[1].href.match(/oldid=(\d+)/)[1]
   diffLastLnk.href = diffLastLnk.href.replace(/&oldid=\d+/, '&oldid='+oldid)
 }else{ //need to expand
   plus.innerHTML = '[–]'
   //show other rows and visually reference the whole group
   row.style.borderLeft = '1px dotted gray'
   for (i=m+1; i<m+len; i++){
     histRow[i].style.display = 'block'
     histRow[i].style.borderLeft = '1px dotted gray'
     histRow[i].style.listStyle = 'none none'
   }
   histRow[m+len-1].style.borderBottom = '1px dotted gray'
   //change back radio button and diff link
   radios[0].value = radios[1].value
   diffLastLnk.href = diffLastLnk['old']
 }
 //hide/show/modify spans in this row
 for (i=0; i<spans.length; i++)
   switch (spans[i].className.split(' ')[0]){
   case 'minor':
     spans[i].style.display = (isHiding && !isMinor)?'none':'inline'
     break
   case 'history-size': //switch to  combined diff size and back
     insertDiffValue(spans[i], histSize[m] - (isHiding ? histSize[m+len] : histSize[m+1]))
     break
   case 'comment': //hide/show
     spans[i].style.display = (isHiding && !window.histCombLeaveComment)?'none':'inline'
     break
   case 'mw-history-undo':
     var undoLnk = spans[i].getElementsByTagName('a')[0]
     if (isHiding) {
       undoLnk['old'] = undoLnk.href
       undoLnk.href = undoLnk.href.replace(/&undoafter=\d+/, '&undoafter='+oldid)
     }else
       undoLnk.href = undoLnk['old']
     break
   //case 'history-user':
 }
}
 
 
function createCombineEdit(m, len, isMinor){ //creates collapsing link for row m down to row m+len
 var row = histRow[m]
 row.style.listStyle = 'none none'
 row.style.position = 'relative'
 var plus = document.createElement('a')
 plus.className = 'collapsedEdits'
 plus.appendChild(document.createTextNode('[–]'))
 plus.style.position = 'absolute'
 plus.style.left = '-22px'
 plus.style.top = '2px'
 plus.href = 'javascript:histComb.toggle('+m+','+len+','+isMinor+')'
 row.appendChild(plus)
 histComb.toggle(m, len, isMinor) //and collapse
 isCombEdits = true
}
 
 
function insertDiffValue(span, value){
 var html, class2
 if (value>0) {
  html = '(+' + value + ')'
  class2 = ' mw-plusminus-pos'
 } else if (value<0) {
  html = '(' + value + ')'
  class2 = ' mw-plusminus-neg'
 } else {
  html = '(0)'
  class2 = ' mw-plusminus-null'
 }
 span.style.fontWeight = (value < -500) ? 'bold' : 'normal'
 span.innerHTML = html
 span.className = span.className.split(' ')[0] + class2
}
 
}//obj
 
if (doneOnloadHook) histComb.onLoad()
else if (wgAction == 'history') addOnloadHook(histComb.onLoad)

// [[user:Where/usertabs]]
// This is a good one!
 
addOnloadHook(function() {
  if (wgTitle.indexOf("/") != -1 || document.title.indexOf("- History -") != -1)  //no subpages or history
     return;
  if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
     var username = encodeURIComponent( wgTitle );
     addPortletLink("p-cactions", "/index.php?title=Special:EditCount&target="+ username + "&doeditcount=Show+count", "edit count", "ca-editcount", "Get this user's edit count.");
     addPortletLink("p-cactions", wgServer + "/index.php?title=Special:Prefixindex&from=" + username + "&namespace=2", "userspace", "", "List of pages in this user's userspace");
  }
});

/******************************************
* Snow Effect Script- By Altan d.o.o. (http://www.altan.hr/snow/index.html)
* Visit Dynamic Drive DHTML code library (http://www.dynamicdrive.com/) for full source code
* Last updated Nov 9th, 05' by DD. This notice must stay intact for use
*****************************************
  
  //Configure below to change URL path to the snow image
  var snowsrc="http://img.photobucket.com/albums/v506/Kimi12715/MarioWiki/Snowflake.png"
  // Configure below to change number of snow to render
  var no = 5;
  // Configure whether snow should disappear after x seconds (0=never):
  var hidesnowtime = 0;
  // Configure how much snow should drop down before fading ("windowheight" or "pageheight")
  var snowdistance = "pageheight";

///////////Stop Config//////////////////////////////////

  var ie4up = (document.all) ? 1 : 0;
  var ns6up = (document.getElementById&&!document.all) ? 1 : 0;

	function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

  var dx, xp, yp;    // coordinate and position variables
  var am, stx, sty;  // amplitude and step variables
  var i, doc_width = 800, doc_height = 600; 
  
  if (ns6up) {
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
  } else if (ie4up) {
    doc_width = iecompattest().clientWidth;
    doc_height = iecompattest().clientHeight;
  }

  dx = new Array();
  xp = new Array();
  yp = new Array();
  am = new Array();
  stx = new Array();
  sty = new Array();
  snowsrc=(snowsrc.indexOf("dynamicdrive.com")!=-1)? "snow.gif" : snowsrc
  for (i = 0; i < no; ++ i) {  
    dx[i] = 0;                        // set coordinate variables
    xp[i] = Math.random()*(doc_width-50);  // set position variables
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;         // set amplitude variables
    stx[i] = 0.02 + Math.random()/10; // set step variables
    sty[i] = 0.7 + Math.random();     // set step variables
		if (ie4up||ns6up) {
      if (i == 0) {
        document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><a href=\"http://dynamicdrive.com\"><img src='"+snowsrc+"' border=\"0\"><\/a><\/div>");
      } else {
        document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
      }
    }
  }

  function snowIE_NS6() {  // IE and NS6 main animation function
    doc_width = ns6up?window.innerWidth-10 : iecompattest().clientWidth-10;
		doc_height=(window.innerHeight && snowdistance=="windowheight")? window.innerHeight : (ie4up && snowdistance=="windowheight")?  iecompattest().clientHeight : (ie4up && !window.opera && snowdistance=="pageheight")? iecompattest().scrollHeight : iecompattest().offsetHeight;
    for (i = 0; i < no; ++ i) {  // iterate for every dot
      yp[i] += sty[i];
      if (yp[i] > doc_height-50) {
        xp[i] = Math.random()*(doc_width-am[i]-30);
        yp[i] = 0;
        stx[i] = 0.02 + Math.random()/10;
        sty[i] = 0.7 + Math.random();
      }
      dx[i] += stx[i];
      document.getElementById("dot"+i).style.top=yp[i]+"px";
      document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
    }
    snowtimer=setTimeout("snowIE_NS6()", 10);
  }

	function hidesnow(){
		if (window.snowtimer) clearTimeout(snowtimer)
		for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
	}
		

if (ie4up||ns6up){
    snowIE_NS6();
		if (hidesnowtime>0)
		setTimeout("hidesnow()", hidesnowtime*1000)
		}
*/
/* </nowiki></pre> */