Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* <pre><nowiki> */
/**
 * [[User:Bookofjude]]'s monobook.js, based on primarily on [[User:Wayward]]'s, 
 * which in turn is based on [[User:Alphax/monobook.js]]'s
 * with many of [[User:Wayward]]'s own mods
 * Must use [[User:Wayward/monobook.css]] for full tab functionality
 * Forked from [[User:ABCD/monobook.js]] around April 2005
 * Dual licensed under the GFDL and GPL
 * See also: [[User:JesseW/monobook.js]]
 * And best of all: [[WP:US]]
 **/

/*** [[User:Lightdarkness]]'s include function ***/
function inc (file) {
  mw.loader.load('/w/index.php?title='+file+'&action=raw&ctype=text/javascript&dontcountme=s');
}

/*** Includes ***/
inc("User:Lupin/popups.js");

/*** Popups customisations, see [[Wikipedia:Tools/Navigation popups]] ***/
popupFixRedirs = true;
popupRedirAutoClick = 'wpPreview';
popupFixDabs = true;
popupStructure = 'menus';

/*** Hooks ***/
addOnloadHook(AddTime);
addOnloadHook(addPurge);
addOnloadHook(changeRecent);
addOnloadHook(changeLinks);
addOnloadHook(morelinks);
addOnloadHook(addToolBoxLinks);
addOnloadHook(addWatch);
addOnloadHook(akeytt);
addOnloadHook(addNavBarLinks);
addOnloadHook(addGoogle);
addOnloadHook(function (){
	if(document.title.indexOf("Confirm delete -") == 0) {
		var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
		addlilink(tabs, "javascript:csd('5 day old, undisputed prod')", 'prod')
	}
});
addOnloadHook(function () {
	if(document.forms.editform) {
		addLink('p-cactions', 'javascript:replace()', 'replace', 'ca-replace', 'Regexp replace for the edit window', '', 'ca-history');
	}
	});
addOnloadHook(function () {
  // Served by srv63 in 0.338 secs.
  // Served by ([^\\s]*) in ([0-9.]+*)
 var text = document.getElementsByTagName('html')[0].innerHTML.match(/Served by [^ ]* in [0-9.]* secs/);
 var toolbox = document.getElementById('p-tb').getElementsByTagName('ul')[0];
 addlilink (toolbox, '#', text);
});
addOnloadHook(function () {
if (document.getElementById('t-contributions')) {
	z=document.getElementById("content").childNodes;
	for (var n=0;n<z.length;n++) { 
		if (z[n].className=="firstHeading") var username = z[n].textContent.replace(new RegExp('User:([^/]*)', 'g'), '$1');
	};
	var toolbox = document.getElementById('p-tb').getElementsByTagName('ul')[0];
	addlilink(toolbox, '/w/index.php?title=Special:Log&user='+username, 'User Logs');
}});
function replace2(s, r) {
	if(s) {
		if(!r && r != '') return;
		var txt = document.editform.wpTextbox1;
		txt.value = txt.value.replace(new RegExp(s, "g"), r);
	}
}
function csd(text){
	var reason = document.getElementById('wpReason');
	reason.value = text;
        document.forms[0].wpConfirmB.click();
}
addOnloadHook(function () {
	if(document.forms.editform) {
		var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
		addlimenu(tabs, 'replace', 'replf');
		var replf = document.getElementById('replf').getElementsByTagName('ul')[0];
		addlilink(replf,"javascript:replace2('(\\n)','$1$1')",'Double whitespace', '');		
	}
	});


/*** GENERIC FUNCTIONS ***/

/**** Tabs and functions ****/
	
// Add test-n templates to user talk pages
function testn(number)
{
	var page = prompt("Vandalism to which article?")
	var f = document.editform, t = f.wpTextbox1;
	if (t.value.length > 0)
	t.value += '\n';
	t.value += "{{subst:" + number + "-n|" + page + "}} ~~~~";
	f.wpSummary.value = "Your edits to [[" + page + "]]"
	document.editform.wpWatchthis.checked = false; 
}
	
