User:Whobot/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('[^:]*://en\\.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/~kate/cgi-bin/count_edits?dbname=enwiki&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 + '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( 'Kate\'s Tool' ) ); // eh, the css makes the text lowercase a.href = 'http://tools.wikimedia.de/~kate/cgi-bin/count_edits?dbname=enwiki&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 );

// - // Übergodmode Monobook skin // (c) 2005 Sam Hocevar  // $Id: ubergodmode.js 886 2005-05-14 23:56:48Z sam $ // -

// - // Language support // - var blocklink = 'Block this user'; switch (document.getElementsByTagName('html')[0].lang) { case 'fr': blocklink = 'Bloquer cet utilisateur'; break; }

// - // Our nice Block functions // - function PerformBlock { var l, target = ''; // Look for '&faketarget=XXX' in URL url = location.pathname; l = location.search.substring(1).split('&'); for (i = 0; i < l.length; i++) { var n = l[i].indexOf('='); if (l[i].substring(0, n) == 'faketarget') { target = l[i].substring(n + 1); } }  if (!target) return; form = document.getElementById('blockip'); if (!form) return; input = form.getElementsByTagName('input')[0]; input.value = target; }

// - // Add block buttons to the page // - function AddBlockButtons { var l, article = '', vandal; // Add 'block' links to a diff page l = document.getElementById('t-contributions'); if (l) { clone = l.cloneNode(true); l.id = 't-blockuser'; a = clone.getElementsByTagName('a')[0]; a.href = a.href.replace(/Special:Contributions\//, 'Special:Blockip/'); a.href = a.href.replace(/target=/, 'faketarget='); a.innerHTML = blocklink; l.parentNode.insertBefore(clone, l.nextSibling); } }

// - // Modify the page once it is loaded // - if (window.addEventListener) { window.addEventListener("load", PerformBlock, false); window.addEventListener("load", add_tabs, false); window.addEventListener("load", AddBlockButtons, false); add_tabs } else if (window.attachEvent) { window.attachEvent("onload", PerformBlock); window.attachEvent("onload", AddBlockButtons); window.attachEvent("onload", add_tabs); }

// // Auto-AFD closer (copied from GraemeL //

/**** 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; }

/**** 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; }

function closevfd(bold, notbold){ var form = document.editform; var txt = form.wpTextbox1; txt.value = "
 * The following discussion is an archived debate of the proposed deletion of the article below. Please do not modify it. Subsequent comments should be made on the appropriate discussion page (such as the article's talk page or in a deletion review).  No further edits should be made to this page.  

The result of the debate was " + bold + "" + notbold + ". --&laquo;&raquo; Who? &iquest; ? meta 03:57, 24 November 2005 (UTC)\n" + txt.value + "\n
 * ''The above discussion is preserved as an archive of the debate. Please do not modify it. Subsequent comments should be made on the appropriate discussion page (such as the article's talk page or in a deletion review). No further edits should be made to this page. \n";

form.wpSummary.value = "Close discussion: " + bold + notbold; form.wpWatchthis.checked = false; }

function add_tabs { var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; var username=document.getElementById("pt-userpage").textContent;

if(document.title.indexOf("Editing Wikipedia:Articles for deletion") != -1){                    // AfD tabs addlimenu(tabs, 'AfD close actions', 'afda'); var afda = document.getElementById('afda').getElementsByTagName('ul')[0]; addlilink(afda, 'javascript:closevfd("Delete", "")', 'Delete', ''); addlilink(afda, 'javascript:closevfd("Speedy Delete", "")', 'SD', ''); addlilink(afda, 'javascript:closevfd("Keep", "")', 'Keep', ''); addlilink(afda, 'javascript:closevfd("Keep (No consensus)", "")', 'Keep, NC', ''); addlilink(afda, 'javascript:closevfd("Merge and Redirect", " to " + prompt("Merge and redirect to?") + "")', 'M&R', ''); addlilink(afda, 'javascript:closevfd("Redirect", " to " + prompt("Redirect to?") + "")', 'Redirect', ''); addlilink(afda, 'javascript:closevfd("Transwiki", " to " + prompt("Transwiki to?"))', 'Transwiki', ''); addlilink(afda, 'javascript:closevfd("Transwiki", " to Wiktionary")', 'WIKT', ''); addlilink(afda, 'javascript:closevfd(prompt("Result?"), "")', 'Other', ''); }

if (document.title.indexOf('User:') == 0     || document.title.indexOf('User talk:') == 0) { 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 "arin" tab tabs.appendChild(addlilink('javascript:arin_look("' + editlk + '")', 'Arin')); }

}

// - // Arin functions // - function arin_look(target) { window.open('http://ws.arin.net/whois/?queryinput=' + target, 'Arin', 'width=600,height=400,top=400,left=0'); }