User:Tdxiang/monobook.js

From Wikipedia, the free encyclopedia

Note: After saving, you have to bypass your browser's cache to see the changes. Mozilla/Safari: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Internet Explorer: press Ctrl-F5, Opera/Konqueror: press F5.

// [[User:Lupin/popups.js]]

document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

/* <pre><nowiki> */
//////////////////////////////////
// [[User:Essjay]]'s monobook.  //
//////////////////////////////////

// Please note: This is a non-sysop, non-bureaucrat, and non-checkuser version of my .js    //
//              If you're looking for sysop, bureaucrat, or checkuser fuctions, please see  //
//              User:Essjay/monobook.js   All settings                                      // 
//              User:Essjay/sysop/monobook.js   Sysop settings only                         //
//              User:Essjay/bureaucrat/monobook.js   Bureaucrat & Sysop settings            //
//              User:Essjay/checkuser/monobook.js   Checkuser & Sysop settings                                                                      //

/**** Initialize on window load ****/

addOnloadHook( myLoadFuncs );

/**** Load custom functions ****/

function myLoadFuncs()
{
    if(!document.getElementById) return;
    // add a clock
    var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
    addlilink(toplinks, '#', '', 'utcdate');
    showtime();
    morelinks();
}

/**** Add generic tab ****/

function addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

//////////////////////////////////////////
// Tabs by Korath
// returns <li><a href="url">name</a></li>
//////////////////////////////////////////
/**** Add tab as menu ****/

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '#';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

/**** Get a clock that autoupdates! ****/

function showtime()
{
    var timerID;
    var now = new Date();
    var timeValue = now.toUTCString().replace(/GMT/, "UTC");
    document.getElementById('utcdate').firstChild.innerHTML = timeValue;
    timerID = setTimeout('showtime()', 100);
}

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


function morelinks()
{
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
if(document.title.indexOf("User") == 0)
    {
        addlimenu(tabs, 'User', 'userf');
        var userf = document.getElementById('userf').getElementsByTagName('ul')[0];

             //User functions //

        var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
            editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));
            editlk = editlk.substring(editlk.indexOf(':') + 1);
            var slloc = editlk.indexOf('/');
            if(slloc > 0) editlk = editlk.substring(0, slloc);
        
        // format: addlilink(userf, url, name);
        
        // add "listusers" tab
        addlilink(userf, '/w/index.php?title=Special:Listusers&group=&username=' + editlk, 'list', '');

        // add "contributions" tab
        addlilink(userf, '/wiki/Special:Contributions/' + editlk, 'contrib', '');
        // addTab('/wiki/Special:Contributions/' + editlk, 'con');
        
        // add "userspace" tab
        addlilink(userf, '/w/index.php?title=Special:Prefixindex&namespace=2&from=' + editlk, 'space', '');

        // add "edit count" tab
        addlilink(userf, 'http://tools.wikimedia.de/~essjay/edit_count/Count.php?username=' + editlk, 'count', '');
        // addTab('http://tools.wikimedia.de/~essjay/edit_count/Count.php?username=' + editlk, 'count');
        
        // add "whois" tab
        addlilink(userf, 'http://tools.wikimedia.de/~essjay/nqt.php?queryType=arin&target=' + editlk, 'whois', '');
        // addTab('http://tools.wikimedia.de/~essjay/nqt.php?queryType=arin&target=' + editlk, 'who');
        
        // add "proxycheck" tab
        addlilink(userf, 'http://quyme.com/proxycheck.php?ip=' + editlk, 'proxy', '');
        // addTab('http://quyme.com/proxycheck.php?ip=' + editlk, 'proxy');

        // add "url" tab
        addlilink(userf, 'http://' + editlk, 'url', '');
        // addTab('http://' + editlk, 'url');

        // add "blocklog" tab
        addlilink(userf, '/wiki/Special:Log/block?page=User:' + editlk, 'log', '');
        // addTab('/wiki/Special:Log/block?page=User:' + editlk, 'log', 'ca-blocklog');

     
}

function do_onload()
{
 if (document.title.indexOf('Block user') == 0) // could stand to be more robust
    do_blockip_stuff();
}