// Add duration for s/block by                                  
function duration(number)                                             
{                                                                    
	var duration = prompt("Block duration")                            
	var f = document.editform, t = f.wpTextbox1;                        
	if (t.value.length > 0)                                             
	t.value += '\n';                                                   
	t.value += "{{s/block2|signature=~~~~|time=" + duration + "}}";     
	f.wpSummary.value = "You have been blocked for " + duration + ""    
	document.editform.wpWatchthis.checked = false;                                                         
}
	

// appends msg to the currently editted page, sets the summary to summ,
// and marks or unmarks the "Watch this page" checkbox according to watch
function edit_summary_watch(msg, summ, watch)
{
	var f = document.editform, t = f.wpTextbox1;
	if (t.value.length > 0)
	t.value += '\n';
	t.value += msg;
	f.wpSummary.value = summ;
	f.wpWatchthis.checked = watch;
}
	
// Places perm block and name block tags at top of edit section,         
// and marks or unmarks the "Watch this page" checkbox according to watch  
function perm_name_block(msg, summ, watch)                                
{                                                                          
	var f = document.editform, t = f.wpTextbox1;                            
	if (t.value.length > 0)                                                
	t.value += '\n';                                                  
	var temp = t.value;                                                    
	t.value = msg;                                                         
	t.value += '\n\n';                                                     
	t.value += temp;                                                         
	f.wpSummary.value = summ;                                                
	f.wpWatchthis.checked = watch; 
}

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

/*** Gets a page name ***/
function getPname() {
  z=document.getElementById("content").childNodes;
  for (var n=0;n<z.length;n++) { 
    if (z[n].className=="firstHeading") return z[n].textContent;
  };
}
	
/*** Gets a username on userpages ***/

function getUname() {
	return document.URL.match(/:.*:(.*)/)[1];
}

/*** Adds something to the contentSub ***/
function addcsub(name, link)
{
	var csub = document.getElementById('contentSub');
	var csuba = document.createElement('a');
	csuba.href = link;
	csuba.appendChild(document.createTextNode(name));
	csub.appendChild(csuba);
	return csuba;
}

function addLink(where, url, name, id, title, key, after){
	//* where is the id of the toolbar where the button should be added;
	//   i.e. one of "p-cactions", "p-personal", "p-navigation", or "p-tb".
	//
	//* url is the URL which will be called when the button is clicked.
	//   javascript: urls can be used to do more complex things.
	//
	//* name is what will appear as the name of the button.
	//
	//* id is the id of the button; it's best to define one.  
	//   Use a prefix to make sure its unique. Optional.
	//
	//* title is the tooltip title that gives a longer description 
	//   of the button; if you define a accesskey, mention it here. Optional.
	//
	//* key is the char you want for the accesskey. Optional.
	//
	//* after is the id of the button you want to follow this one. Optional.
	//
	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);
	var tabs = document.getElementById(where).getElementsByTagName('ul')[0];
	if(after) {
		tabs.insertBefore(li,document.getElementById(after));
	} else {
		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 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);
	}
}
	
/**** 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;
}

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

/*** Add purge tab ***/
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];
	
	var pf = document.createElement('form');
	pf.action = '?action=purge';
	pf.method = 'POST';
	pf.id = 'pf';
	x.appendChild(pf);
	
	addlilink(tabs, 'javascript:document.getElementById("pf").submit();', 'purge', 'ca-purge');
}
	
/*** Add article watchlist tab ***/
function addWatch()
{
	if (!location.href.indexOf("Special:") == -1) {
	ta['ca-watchlist'] = ['u', 'Add this article to Wikibot watchlist'];
	if(!document.getElementById) return;
	var tabs = document.getElementById('p-cactions').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'));
	addlilink(tabs, 'http://192.168.0.64/rc.php?watchlist=' + editlk, 'watchlist', 'ca-watchlist', 'ca-watchlist');	
	}
}

/*** Add google tab ***/
function addGoogle() 
{
	var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
	addlilink(tabs, 'http://www.google.com.au/search?q=' + getPname(), 'google',  'ca-google', 'ca-google');
}
	
/*** Change recent changes link ***/
	
function changeRecent()
{
	var portlet = document.getElementById('n-recentchanges');
	portlet.innerHTML = "<a href=\"http://192.168.0.64/rc.php\">Recent changes</a>";
}

