Monchoman45

rollback summaries + open talk

Jun 5th, 2011
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* extra rollback links */
  2. function CustomRollbacks() {
  3.     var Buttons = [{
  4.         text: 'spam',
  5.         title: 'Revert spam',
  6.         summary: 'Reverted [[w:c:help:Help:Spam|spam]]',
  7.         loadtalk: true //Load up the users' talk page after rollbacking
  8.     }, {
  9.         text: 'vandalism',
  10.         title: 'Revert vandalism',
  11.         summary: 'Reverted [[w:c:help:Help:Vandalism|vandalism]]',
  12.         loadtalk: true
  13.     }, {
  14.         text: 'null',
  15.         title: 'Revert with no summary',
  16.         summary: ' &bot=1', //This one has no summary, and flags it as a bot edit
  17.         loadtalk: false
  18.     }];
  19.  
  20.     var list = document.getElementsByTagName('span');
  21.     for(i in list) {
  22.         if(list[i].className == 'mw-rollback-link') {
  23.             var link = list[i];
  24.             var rollback = link.innerHTML;
  25.             for(j in Buttons) {
  26.                 var customlink = document.createElement('span');
  27.                 customlink.innerHTML = rollback;
  28.                 customlink.className = 'customrollback'; //we do this to avoid an infinite loop, because when we insert a <span> into the DOM, the list variable includes it
  29.                 customlink.getElementsByTagName('a')[0].title = Buttons[j].title;
  30.                 customlink.getElementsByTagName('a')[0].href += '&summary=' + Buttons[j].summary;
  31.                 customlink.getElementsByTagName('a')[0].innerHTML = Buttons[j].text;
  32.                 if(Buttons[j].loadtalk == true) {customlink.getElementsByTagName('a')[0].className = 'loadtalk';}
  33.                 if(urlQuery('action') == 'history') {
  34.                     link.parentElement.insertBefore(customlink, link.nextSibling);
  35.                     customlink.outerHTML = ' | ' + customlink.outerHTML;
  36.                 }
  37.                 else {
  38.                     link.parentElement.appendChild(customlink);
  39.                     customlink.outerHTML = ' ' + customlink.outerHTML;
  40.                 }
  41.             }
  42.         }
  43.     }
  44.     for(i in list) { //why another one of these? we're fixing the class that we set to avoid an infinite loop
  45.         if(list[i].className == 'customrollback') {
  46.             list[i].className = 'mw-rollback-link';
  47.         }
  48.     }
  49.     /* Grunny's function for opening up a user's talkpage when rollbacking (http://community.wikia.com/wiki/User:Grunny) */
  50.     $( '.mw-rollback-link .loadtalk' ).click( function (e) {
  51.         e.preventDefault();
  52.         var $rblink = $( this );
  53.         $.ajax( {
  54.             url: $rblink.attr( 'href' ),
  55.             success: function () {
  56.                 var user = $rblink.attr( 'href' ).replace( /.*[&?]from=([^&]*).*/, '$1' ).replace( /\+/g, '_' ),
  57.                     newurl = wgServer + wgArticlePath.replace( '$1', 'User_talk:' + user + '?action=edit&section=new' );
  58.                 location.href = newurl;
  59.             },
  60.             error: function () {
  61.                 $rblink.text( function ( i, val ) {
  62.                     return val + ' [failed]';
  63.                 } );       
  64.             }
  65.         } );
  66.     } );
  67. }
  68.  
  69. addOnloadHook(CustomRollbacks);
  70.  
  71. /* URL parser */
  72. function urlQuery(quer) {
  73.     for(i in location.href.split('?')) {
  74.         for(j in location.href.split('?')[i].split('&')) {
  75.             if(location.href.split('?')[i].split('&')[j].split('=')[0] == quer) {
  76.                 return location.href.split('?')[i].split('&')[j].split('=')[1];
  77.             }
  78.         }
  79.     }
  80.     return '';
  81. }
Advertisement
Add Comment
Please, Sign In to add comment