User:The Kitty :3/utilities.js

/* */

//execute functions on page load insertBeforeNum = 7; insertBeforeArr = new Array("","pt-userpage","pt-mytalk","pt-preferences","pt-watchlist","pt-mycontris","pt-logout",""); insertBefore = insertBeforeArr[insertBeforeNum]; window.onload = Main;

function Main { changelinks; addpurge; }

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

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

function vandal(tmplt) { var txt = document.editform.wpTextbox1; if(txt.value.length > 0) txt.value += '\n'; txt.value += ' ~'; txt.focus; txt = document.editform.wpSummary; txt.value = tmplt document.editform.wpWatchthis.checked = false; }

function replace { var s = prompt("Search regexp?"); if(s) { var r = prompt("Replace regexp?"); if(!r && r != '') return; var txt = document.editform.wpTextbox1; txt.value = txt.value.replace(new RegExp(s, "g"), r); } }

//change the 'personal links' function changelinks { if(!document.getElementById) return; mw.util.addPortletLink('p-personal', wgArticlePath.replace(/\$1/, 'User:The Kitty :3/monobook.js'),       'monobook', 'pt-monobook', 'monobook', null, document.getElementById('pt-logout')); mw.util.addPortletLink('p-personal', wgArticlePath.replace(/\$1/, 'Special:Recentchanges'),       'RC', 'pt-RC', 'Recent changes', null, document.getElementById('pt-logout')); mw.util.addPortletLink('p-personal', wgArticlePath.replace(/\$1/, 'Special:Newpages'),       'NP', 'NP', 'New pages', null, document.getElementById('pt-logout')) document.getElementById('pt-mytalk').firstChild.innerHTML = 'Talk '; document.getElementById('pt-preferences').firstChild.innerHTML = 'Prefs'; document.getElementById('pt-watchlist').firstChild.innerHTML = 'Watchlist'; document.getElementById('pt-mycontris').firstChild.innerHTML = 'Contribs'; document.getElementById('pt-logout').firstChild.innerHTML = 'Log out'; if(document.getElementById('ca-edit')) document.getElementById('ca-edit').firstChild.innerHTML = 'edit'; }

//adds the time beside the 'log out' link function makeTime { var li = document.createElement( 'li' ); li.id = 'pt-time';

var mySpan = document.createElement( 'span' ); mySpan.appendChild( document.createTextNode( 'date and time' ) );

li.appendChild( mySpan );

if ( insertBefore ) {   var before = document.getElementById( insertBefore ); before.appendChild( li, before ); } else // append to end (right) of list {   document.getElementById( 'pt-logout' ).parentNode.appendChild( li ); } getTime }

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

function getTime {   var time    = new Date; var date   = time.getUTCDate; var months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' '); month  = months[time.getUTCMonth]; var year   = time.getUTCFullYear; var hours  = '0' + time.getUTCHours; hours  = hours.substr(hours.length-2, hours.length); var minutes = '0' + time.getUTCMinutes; minutes = minutes.substr(minutes.length-2, minutes.length); var seconds = '0' + time.getUTCSeconds; seconds = seconds.substr(seconds.length-2, seconds.length); var curTime = hours + ":" + minutes + ":" + seconds; datePlace  = document.getElementById('pt-time').childNodes[0].childNodes[0]; datePlace.replaceData(0, datePlace.length, curTime); }

/* */