User:Monchoman45/global.js

/************************************ stuff here goes on every wiki ************************************/ /*** Please note that functions on this page are heavily integrated with one another, and will not work by themselves. ***/ /*** Many of these are derivatives of publicly available fixes - see User blog:Monchoman45/Improving your interface with CSS/JS. ***/ /*** If you'd like to use something in here, ask me on my talk page and I'll gladly give you the function in a form that will work for you. ***/

/************* Common stuff *************/

/* APIQuery, B3, wham, chat hacks, other import crap */ importScriptPage('MediaWiki:APIQuery.js', 'monchbox'); importScriptURI('http://monchbox.wikia.com/index.php?title=MediaWiki:B3.js&action=raw&ctype=text/javascript&templates=expand&t=' + (new Date).getTime); importScriptURI('http://monchbox.wikia.com/index.php?title=MediaWiki:Torus.js/dev.js&action=raw&ctype=text/javascript&templates=expand&t=' + (new Date).getTime); importScriptPage('MediaWiki:WhamAPI.js', 'monchbox'); importScriptPage('User:Monchoman45/ChatHacks.js', 'c'); if(!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') {importScriptPage('AjaxRC/code.js', 'dev');}

/* storage init */ function CheckStorage { if(localStorage.getItem('globalJS') == null) {localStorage.setItem('globalJS', 'true');} if(skin == 'oasis') {$('#AccountNavigation').prepend(' JS ');} }

addOnloadHook(CheckStorage);

function ToggleGlobalJSStorage { if(localStorage.getItem('globalJS') == 'true') { localStorage.setItem('globalJS', 'false'); $('#GlobalJSText').html('Off'); }	else { localStorage.setItem('globalJS', 'true'); $('#GlobalJSText').html('On'); }	window.location.reload; }

/* URL parser */ function urlQuery(quer) { for(var i in location.href.split('?')) { for(j in location.href.split('?')[i].split('&')) { if(location.href.split('?')[i].split('&')[j].split('=')[0] == quer) { return location.href.split('?')[i].split('&')[j].split('=')[1]; }		}	}	return ''; }

function KillMessageWall { var sub = ['Talk', 'talk']; //pages to check var on = false; for(var i = 0; i < sub.length; i++) { if(wgPageName == 'User:' + wgUserName + '/' + sub[i]) {on = true; break;} }	if(!on) { xhr = new XMLHttpRequest; xhr.open('GET', '/api.php?action=query&prop=info&titles=User:' + wgUserName + '/' + sub.join('|User:' + wgUserName + '/'), true); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.onreadystatechange = function { if(this.readyState == 4 && this.status == 200) { var pages = JSON.parse(this.responseText).query.pages; for(var i in pages) { if(i > 0 && pages[i].lastrevid > localStorage.getItem('msgwl_' + pages[i].title.substring(pages[i].title.indexOf('/') + 1))) { if(skin == 'oasis') { document.getElementById('WikiaFooter').getElementsByTagName('ul')[0].outerHTML += ' You have new messages. '; }						else { document.getElementById('contentSub').outerHTML += ' You have new messages (show most recent</a>). ';						}					}				}			}		}		xhr.send; }	else {localStorage.setItem('msgwl_' + wgPageName.substring(wgPageName.lastIndexOf('/') + 1), wgCurRevisionId);} } if(!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') {addOnloadHook(KillMessageWall);}

function AnonIP { var list = document.getElementsByTagName('a'); for(var i in list) { if(list[i].href && list[i].href.indexOf('Special:Contributions/') && list[i].innerHTML == 'A Wikia contributor') { list[i].innerHTML = list[i].href.substring(list[i].href.lastIndexOf('/') + 1, list[i].href.length); }	} } if(!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') {addOnloadHook(AnonIP);}

function UnusedFiles { $('.gallerytext a').each(function {		$(this).html($(this).attr('title'));	}); } if(!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') {addOnloadHook(UnusedFiles);}

/* Rollback with Ajax - stolen from Grunny */ function SetAjaxRollback { $('a.mw-rollback-link').click(function(e) {		e.preventDefault;		var $rblink = $(this);		var href = this.getElementsByTagName('a')[0].href;		this.innerHTML = ' <img src="http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif" style="vertical-align: baseline;" border="0" alt="Rollbacking..." />';		$.ajax({ url: href, success: function { $rblink.text(function (i, val) {return val + ' [success]';}); loadPageData; },			error: function { $rblink.text(function (i, val) {return val + ' [failed]';}); loadPageData; }		});	}); } if(!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') {addOnloadHook(SetAjaxRollback);}

/* add clock to buttons - function is called by RedefineButtons */ //Modified from work by Patrick Westerhoff [poke]: //http://bulbapedia.bulbagarden.net/wiki/MediaWiki:Monobook.js //Further modified by Monchoman45 to play nicely with the rest of my interface function displayTimer { if(typeof(timerDisplay) !== 'undefined' && timerDisplay === false) {return;} var date; if(skin == 'oasis') {var timerParent = document.getElementById('WikiHeader').getElementsByTagName('div')[0];} else {var timerParent = document.getElementById('p-personal').getElementsByTagName('ul')[0];} var timerLink = document.createElement('a'); var timerObj = document.createElement('li'); var timerDiv = document.createElement('div'); timerLink.href = '/index.php?title=' + wgPageName + '&action=purge'; timerLink.title = 'Purge'; timerLink.style.margin = '0'; timerLink.style.padding = '0 5px 0 5px'; timerObj.id = 'displayTimer'; timerObj.style.textTransform = 'none'; timerObj.style.fontWeight = 'bold'; timerObj.style.fontSize = '100%'; timerDiv.id = 'middlerow'; timerDiv.style.float = 'right'; timerDiv.style.margin = '0 0 2px 0'; timerObj.appendChild(timerLink); timerDiv.appendChild(timerObj); timerParent.insertBefore(timerDiv, timerParent.lastChild); var month = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; function actualizeUTC { timerDate = new Date; timerLink.innerHTML = (timerDate.getUTCDate < 10 ? '0' : ) + timerDate.getUTCDate + ' ' + (timerDate.getUTCMonth < 10 ?  : ) + month[timerDate.getUTCMonth] + ' ' + (timerDate.getUTCFullYear < 10 ? '0' : ) + timerDate.getUTCFullYear + ' ' + (timerDate.getUTCHours < 10 ? '0' : ) + timerDate.getUTCHours   + ':' + (timerDate.getUTCMinutes < 10 ? '0' : ) + timerDate.getUTCMinutes  + ':' + (timerDate.getUTCSeconds < 10 ? '0' : '') + timerDate.getUTCSeconds  + ' (UTC)'; }	function actualizeCustom { timerDate = new Date; timerDate.setMinutes(timerDate.getMinutes + timerDate.getTimezoneOffset + timerTimezone * 60); timerLink.innerHTML = (timerDate.getDate < 10 ? '0' : ) + timerDate.getDate + ' ' + (timerDate.getMonth < 10 ?  : ) + month[timerDate.getMonth] + ' ' + (timerDate.getFullYear < 10 ? '0' : ) + timerDate.getFullYear + ' ' + ( timerDate.getHours < 10 ? '0' : ) + timerDate.getHours + ':' + (timerDate.getMinutes < 10 ? '0' : ) + timerDate.getMinutes + ':' + (timerDate.getSeconds < 10 ? '0' : '') + timerDate.getSeconds + ' (UTC' + (timerTimezone < 0 ? '' : '+') + timerTimezone + ')'; }	// start if(typeof(timerTimezone) !== 'number') { actualizeUTC; setInterval(actualizeUTC, 1000); }	else { actualizeCustom; setInterval(actualizeCustom, 1000); } } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin != 'oasis') {addOnloadHook(displayTimer);}

/************* Oasis stuff *************/

/* change publish to save and rename to move */ function PublishToSave { $('#wpSave').val('Save changes'); $('a[data-id="move"]').html('Move'); } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin == 'oasis') {addOnloadHook(PublishToSave);} /* redo links on user nav to be more useful */ function RedefineUserNav { $('.AccountNavigation .subnav li:first-child').replaceWith('<a href="/wiki/User_talk:'+ wgUserName +'">Talk</a></li><a href="/wiki/Special:Contributions/'+ wgUserName +'">Contributions</a></li>'); $('.AccountNavigation .subnav li a[href="/wiki/Special:Preferences"]').replaceWith('<a href="/wiki/Special:Preferences">Preferences</a></li>'); $('.AccountNavigation .subnav li a[href="/wiki/Special:Following"]').replaceWith('<a href="/index.php?title=User:'+ wgUserName +'/Sandbox&action=edit">Sandbox</a></li>'); $('.AccountNavigation .subnav li a[href="/wiki/Help:Contents"]').replaceWith('<a href="http://community.wikia.com/wiki/Forum:Index">Central Forum</a></li><a href="http://community.wikia.com/wiki/User:'+ wgUserName +'/global.js">global.js</a></li><a href="http://community.wikia.com/wiki/User:'+ wgUserName +'/global.css">global.css</a></li>'); $('.AccountNavigation .subnav').css({'width': "133px"}); } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin == 'oasis') {addOnloadHook(RedefineUserNav);}

/* kill image popups */ window.wgEnableImageLightboxExt = false; function changeimagelinks { $('#WikiaArticle, .LatestPhotosModule, #article-comments').unbind('click.lightbox');

var a = document.getElementsByTagName('a'); for(var t = 0; t < a.length; ++t) { var a2 = a[t]; var img = a2.getElementsByTagName('img'); if(img[0] != null && a2.href.indexOf('images.wikia.com') != -1) { var link = wgServer + '/wiki/File:' + a2.href.substring(a2.href.lastIndexOf('/') + 1); a2.setAttribute('href',link); }	} } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin == 'oasis') {addOnloadHook(changeimagelinks);}

/************* Monobook stuff *************/ function UserLinks { //The "My" really annoys me. Must kill it	document.getElementById('pt-mytalk').getElementsByTagName('a')[0].innerHTML = 'Talk'; document.getElementById('pt-preferences').getElementsByTagName('a')[0].innerHTML = 'Preferences'; document.getElementById('pt-mycontris').getElementsByTagName('a')[0].innerHTML = 'Contribs'; $('#pt-mytalk').after($('#pt-mycontris').detach); $('#pt-watchlist').remove; $('#pt-preferences').after('<a href="http://community.wikia.com/wiki/User:Monchoman45/global.js" style="text-transform:lowercase;">global.js</a></li><a href="http://community.wikia.com/wiki/User:Monchoman45/global.css" style="text-transform:lowercase;">global.css</a></li>'); //This really should never have changed to rename if(document.getElementById('ca-move')){document.getElementById('ca-move').getElementsByTagName('a')[0].innerHTML = 'Move';} //And this really shouldn't have changed to publish if(document.getElementById('wpSave')) {document.getElementById('wpSave').value = 'Save page';} } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin != 'oasis') {addOnloadHook(UserLinks);}

/* Skin change buttons and JS tab */ function ExtraTabs { $('#p-cactions .pBody ul li:nth-last-child(1)').after('<a href="/index.php?title='+ wgPageName +'&useskin=wikia" title="Change to Oasis [o]" id="skinChangeButton" accesskey="o">Oasis</a></li><a href="/index.php?title='+ wgPageName +'&useskin=vector" title="Change to Vector [v]" id="skinChangeButton" accesskey="o">Vector</a></li>'); } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin != 'oasis') {addOnloadHook(ExtraTabs);}

/* Sidebar submenus */ function MonobookSubmenus { var ports = $('.generated-sidebar'); $('#p-search').before(' Wiki navigation </ul> '); var ul = document.getElementById('p-generated').getElementsByTagName('ul')[0]; for(var i = 0; i < ports.length; i++) { var links = ''; for(var j = 0; j < ports[i].getElementsByTagName('li').length; j++) { links += ports[i].getElementsByTagName('li')[j].outerHTML; }		ul.innerHTML += ' ' + ports[i].getElementsByTagName('h5')[0].innerHTML + ' &raquo; <ul class="sidebar-subnav" style="position:absolute; left:138px; margin-top:-22px; z-index:99999; background-color:#fff; border:1px solid #000; padding:3px 7px 3px 17px; display:none;">' + links + '</ul></li>'; }	ports.remove; document.getElementById('p-generated').className = 'generated-sidebar portlet'; //set here to avoid class list loop } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin != 'oasis') {addOnloadHook(MonobookSubmenus);}

function ShowMBMenu { clearTimeout(window.sidebartime); //Clear existing timeout to prevent confusion when moving from one module to another module var uls = $('.sidebar-subnav'); for(var i = 0; i < uls.length; i++) { uls[i].style.display = 'none'; //Hide all other modules uls[i].parentNode.onmouseover = function(event) {window.sidebarpar = this; ShowMBMenu;} }	window.sidebarpar.getElementsByTagName('ul')[0].style.display = 'block'; window.sidebarpar.onmouseover = function(event) {window.sidebarpar = undefined; clearTimeout(window.sidebartime);} window.sidebarpar.onmouseout = function(event) {window.sidebarpar = this; window.sidebartime = setTimeout('HideMBMenu', 400);} } function HideMBMenu { window.sidebarpar.getElementsByTagName('ul')[0].style.display = 'none'; window.sidebarpar.onmouseover = function(event) {window.sidebarpar = this; window.sidebartime = setTimeout('ShowMBMenu', 300);} window.sidebarpar.onmouseout = function(event) {window.sibebarpar = undefined; clearTimeout(window.sidebartime);} }

function ExtraPortlets { $('#p-search').before(' Tools  <a href="/wiki/Special:RecentChanges">Recent changes</a> &raquo; <ul class="sidebar-subnav" style="position:absolute; left:138px; margin-top:-22px; z-index:99999; background-color:#fff; border:1px solid #000; padding:3px 7px 3px 17px; display:none;"><a href="/wiki/Special:Log">Log</a></li><li><a href="/wiki/Special:NewPages">New pages</a></li><li><a href="/wiki/Special:NewFiles">New files</a></li></ul></li><li onmouseover="window.sidebarpar = this; window.sidebartime = setTimeout(\'ShowMBMenu\', 300);" onmouseout="window.sidebarpar = undefined; clearTimeout(window.sidebartime);"> <a href="/wiki/Special:CreatePage">Create page</a> &raquo;  <ul class="sidebar-subnav" style="position:absolute; left:138px; margin-top:-22px; z-index:99999; background-color:#fff; border:1px solid #000; padding:3px 7px 3px 17px; display:none;"><li><a href="/wiki/Special:Upload">Upload</a></li><li><a href="/wiki/Special:MultipleUpload">Multiple upload</a></li><li><a href="/wiki/Special:CreateBlogPage">Blog</a></li></ul></li><li onmouseover="window.sidebarpar = this; window.sidebartime = setTimeout(\'ShowMBMenu\', 300);" onmouseout="window.sidebarpar = undefined; clearTimeout(window.sidebartime);"> <a href="/wiki/Special:ListUsers">List</a> &raquo;  <ul class="sidebar-subnav" style="position:absolute; left:138px; margin-top:-22px; z-index:99999; background-color:#fff; border:1px solid #000; padding:3px 7px 3px 17px; display:none;"><li><a href="/wiki/Special:ListUsers/sysop">Admins</a></li><li><a href="/wiki/Special:ListUsers/bureaucrat">Bureaucrats</a></li><li><a href="/wiki/Special:ListUsers/chatmoderator">Chat mods</a></li></ul></li><li><a href="/wiki/Special:SpecialPages">Special pages</a></li><li><a href="javascript:OpenChatWindow;">Chat</a></li></ul>  '); $('#p-logo').after($('#p-search').detach); } if((!localStorage.getItem('globalJS') || localStorage.getItem('globalJS') == 'true') && skin != 'oasis') {addOnloadHook(ExtraPortlets)}