/*** Adds a link for the clock ***/
function AddTime() {
	var toplinks = document.getElementById('p-personal').getElementsByTagName('ul')[0];
	addlilink(toplinks, 'http://192.168.0.64/rc.php', 'Recent changes', '');
	addlilink(toplinks, '#', '', 'utcdate');
	showtime();
}

/*** Auto-updating clock ***/
function showtime() {
	var timerID;
	var now = new Date();
	var timeValue = now.toLocaleString().replace(/GMT/, "UTC");
        var timeValue2 = now.toUTCString().replace(/GMT/, "UTC");
	document.getElementById('utcdate').firstChild.innerHTML = timeValue + "<br>" + timeValue2;
	timerID = setTimeout('showtime()', 100);
}

/*** AFD FUNCTIONS ***/

/*** Add afd header, footer and comment ***/
function closeafd(bold, notbold)
{
	var txt = document.editform.wpTextbox1;
	txt.value = "{{subst:vt}} '''" + bold + "'''" + notbold + ". &ndash; ~~~~\n" + txt.value
	+ "\n{{subst:vb}}\n";
	txt = document.editform.wpSummary;
	txt.value = "close discussion: " + bold + notbold;
	document.editform.wpWatchthis.checked = false;
}
	
/*** Talk page AFD result ***/
function afdresult()
{
	var res = prompt("Result?");
	if(!res) return;
	var afddate = prompt("Nomination date?");
	document.editform.wpSummary.value = 'AFD result - ' + res.replace(/'/g, '');
	var txt = document.editform.wpTextbox1;
	if(txt.value.length > 0) txt.value += '\n';
	txt.value += '{{oldafdfull|date=[[' + afddate + ']] [[{{subst:CURRENTYEAR}}]]|result=' + res + '|votepage={{subst:PAGENAME}}}}';
	txt.focus();
}
	
/*** Make old AfD's appear or disappear ***/
	
function hideafd()
{
	var divs = document.getElementsByTagName("div");
	for(var x = 0; x < divs.length; ++x)
		if(divs[x].className.indexOf("vfd") != -1)
		divs[x].style.display = "none";
	document.getElementById('footer').style.display = 'none';
}
	
function showafd()
{
	var divs = document.getElementsByTagName("div");
	for(var x = 0; x < divs.length; ++x)
		if(divs[x].className.indexOf("vfd") != -1)
		divs[x].style.display = "";
	document.getElementById('footer').style.display = '';
}

/*** Not sure how this works ***/
	
function afddelete(){
	//    var form = document.forms.deleteconfirm;
	//    form.wpReason.value = '[[Wikipedia:Articles for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')) + ']]';
	//    form.wpConfirm.checked = true;
}

	
/*** Make the top links look better ***/
	
function changeLinks()
{
	if(!document.getElementById) return;
	document.getElementById('pt-mytalk').firstChild.innerHTML = 'talk';
	document.getElementById('pt-preferences').firstChild.innerHTML = 'preferences';
	document.getElementById('pt-watchlist').firstChild.innerHTML = 'watchlist';
	document.getElementById('pt-mycontris').firstChild.innerHTML = 'contributions';
}
	

/**** Automatically-updating word count on edit pages ****/

/*** Count words in a field ***/
function countWords(field) { 
	return field && field.value ? field.value.split(/\s+/).length : 0;
}

/*** Creates div ***/ 
function doWordCount() {
	if (document.title.slice(0,7) == "Editing") {
	var x = document.getElementById('editpage-copywarn');
	var y = document.getElementById('editform');
	if (x && y && y.wpTextbox1) {
		var z = document.createElement('div');
		z.id = 'word-count';
		x.appendChild(z);
		refreshCount();
	} else {
		alert('Missing element needed for word count');
	}
	}
}

/*** Auto-updated ***/
function refreshCount() {
	var wc = '<small>Word count: ' + countWords(document.getElementById('editform').wpTextbox1) + '</small>';
	document.getElementById('word-count').innerHTML = wc;
	setTimeout(refreshCount, 10000);
}


function morelinks() {
	var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
	if(document.title.indexOf("Editing User talk:") == 0) {
	  addlimenu(tabs, 'Talk page messages', 'talkm');
	  var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0];
	// Welcome menu      
	  addlimenu(talkm, 'Welcome', 'welcomess');
	  var welcomess = document.getElementById('welcomess').getElementsByTagName('ul')[0];
	  addlilink(welcomess,'javascript:edit_summary_watch("{{subst:User:Bookofjude/Welcome}}  ~~~~", "Welcome to Wikipedia!", true, 1)','Welcome', '');
	  addlilink(welcomess,'javascript:edit_summary_watch("{{subst:Anon}}  ~~~~", "Welcome to Wikipedia!", true, 1)','Anon', '');
	// Test menu
	  addlimenu(talkm, 'Test[x]', 'testx');
	  var testx = document.getElementById('testx').getElementsByTagName('ul')[0];
	  addlilink(testx,'javascript:testn("nn-test")','Non-notable test', '');
	  addlilink(testx,'javascript:testn("test0")', 'Test0', '');
	  addlilink(testx,'javascript:testn("test1")', 'Test1', '');
	  addlilink(testx,'javascript:testn("test2")','Test2', '');
	  addlilink(testx,'javascript:testn("test2a")','Test2a', '');
	  addlilink(testx,'javascript:testn("test3")','Test3', '');
	  addlilink(testx,'javascript:testn("test4")','Test4', '');
	  addlilink(testx,'javascript:testn("test4-im")','Only warning', '');
	  addlilink(testx,'javascript:testn("User:Bookofjude/tpv1")','Talk page vandalism 1', '');
	  addlilink(testx,'javascript:edit_summary_watc("{{subst:wr}}  ~~~~", "Blanking your talk page", false, 1)', 'Warning blankings 1', '');
	// Blatant vandalism
	  addlimenu(talkm, 'Blatant vandalism', 'bv')
	  var bv = document.getElementById('bv').getElementsByTagName('ul')[0];
	  addlilink(bv,'javascript:testn("vw")','Blatant vandalism 1', '');
	  addlilink(bv,'javascript:testn("bv")','Blatant vandalism 2', '');
	  addlilink(bv,'javascript:edit_summary_watch("{{subst:blanking}}  ~~~~", "Blanking pages", false, 1)','blanking', '');
	// Spam
	  addlimenu(talkm, 'Spam', 'spam');
	  var spam = document.getElementById('spam').getElementsByTagName('ul')[0];
	  addlilink(spam,'javascript:edit_summary_watch("{{subst:spam1}}  ~~~~", "Adding links to Wikipedia", false, 1)','Spam1', '');
	  addlilink(spam,'javascript:edit_summary_watch("{{subst:spam2}}  ~~~~", "Spamming", false, 1)','Spam2', '');
	  addlilink(spam,'javascript:edit_summary_watch("{{subst:spam3}}  ~~~~", "Last warning for spamming", false, 1)','Spam3', '');
	  addlilink(spam,'javascript:edit_summary_watch("{{subst:spam4}}  ~~~~", "You have been blocked for spamming", false, 1)','Spam4', '');
	// Talk page messages
	  addlimenu(talkm, 'Talk messages', 'tkm');
	  var tkm = document.getElementById('tkm').getElementsByTagName('ul')[0];
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:Summary}}  ~~~~", "Edit summaries", false, 1)','Edit summary 1', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:Mess2}}  ~~~~", "Messages in articles", false, 1)','Messages 1', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:Comment2}}  ~~~~", "Messages in articles", false, 1)','Messages 2', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:Comment3}}  ~~~~", "Messages in articles", false, 1)','Messages 3', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:Vanity|}}  ~~~~", "About the page you created", false, 1)','Vanity', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:nothanks|}}  ~~~~", "About your edits", false, 1)','nothanks', '');
	  addlilink(tkm,'javascript:edit_summary_watch("{{subst:nothanks-sd|pg=page name|url=url of source}}  ~~~~", "{{nothanks-sd}}", false, 1)','nothanks-sd', '');
	  addlilink(tkm,'javascript:rvfd(1)', 'rvfd', ''); 
	// Block messages
	  // addlilink(talkm,'javascript:duration(1)', 'Temp Block', '');
	  // addlilink(talkm,'javascript:perm_name_block("{{s/block3|signature=~~~~}}", "You have been indefinitely blocked", true, 1)','Perm Block', ''); 
	  // addlilink(talkm,'javascript:perm_name_block("{{subst:nameblock}} ~~~~", "{{nameblock}}", true, 1)','Name Block', ''); 
	} else if(document.title.indexOf("Wikipedia:Articles for deletion") == 0) {
		addlilink(tabs, 'javascript:hideafd()', 'hide closed', 'ca-hide');
		ta['ca-hide'] = ['', 'Hide closed AFDs'];
		addlilink(tabs, 'javascript:showafd()', 'show closed', 'ca-show');
		ta['ca-show'] = ['', 'Show closed AFDs'];
	} else if(document.title.indexOf("User") == 0) {
		addlilink(tabs, '/wiki/Special:Contributions/' + getUname(), 'contributions', 'ca-contribs');
		addlilink(tabs, 'http://192.168.0.64/rc.php?whitelist=' + getUname(), 'whitelist', 'ca-whitelist');
		addlilink(tabs, 'http://192.168.0.64/rc.php?blacklist=' + getUname(), 'blacklist', 'ca-blacklist');
	}
}
	
