User:C.m.jones/simple.js

/*
 * Add tab for Avatar's "CheckUsage", "block" and "purge"
 * Rename "página de usuário" to "utilizador"
 * Rename "minhas contribuições" to "contribuições"
 * Based on Duesentrieb's, Dbenbenn's and Essjay's monobook.js code.
 @author: Duesentrieb, [[User:Duesentrieb/monobook.js]], Dbenbenn, [[User:Dbenbenn/monobook.js]], Essjay [[User:Essjay/monobook.js]], ABCD [[User:ABCD/monobook.js]], JesseW [[User:JesseW/monobook.js]]
 @license: Dual licensed under the GFDL and GPL
 */

// Returns <li><a href="url">name</a></li>
function addlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

// Gets the URL version of the page title.
function get_tidy_title()
{
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  // cut everything up to "title=" from the start and everything past "&action=edit" from the end
  editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));

  return editlk;
}

// Tab for Avatar's CheckUsage
function add_image_tabs()
{
  var imagetitle = get_tidy_title();

  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

//  tabs.appendChild(addlilink('http://en.wikipedia.org/wiki/' + imagetitle, 'en'));
  tabs.appendChild(addlilink('http://www.juelich.de/avatar/check-usage/check-usage.php?filename=' + imagetitle + '&template', 'check-usage'));

  tabs.appendChlid(addlilink('1', '1'));
  imagetitle = imagetitle.substring(6, imagetitle.length());
  tabs.appendChlid(addlilink('2', '2'));


  var i = 0;
  while (imagetitle[i] >= '1' && imagetitle[i] <= '9')
    i++;
  tabs.appendChlid(addlilink(imagetitle + ' ' + i, imagetitle + ' ' + i));
  if (i > 0 && imagetitle.substring(3) == 'px-') {
    imagetitle = imagetitle.substring(i + 3, imagetitle.length());
    tabs.appendChild(addlilink('http://commons.wikimedia.org/wiki/Image:' + imagetitle, 'unthumb'));
  }
}

// Adds "purge" tab to pages.
function add_purge_tab()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // use the "edit this page" tab to get already-tidied url
  var editlk = get_tidy_title();
  var editlko = get_tidy_title();

  editlk = editlk.substring(editlk.indexOf(':') + 1);
  var slloc = editlk.indexOf('/');
  if (slloc > 0)
    editlk = editlk.substring(0, slloc);

  // add "purge" tab
  tabs.appendChild(addlilink('/w/index.php?title=' + editlko + '&action=purge', 'A'));
}

function do_onload()
{
  var title = get_tidy_title();
  if (document.title.indexOf('Image:') == 0
      || document.title.indexOf('Imagem:') == 0)
  {
    add_image_tabs();
  }

  add_purge_tab();
}

if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);

if ( document.createElement && window.addEventListener )
{
	function SoFixItInit() // pre-load
	{

	}

	function SoFixItLoad() // post-load
	{
		UserMenu = new PortletMenu( 'p-personal'   );
		PageMenu = new PortletMenu( 'p-cactions'   );
		 NavMenu = new PortletMenu( 'p-navigation' );
		//ToolMenu = new PortletMenu( 'p-tb'         );

			//	This is inefficient and not particularly robust.
			//	This comes first, I want this link to come up as
			//	fast as possible.
			//
		function GetByClass( sElem, sClass )
		{	var i, a2 = [], a = document.getElementsByTagName( sElem );
			for ( i = 0; i < a.length; i++ )
				if ( a[ i ].className == sClass )
					a2.push( a[ i ] );
			return a2;
		}
		var a, td = GetByClass( 'td', 'diff-otitle' );
		if ( ( td = td[ 0 ] ) && ( a = td.getElementsByTagName( 'a' )[ 0 ] ) )
			a.href = a.href + '&action=edit'; // need to change text, later

		var userName = UserMenu.getText( 'pt-userpage' );
		UserMenu.setText( 'pt-mycontris'  , 'Contribuições' );
		PageMenu.setText( 'ca-nstab-user' , 'Utilizador'    );

		var x = 1;
		UserMenu.insertBefore( 'pt-watchlist', 'njs-pt-watchlist-en', 'en', 'http://en.wikipedia.org/wiki/Special:Watchlist' );
		NavMenu.append( 'n-' + x++, 'Esplanada', '/w/index.php?title=Wikipedia%3AEsplanada&amp;action=purge' );
	}
	function PortletMenu( id ) // constructor
	{
		this.menu = document.getElementById( id );
		this.list = this.menu.getElementsByTagName( 'ul' )[ 0 ]; // bypass "<h5>Views</h5>", etc.

			//	sigh...as far as I can figure, there is empty whitespace being treated
			//	as TextNodes....
			//
		var LIs = this.list.getElementsByTagName( 'li' );

		for ( var i = 0; i < LIs.length; i++ )
		{
			this[ LIs[ i ].id ] = LIs[ i ];
		}

		this.newItem = function( id, txt, url )
		{	var li = document.createElement( 'li' ); li.id   = id;
			var  a = document.createElement( 'a'  );  a.href = url;

			 a.appendChild( document.createTextNode( txt ) );
			li.appendChild( a );

			this[ id ] = li; // watch this!!!

			return li;
		}

		this.append = function( id, txt, url )
		{	this.list.appendChild( this.newItem( id, txt, url ) );
		}
		
		this.insertBefore = function( old, id, txt, url )
		{	this.list.insertBefore( this.newItem( id, txt, url ), this[ old ] );
		}

			//	the ByTagName here is a bit annoying, but in Safari, I was picking
			//	up TextNodes by using this[ id ].firstChild.firstChild
			//
		this.getText = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data }
		this.setText = function( id, txt ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data = txt }

		this.getHref = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].href       }
		this.setHref = function( id, url ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].href = url }
	}
	SoFixItInit();
	window.addEventListener( 'load', SoFixItLoad, false );
}

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.