User:Riley H/global.js

// *********************************** // Kill image popups (code from Rappy) // *********************************** window.wgEnableImageLightboxExt = false; function changeimagelinks { if (window.skin == 'oasis') { var article = $('#WikiaArticle, .LatestPhotosModule, #article-comments'); }   else { var article = $('#bodyContent'); }   article.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 ) { if ( a2.href.indexOf("images.Wikia.com") != -1 ) { var link = wgServer + '/wiki/File:' + a2.href.substring(a2.href.lastIndexOf('/') + 1); a2.setAttribute('href',link); }       }    } } addOnloadHook(changeimagelinks);

/* Auto-refresh the Recentchanges and Wikiactivity; copied from Avatar Wiki's */

AjaxRCRefreshText = 'Auto-refresh'; AjaxRCRefreshHoverText = 'Automatically refresh the page'; ajaxPages = ["Special:RecentChanges","Special:WikiActivity"]; importScriptPage('AjaxRC/code.js', 'dev');

/* add contribs to user menu - 2/1/11; by Monchoman45 */

function UserContribsMenuItem { $('ul.AccountNavigation li:first-child ul.subnav li:first-child').after('Contributions'); } addOnloadHook(UserContribsMenuItem);

/* Custom edit buttons * Original by User:Grunny */ mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images1.wikia.nocookie.net/central/images/7/73/Button_code_nowiki.png?1", "speedTip": "code+nowiki", "tagOpen": " ", "sampleText": "Insert code here"};

importScriptURI('http://monchbox.wikia.com/index.php?title=MediaWiki:APIQuery.js&action=raw&ctype=text/javascript'); importScriptURI('http://monchbox.wikia.com/index.php?title=MediaWiki:B3.js&action=raw&ctype=text/javascript'); importScriptURI('http://monchbox.wikia.com/index.php?title=MediaWiki:WhamAPI.js&action=raw&ctype=text/javascript');

/* Extra rollback links */ function CustomRollbacks { var Buttons = [{ text: 'spam', title: 'Revert spam', summary: 'Reverted spam', loadtalk: false }, {		text: 'vandalism', title: 'Revert vandalism', summary: 'Reverted vandalism', loadtalk: false }, {		text: 'null', title: 'Revert with no summary', summary: ' &bot=1', //This one has no summary, and flags it as a bot edit loadtalk: false }];	var list = document.getElementsByTagName('span'); for(var i in list) { if(list[i].className == 'mw-rollback-link') { var link = list[i]; var rollback = link.innerHTML; for(j in Buttons) { var customlink = document.createElement('span'); customlink.innerHTML = rollback; customlink.className = 'customrollback'; //we do this to avoid an infinite loop, because when we insert a into the DOM, the list variable includes it				customlink.getElementsByTagName('a')[0].title = Buttons[j].title; customlink.getElementsByTagName('a')[0].href += '&summary=' + Buttons[j].summary; customlink.getElementsByTagName('a')[0].innerHTML = Buttons[j].text; if(Buttons[j].loadtalk == true) {customlink.getElementsByTagName('a')[0].className = 'loadtalk';} if(urlQuery('action') == 'history') { link.parentNode.insertBefore(customlink, link.nextSibling); customlink.outerHTML = ' | ' + customlink.outerHTML; }				else { link.parentNode.appendChild(customlink); customlink.outerHTML = ' ' + customlink.outerHTML; }			}		}	}	for(var i in list) { //why another one of these? we're fixing the class that we set to avoid an infinite loop if(list[i].className == 'customrollback') { list[i].className = 'mw-rollback-link'; }	}	/* Grunny's function for opening up a user's talkpage when rollbacking (http://community.wikia.com/wiki/User:Grunny) */ $( '.mw-rollback-link .loadtalk' ).click( function (e) {		e.preventDefault;		var $rblink = $( this );		$.ajax( { url: $rblink.attr( 'href' ), success: function { var    user = $rblink.attr( 'href' ).replace( /.*[&?]from=([^&]*).*/, '$1' ).replace( /\+/g, '_' ), newurl = wgServer + wgArticlePath.replace( '$1', 'User_talk:' + user + '?action=edit&section=new' ); location.href = newurl; },			error: function { $rblink.text( function ( i, val ) {					return val + ' [failed]';				} ); }		} );	} ); }

if(readCookie('globalJS') == 'true') {addOnloadHook(CustomRollbacks);}

/* Rollback with Ajax - stolen from Grunny (see above) */ function SetAjaxRollback { $('.mw-rollback-link').click(function(e) {		e.preventDefault;		var $rblink = $(this);		var href = this.getElementsByTagName('a')[0].href;		this.innerHTML = ' ';		$.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(readCookie('globalJS') == 'true') {addOnloadHook(SetAjaxRollback);}

/* Quickblock links */ function AddQuickblockLinks { var Buttons = [{ text: 'v-w', title: 'Week-long block for vandalism', summary: 'Vandalism', length: '1 week' }, {		text: 'pb-w', title: 'Week-long block for page blanking', summary: 'Removing content from pages', length: '1 week' }, {		text: 'h-w', title: 'Week-long block for harassment', summary: 'Intimidating behavior/Harassment', length: '1 week' }];	var admin = false; for(var i in wgUserGroups) { if(wgUserGroups[i] == 'sysop' || wgUserGroups[i] == 'bureaucrat' || wgUserGroups[i] == 'helper' || wgUserGroups[i] == 'staff') {admin = true; break;} }	if(!admin) {return;} window.qbapi = new APIQuery; var list = document.getElementsByTagName('span'); for(var i in list) { if(list[i].className == 'mw-usertoollinks') { var link = list[i].getElementsByTagName('a')[list[i].getElementsByTagName('a').length - 1]; for(j in Buttons) { var customlink = document.createElement('a'); customlink.innerHTML = Buttons[j].text; customlink.className = 'mw-quickblock'; customlink.title = Buttons[j].title; customlink.href = 'javascript:this.innerHTML = \'\'; qbapi.newQuery(\'POST\', {action: \'block\', user: ' + link.parentNode.previousSibling.previousSibling.innerHTML + ', reason: ' + Buttons[j].summary + ', expiry: ' + Buttons[j].length + ', nocreate: 1, autoblock: 1, noemail: 1}, function(result) {this.hash.link.innerHTML = \'success\'; if(preloadAJAXRL) {preloadAJAXRL;}}); qbapi[0].hash.link = this; qbapi.send(0, true);'; link.parentNode.insertBefore(customlink, link.nextSibling); customlink.outerHTML = ' | ' + customlink.outerHTML; }		}	} } if(readCookie('globalJS') == 'true') {addOnloadHook(AddQuickblockLinks);}

/* 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(readCookie('globalJS') == 'true' && skin != 'oasis') {addOnloadHook(displayTimer);}