/*** Add links to the toolbox ***/

function addToolBoxLinks()
	{
	if(document.title.indexOf("User:") == 0) {
		var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
		addlilink(tb, '/wiki/Special:Ipblocklist', 'IPBlocklist', '');
		addlilink(tb, '/wiki/Wikipedia:Template messages/User_talk_namespace', 'Talk templates', '');
		addlilink(tb, '/wiki/Wikipedia:Template_messages', 'Templates', '');
		addlilink(tb, '/wiki/WP:CSD', 'SD criteria', '');
		username_a = document.URL.match(/:.*:(.*)/);
		username=username_a[1];
		addlilink(tb, 'http://www.math.ucla.edu/~aoleg/wp/rfa/edit_summary.cgi?user=' + getUname() + '&lang=en', 'User\'s edit summary calculations');
		addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=' + getUname(), 'User\'s edit count', '');
		var username=document.getElementById("pt-userpage").textContent;
		addlilink(tb, 'http://www.math.ucla.edu/~aoleg/wp/rfa/edit_summary.cgi?user=' + username + '&lang=en', 'My edit summary calculations');
		addlilink(tb, 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=enwiki_p&user=' + username, 'My edit count', '');
		addlilink(tb, '/wiki/Special:Log', 'Log', '');
		addlilink(tb, '/wiki/Category:Requests for unblock', 'Unblock requests', '');
	}
}
	
