User:KATANAGOD/rollback.js

/* extra rollback links */ //good guy Monchoman45 (with really amazing coding imposed upon it by Sactage) function templateload1(Buttons) { for(j in Buttons) { template = Buttons[j].preload; return template; } } function CustomRollbacks { var Buttons = [{ text: 'IRL', title: 'Rollback (IRL)', summary: 'Removing IRL Info', preload: '', loadtalk: true }, {		text: 'Vandal', title: 'Rollback (Vandal)', summary: 'Vandalism', preload: '', loadtalk: true }, {		text: 'DDD', title: 'Rollback (DDD)', summary: 'DDD', preload: '', loadtalk: true }, {		text: 'NS', title: 'Admin only', summary: ' &bot=1', //This one has no summary, and flags it as a bot edit preload: '', loadtalk: false }];	var list = document.getElementsByTagName('span'); for(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; templateload1(Buttons); if(Buttons[j].loadtalk == true) {customlink.getElementsByTagName('a')[0].className = 'loadtalk';} if(urlQuery('action') == 'history') { link.parentElement.insertBefore(customlink, link.nextSibling); customlink.outerHTML = ' | ' + customlink.outerHTML; }				else { link.parentElement.appendChild(customlink); customlink.outerHTML = ' ' + customlink.outerHTML; }			}		}	}	for(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&preload='+template ); location.href = newurl; },			error: function { $rblink.text( function ( i, val ) {					return val + ' [failed]';				} ); }		} );	} ); } //addOnloadHook(templateload1); addOnloadHook(CustomRollbacks); /* URL parser */ function urlQuery(quer) { for(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 ''; } ajaxCallAgain = [CustomRollbacks];