User:ScribeOfTheNile/monobook.js
From Wikipedia, a free encyclopedia written in simple English for easy reading.
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror:: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences.
/*
* Few personal modifications by [[en:User:ScribeOfTheNile]]
* Original author and licensing information preserved below
**
* 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()
{
if (!document.getElementById('ca-edit') && !document.getElementById('ca-viewsource')) {
return false;
}
if (document.getElementById('ca-edit')) {
var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
} else if (document.getElementById('ca-viewsource')) {
var editlk = document.getElementById('ca-viewsource').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;
}
// Adds "contribs" tabs to User: and User talk: pages.
function add_contribs_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();
editlk = editlk.substring(editlk.indexOf(':') + 1);
var slloc = editlk.indexOf('/');
if (slloc > 0)
editlk = editlk.substring(0, slloc);
// add the tab
tabs.appendChild(addlilink('/wiki/Special%3AContributions/' + editlk, 'contributions'));
}
// 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://www.juelich.de/avatar/check-usage/check-usage.php?filename=' + imagetitle + '&template', 'check usage'));
tabs.appendChild(addlilink('http://commons.wikimedia.org/wiki/' + imagetitle, 'commons'));
}
// 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', 'purge'));
}
function do_onload()
{
var title = get_tidy_title();
if (document.title.indexOf('Image:') == 0)
{
add_image_tabs();
}
if (document.title.indexOf('User:') == 0
|| document.title.indexOf('User talk:') == 0
|| document.title.indexOf('Editing User:') == 0
|| document.title.indexOf('Editing User talk:') == 0)
{
add_contribs_tab();
}
//only show purge tab on non-special pages?
if (document.getElementById('ca-history')) {
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' );
// 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' );
}
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 );
}

