Monchoman45

ExtraRollbackLink

Apr 2nd, 2011
8,233
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 = [{ //Your buttons go here. You can copy and paste this to make more than three
  4.         text: 'spam',
  5.         title: 'Revert spam',
  6.         summary: '[[Help:Spam|spam]]'
  7.     }, {
  8.         text: 'vandalism',
  9.         title: 'Revert vandalism',
  10.         summary: '[[Help:Vandalism|vandalism]]'
  11.     }, {
  12.         text: 'null',
  13.         title: 'Revert with no summary',
  14.         summary: ' ' //This one has no summary
  15.     }];
  16.  
  17.     var list = document.getElementsByTagName('span');
  18.     for(i in list) {
  19.         if(list[i].className == 'mw-rollback-link') {
  20.             var link = list[i];
  21.             var rollback = link.innerHTML;
  22.             for(j in Buttons) {
  23.                 var customlink = document.createElement('span');
  24.                 customlink.innerHTML = rollback;
  25.                 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
  26.                 customlink.getElementsByTagName('a')[0].title = Buttons[j].title;
  27.                 customlink.getElementsByTagName('a')[0].href += '&summary=' + Buttons[j].summary;
  28.                 customlink.getElementsByTagName('a')[0].innerHTML = Buttons[j].text;
  29.                 if(wgPageName == 'Special:RecentChanges' || wgPageName == 'Special:Contributions') {
  30.                     link.parentElement.appendChild(customlink);
  31.                     customlink.outerHTML = ' ' + customlink.outerHTML;
  32.                 }
  33.                 else { //assumes you're on history
  34.                     link.parentElement.insertBefore(customlink, link.nextSibling);
  35.                     customlink.outerHTML = ' | ' + customlink.outerHTML;
  36.                 }
  37.             }
  38.         }
  39.     }
  40.     for(i in list) { //why another one of these? we're fixing the class that we set to avoid an infinite loop
  41.         if(list[i].className == 'customrollback') {
  42.             list[i].className = 'mw-rollback-link';
  43.         }
  44.     }
  45. }
  46.  
  47. addOnloadHook(CustomRollbacks);
Advertisement
Add Comment
Please, Sign In to add comment