User:Titoxd/monobook.js

// //

// Useful stuff from WikiProject_User_scripts

function addToolboxLink(url, name, id){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; addlilink(tb, url, name, id); }

function addlilink(tabs, url, name, id, title, key){ var na = document.createElement('a'); na.href = url; na.appendChild(document.createTextNode(name)); var li = document.createElement('li'); if(id) li.id = id; li.appendChild(na); tabs.appendChild(li); if(id) { if(key && title) ta[id] = [key, title]; else if(key)    ta[id] = [key, '']; else if(title)  ta[id] = ['', title]; } // re-render the title and accesskeys from existing code in wikibits.js  akeytt; return li; }

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

function addPurge{ ta['ca-purge'] = ['g', 'Purge the internal cache for this page']; var x = document.getElementById('ca-history'); if(!x) return; if(x.children) x = x.children[0].href; else x = x.childNodes[0].href; addTab(x.replace(/=history/, "=purge"), 'purge', 'ca-purge'); akeytt; }

// culled from User:Lupin/popups.js

function nichalp_articleFromURL(h) { if (typeof h != 'String') h=String(h); h=decodeURI(h); var m=RegExp('[^:]*://es\\.wikipedia\\.org/(wiki/|w/index\\.php\\?title=)([^&?]*)').exec(h); if(m===null) return null; return m[2]; }

function nichalp_isIpUser(user) { return RegExp('(User:)?' +                '((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}' +                 '(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])') .test(user); }

function nichalp_removeAnchor(article) { // is there a #? if not, we're done var i=article.indexOf('#'); if (i == -1) return article; return article.substring(0,i); }

function nichalp_userName(article) { var i=article.indexOf('User'); var j=article.indexOf(':'); if (i != 0 || j == -1) return null; var k=article.indexOf('/'); if (k==-1) return article.substring(j+1); else return article.substring(j+1,k); }

// do it

function nichalp_customLinks { addPurge; var article=nichalp_articleFromURL(document.location.href); if (!article) return; var user=nichalp_userName(article); if(!user) return; user=nichalp_removeAnchor(user); if (!nichalp_isIpUser(user)) { addToolboxLink('http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwikinews&user='+user, user+"'s edit count", 'toolbox_katestool'); } var special='http://en.wikipedia.org/w/index.php?title=Special:'; addToolboxLink(special + 'Log&user='+user, user+"'s log", 'toolbox_userlog'); addToolboxLink(special + 'Blockip&ip='+user, 'Block '+user, 'toolbox_blockuser'); addToolboxLink(special + 'Ipblocklist&action=unblock&ip='+user, 'Unblock '+user, 'toolbox_unblockuser'); }

// make it all happen on page load

if (window.addEventListener) window.addEventListener("load",nichalp_customLinks,false); else if (window.attachEvent) window.attachEvent("onload",nichalp_customLinks); else { window._old_nichalp_onload = window.onload; window.onload = function { window._old_nichalp_onload; nichalp_customLinks; } }

// Add a "Kate" link to your monobook "personal menu" list at the very // top of the page. // // Indicate where you would like "Kate" to appear: //   pt-userpage, pt-mytalk, pt-preferences, //   pt-watchlist, pt-mycontris, pt-logout // gsKateInsertBefore = 'pt-mycontris'; // leave blank to append after "logout"

function KateLink {  var user = document.getElementById( 'pt-userpage').firstChild.firstChild.data; var li = document.createElement( 'li' ); li.id = 'pt-kate'; var a = document.createElement( 'a' ); a.appendChild( document.createTextNode( 'Interiot\'s Tool' ) ); // eh, the css makes the text lowercase a.href = 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwikinews_p&user=' + user;

li.appendChild( a ); if ( ! gsKateInsertBefore ) // append to end (right) of list {     document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); }  else {      var before = document.getElementById( gsKateInsertBefore ); before.appendChild( li, before ); } } if ( window.addEventListener ) window.addEventListener( 'load', KateLink, false ); else if ( window.attachEvent ) window.attachEvent( 'onload', KateLink );

// //