/*** Add navigation bar links ***/
	
function addNavBarLinks() {   
	var navbar = document.getElementById('p-navigation').getElementsByTagName('ul')[0];
	var afdtime = new Date();
	var months = ['January', 'February', 'March', 'April', 'May', 'June',
		'July', 'August', 'September', 'October', 'November', 'December'];
	addlilink(navbar, '/w/index.php?title=Special:Recentchanges&hidemyself=1&hideminor=1&hideliu=1', 'Recent changes 2', '');
	addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear()
		+ '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), 'Today\'s AfD', '');
	afdtime.setUTCDate(afdtime.getUTCDate() - 5);
	addlilink(navbar, '/wiki/Wikipedia:Articles_for_deletion/Log/' + afdtime.getUTCFullYear()
		+ '_' + months[afdtime.getUTCMonth()] + '_' + afdtime.getUTCDate(), '5-day-old AfD', '');
	var username=document.getElementById("pt-userpage").textContent;
	addlilink(navbar, '/w/index.php?title=User:' + username + '/monobook.js&action=edit', 'My monobook.js', '');   
	addlilink(navbar, '/w/index.php?title=User:' + username + '/monobook.css&action=edit', 'My monobook.css', ''); 
	addlilink(navbar, '/wiki/User:Bookofjude/Sandbox', 'My sandbox', ''); 
}
	

/* </nowiki></pre> */