User:Kangaroopower/rollbacks.js

/* Moncho and Grunny */ function CustomRollbacks { var Buttons = [{ text: 'spam', title: 'Revert spam', summary: 'Reverted spam', }, {               text: 'vandalism', title: 'Revert vandalism', summary: 'Reverted vandalism', }, {               text: 'bot', title: 'Revert with no summary', summary: ' &bot=1', }];       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                               var a = customlink.getElementsByTagName('a') a[0].title = Buttons[j].title; a[0].href += '&summary=' + Buttons[j].summary; a[0].innerHTML = Buttons[j].text; if(urlQuery('action') == 'history') { link.parentNode.insertBefore(customlink, link.nextSibling); customlink.outerHTML = ' | ' + customlink.outerHTML; }                               else { link.parentNode.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'; }       } } addOnloadHook(CustomRollbacks); /* Fix Monobook error*/ 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 undefined; }