//From User:Func
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, (don't want to slow down loading of article's content, though)
	{

	}

	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' );

			// personal (top-most) menu
			//
			//		
			//
		UserMenu.setText( 'pt-mytalk'     , 'Talk'  );
		UserMenu.setText( 'pt-preferences', 'Prefs' );
		UserMenu.setText( 'pt-watchlist'  , 'Watchlist' );
		UserMenu.setText( 'pt-mycontris'  , 'Contribs' );
		UserMenu.setText( 'pt-logout'     , 'Log out'   );
			//
		UserMenu.setHref( 'pt-mycontris',
			'http://en.wikipedia.org/w/index.php?title=Special:Contributions&target=' +
			userName + '&offset=0&limit=500' );
			//
			//
			//		
		
			//	article-actions menu, (the "tabs")
			//
		if ( PageMenu[ 'ca-history' ] ) // theory: if it has a history tab, then it's purgable
		{
			PageMenu.insertBefore( 'ca-history', 'ca-lastdiff', 'diff',
				PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'diff=0' ) );

			PageMenu.append( 'ca-purge', 'Purge',
				PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'action=purge' ) );
							//Shorten tab names //
                        PageMenu.setText( 'ca-nstab-user' , 'user' );
                        PageMenu.setText( 'ca-talk' , 'talk' );
                        PageMenu.setText( 'ca-edit'     , 'edit'   );
                        PageMenu.setText( 'ca-history'     , 'history'   );
                        PageMenu.setText( 'ca-delete'     , 'delete'   );
                        PageMenu.setText( 'ca-watch'     , 'watch'   );
                        PageMenu.setText( 'ca-protect'     , 'protect'   );

		}

		var x = 1;
		NavMenu.append( 'n-' + x++, 'Monobook.js', '/wiki/User:' + userName + '/monobook.js' );
		NavMenu.append( 'n-' + x++, 'Interiot', 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?user=Essjay&dbname=enwiki_p' );

	}

	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 }
		
		//	I add em as I need em....
	}

	function RemoveNode( id )
	{	var node = document.getElementById( id )
		node.parentNode.removeChild( node );
	}

	SoFixItInit();
	window.addEventListener( 'load', SoFixItLoad, false );
}

// Do useful thinks on Special:Log/newusers //

function NUPatrol()
{
	if (	( window.location.href.indexOf( 'Special%3ALog&type=newusers' ) == -1 ) &&
			( window.location.href.indexOf( 'Special:Log/newusers'        ) == -1 )  )
	return; // make more robust???

	var items, item, i, links, user, name, talk, contribs, insertLoc, link;

	items = document.getElementById( 'bodyContent' ).getElementsByTagName( 'ul' )[ 0 ].getElementsByTagName( 'li' );

	function NewLink( txt, url, plainlinks, linkColor )
	{	var a = document.createElement( 'a' );
			a.appendChild( document.createTextNode( txt ) );
			a.href = url;
		if ( plainlinks ) a.className = 'plainlinks';
		if ( linkColor )
		{	if ( typeof linkColor == "string" )
					a.style.color = linkColor;
			else	a.style.color = '#FF0000'; // old default behavior
		}
		return a;
	}

	for ( i = 0; i < items.length; i++ )
	{
		item = items[ i ];
		
		links = item.getElementsByTagName( 'a' );

			user = links[ 0 ]; name = user.firstChild.nodeValue;
			talk = links[ 2 ]; talk.firstChild.nodeValue = 'talk'; // lowercase 'Talk' for consistency
		contribs = links[ 3 ];

		insertLoc = user.nextSibling; // ' newusers '

		item.insertBefore( document.createTextNode( ' ( ' ), insertLoc );

		item.insertBefore( talk, insertLoc );
		item.insertBefore( document.createTextNode( ', ' ), insertLoc );

		item.insertBefore( contribs, insertLoc );
		item.insertBefore( document.createTextNode( ', ' ), insertLoc );

		item.insertBefore( NewLink( 'actions', '/w/index.php?title=Special%3ALog&user=' + name, true, '#000088' ), insertLoc );
		item.insertBefore( document.createTextNode( ', ' ), insertLoc );

		item.insertBefore( NewLink( 'blocks', '/w/index.php?title=Special%3ALog&type=block&page=User%3A' + name, true, '#008800' ), insertLoc );
		item.insertBefore( document.createTextNode( ', ' ), insertLoc );

		item.insertBefore( NewLink( 'is blocked?', '/wiki/Special:Ipblocklist?action=search&ip=' + name, true, '#888800' ), insertLoc );
		item.insertBefore( document.createTextNode( ', ' ), insertLoc );

		item.insertBefore( NewLink( 'do block!', '/w/index.php?title=Special:Blockip&ip=' + name, true, '#880000' ), insertLoc );

		item.insertBefore( document.createTextNode( ' )' ), insertLoc );

		item.removeChild( insertLoc.nextSibling ); // should remove the span
		item.removeChild( insertLoc ); // should remove ' newusers ' text
	}
}

if ( window.addEventListener ) window.addEventListener( 'load', NUPatrol, false );
else if ( window.attachEvent ) window.attachEvent( 'onload', NUPatrol );

function inc (file) {
  var lt = String.fromCharCode(60);
  var gt = String.fromCharCode(62);
  document.writeln(lt+'script type="text/javascript" src="/w/index.php?title='+file+'&amp;action=raw&amp;ctype=text/javascript&amp;dontcountme=s"'+gt+lt+'/script'+gt);
}

inc("User:Essjay/statuschanger.js");

//Interiot's Java //

document.write('<script type="text/javascript" src="' 
    + 'http://en.wikipedia.org/w/index.php?title=User:Interiot/Tool2/code.js' 
    + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

// Unwatch Links //

addOnloadHook(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);
    }
});

//Death to editing on redlinks //

function stopRedlinksEditing(){ 
    var len=document.links.length;
    for(var i=0; i<len; ++i) {
        var l=document.links[i];
        if (l.className=='new') {
            l.href=l.href.replace('&action=edit', '');
        }
    }
}
addOnloadHook(stopRedlinksEditing); 
}

// </nowiki></pre> //