MediaWiki: Common.js

From happytrees.org
Jump to: navigation, 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.
/* Any JavaScript here will be loaded for all users on every page load. */

/* this adds categories to sidebar (requires mod to LocalSettings.php) */
var one = document.querySelector("#catlist");
if(typeof(one) != 'undefined' && one !== null){
  var children = document.querySelector("#catlinks").children;
  Array.prototype.forEach.call(children, function (child) {
      one.appendChild(child);
  });
}


/* add tag title to sidebar */
var catelement = document.getElementById("mw-normal-catlinks");
if(typeof(catelement) != 'undefined' && catelement !== null){
 	var cattar = document.getElementById("catlist");
 	if(typeof(cattar) != 'undefined' && cattar !== null){
 	    cattar.insertAdjacentHTML('beforebegin', '<div class="tags-b4-title">Tags:</div>');
 	}
}


/* add toc title to sidebar */
var element = document.getElementById("toc");
//If it isn't "undefined" and it isn't "null", then it exists.
if(typeof(element) != 'undefined' && element !== null){
	var target = document.getElementById("tweekiTOC");
	if(typeof(target) != 'undefined' && target !== null){
	  target.insertAdjacentHTML('beforebegin', '<div class="toc-b4-title">Table of contents:</div>');	
	}
}




/* remove ":" from sidebar category using jQuery */
// $('#mw-normal-catlinks').html(function(index, html){
    // return html.replace(':', 'xxxxxx');
// });

// change links href, causes errors on some pages
//document.getElementById('mw-normal-catlinks').innerHTML = document.getElementById('mw-normal-catlinks').innerHTML.replace("A",'asda');

// changes text but causes errors, removes links
//document.getElementById('mw-normal-catlinks').innerText = document.getElementById('mw-normal-catlinks').innerText.replace("A",'dfsdf');


// jquery
// $('#mw-normal-catlinks:contains("A")').text().replace("A", "dsdada")
//$("#mw-normal-catlinks").text($("#mw-normal-catlinks").text().replace("A", "Bye"));
// var $toptitle = $('#mw-normal-catlinks');
// if ( $toptitle.text() == 'A' ) // No {} brackets necessary if it's just one line.  
//   $toptitle.text('New Word');      


// causes errors
//document.getElementById('mw-normal-catlinks').innerContent = document.getElementById('mw-normal-catlinks').innerContent.replace("A",'dfsdf');
/* Add tagcloud to sidebar (requires mod to LocalSettings.php) */
// document.querySelector('.tagcloudbox').innerHTML = '<tagcloud>\nmin_size=55\nexclude=browse\n</tagcloud>\n';