User:GregAsche/monobook.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
The accompanying .css page for this skin is at User:GregAsche/monobook.css. |
// [[User:Lupin/popups.js]] - please include this line
mw.loader.load(
'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s');
popupAdminLinks=true;
function RcHideUsers()
{
var li = document.getElementById( 'n-recentchanges' );
if ( ! li ) return; // sanity check
li.appendChild( document.createTextNode( ' ' ) );
var a = document.createElement( 'a' );
a.href = '/w/index.php?title=Special:Recentchanges&hideliu=1&limit=100';
a.appendChild( document.createTextNode( 'Hide' ) );
li.appendChild( a );
}
if ( window.addEventListener ) window.addEventListener( 'load', RcHideUsers, false );
else if ( window.attachEvent ) window.attachEvent( 'onload', RcHideUsers );
function addlilink(tabs, url, name){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
li.appendChild(na);
tabs.appendChild(li);
return 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;
}
// Adds a "blocklog" tab and fills in the username field on Special:Blockip, if a "&faketarget=username" is present.
function do_blockip_stuff()
{
// focus on Reason field
document.getElementsByName('wpBlockReason')[0].focus();
// Look for a &faketarget= for the username/ip
var l = location.search.substring(1).split('&');
var target = '';
for (var i = 0; i < l.length; ++i)
{
var n = l[i].indexOf('=');
if (l[i].substring(0, n) == 'faketarget')
{
target = l[i].substring(n + 1);
break;
}
}
if (target == '')
return;
// put account name in "IP Address/username" field
var addr = document.getElementsByName('wpBlockAddress')[0];
addr.value = unescape(target);
// add "blocklog" tab
var c1 = document.getElementById('column-one');
var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + target, 'blocklog'));
}
// Opens the block log in the current window, and Special:Blockip in a popup.
// Width, height, top, and left are chosen for a 1600x1200 display.
//function blockpage_and_log(target)
//{
// window.open('Special_Blockip.html?foo=blarg&faketarget=' + target, 'Block', 'width=1600,height=600,top=600,left=0');
// document.location.href = 'http://en.wikipedia.org/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + target;
//}
function arin_look(target)
{
window.open('http://ws.arin.net/whois/?queryinput=' + target, 'Arin', 'width=600,height=400,top=400,left=0');
}
// Adds "block" and "blocklog" tabs to User: and User talk: pages.
function add_block_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 = 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'));
editlk = editlk.substring(editlk.indexOf(':') + 1);
var slloc = editlk.indexOf('/');
if (slloc > 0)
editlk = editlk.substring(0, slloc);
// add "block" tab
tabs.appendChild(addlilink('/w/index.php?title=Special%3ABlockip&faketarget=' + editlk, 'block'));
// To open the block page and block log simultaneously, replace the above line with:
// tabs.appendChild(addlilink('javascript:blockpage_and_log("' + editlk + '")', 'Block'));
// and uncomment the blockpage_and_log() function above.
// add "blocklog" tab
tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&type=block&user=&page=User%3A' + editlk, 'blog'));
//add "contributions" tab
tabs.appendChild(addlilink('/w/wiki.phtml?title=Special:Contributions&target=User%3A' + editlk, 'contrib'));
// add "arin" tab
tabs.appendChild(addlilink('javascript:arin_look("' + editlk + '")', 'Arin'));
}
function do_onload()
{
if (document.title.indexOf('User:') == 0
|| document.title.indexOf('User talk:') == 0)
add_block_tab();
else if (document.title.indexOf('Block user') == 0) // could stand to be more robust
do_blockip_stuff();
document.getElementById('ca-edit').firstChild.innerHTML = 'edit';
document.getElementById('ca-talk').firstChild.innerHTML = 'talk';
}
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
//
// Func Talk Prefs Watch List Edits Kate Logs #IRC Out
//
UserMenu.setText( 'pt-mytalk' , 'Talk' );
UserMenu.setText( 'pt-preferences', 'Prefs' );
UserMenu.setText( 'pt-watchlist' , 'Watch' );
UserMenu.setText( 'pt-mycontris' , 'Edits' );
UserMenu.setText( 'pt-logout' , 'Out' );
//
UserMenu.setHref( 'pt-mycontris',
'http://en.wikipedia.org/w/index.php?title=Special:Contributions&target=' +
userName + '&offset=0&limit=500' );
//
//
// it seems there is a stylesheet that makes them lowercase
//
// ok, the lowercased menu items are starting to really bug me:
//
document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0].style.textTransform = 'none';
//
UserMenu.insertBefore( 'pt-mycontris', 'pt-list', 'List', '/wiki/Special:Watchlist/edit' );
UserMenu.insertBefore( 'pt-logout' , 'pt-logs', 'Logs',
'/w/index.php?title=Special%3ALog&user=' + userName );
UserMenu.insertBefore( 'pt-logs' , 'pt-kate', 'Kate',
'javascript:void InlineKate( "' + userName + '" )' );
// 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' ) );
}
var x = 1;
NavMenu.append( 'n-' + x++, 'WP:CP', '/wiki/Wikipedia:Copyright problems' );
NavMenu.append( 'n-' + x++, 'Newpages', '/wiki/Special:Newpages' );
}
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 InlineKate( user )
{
var kate =
'http://tools.wikimedia.de/~kate/cgi-bin/count_edits?user=GregAsche&dbname=enwiki';
var div = document.createElement( 'div' );
div.id = 'inlineKateDiv';
div.style.position = 'absolute';
div.style.zIndex = 1000;
div.style.left = '20px';
div.style.top = '20px';
div.style.backgroundColor = '#FFFFFF';
div.style.borderStyle = 'solid';
div.style.borderWidth = ' medium';
div.style.borderColor = '#000000';
var top = document.createElement( 'div' );
top.id = 'inlineKateTop';
top.style.textAlign = 'right';
top.style.margin = '8px';
top.style.backgroundColor = '#DDDDDD';
var a = document.createElement( 'a' );
a.appendChild( document.createTextNode( "Go to Kate's" ) );
a.href = kate;
a.target = '_parent';
a.style.margin = '8px';
top.appendChild( a );
a = document.createElement( 'a' );
a.appendChild( document.createTextNode( 'Close' ) );
a.href = "javascript:void RemoveNode('inlineKateDiv')";
a.style.margin = '8px';
top.appendChild( a );
div.appendChild( top );
var iframe = document.createElement( 'iframe' );
iframe.id = 'inlineKateBot';
iframe.style.width = '300px';
iframe.style.height = '400px';
iframe.style.margin = '8px';
iframe.style.borderStyle = 'solid';
iframe.style.borderWidth = 'thin';
iframe.style.borderColor = '#000000';
iframe.src = kate;
div.appendChild( iframe );
document.body.appendChild( div );
}
function RemoveNode( id )
{ var node = document.getElementById( id )
node.parentNode.removeChild( node );
}
function UTCTime()
{
// Get a date stamp for the time in UTC-land.
//
// for the future: a format arg
//
var s = '',
d = new Date(),
a = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');
return d.getUTCDate() + ' ' +
a[ d.getUTCMonth() ] + ' ' +
d.getUTCFullYear() + ' ' +
( '0' + d.getUTCHours() ).substr( -2 ) + ':' +
( '0' + d.getUTCMinutes() ).substr( -2 ) + ' ' + 'UTC';
}
SoFixItInit();
window.addEventListener( 'load', SoFixItLoad, false );
}