User:Hairr/rollback.js

function CustomRollbacks { var Buttons = [{ text: 'spam', title: 'Revert spam', summary: 'Reverted spam', loadtalk: false }, {               text: 'Oh no' title: 'Revert edit that didn't work summary: 'Reverting test or code that didn't work' loadtalk: true }, {               text: 'vandalism', title: 'Revert vandalism', summary: 'Reverted vandalism', loadtalk: false }, {               text: 'null', title: 'Revert with no summary', summary: ' &bot=1', 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'; 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(i in list) { if(list[i].className == 'customrollback') { list[i].className = 'mw-rollback-link'; }       }

$( '.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]';                                } ); }               } );        } ); }

addOnloadHook(CustomRollbacks);