Jump to content

User:TheDragonFire/scripts/steamroller.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<nowiki>
//
// steamroller.js - Your standard roller on steroids.
//
// To install, place {{subst:iusc|User:TheDragonFire/scripts/steamroller.js}} on [[Special:MyPage/Common.js]].
//

mw.loader.using(['oojs-ui-core', 'oojs-ui-windows'], function() {
  $('.mw-rollback-link a').click(function(event) {
    event.preventDefault();
    var count = event.target.innerText.match(/\d+/) ? event.target.innerText.match(/\d+/)[0] : null;
    var message = 'Roll back ' + (count ? count + ' edits' : 'edit') + ' by ' + mw.util.getParamValue('from', event.target.href) + '?';

    OO.ui.confirm(message, {
      title: 'Confirm rollback',
      actions: [{
          action: 'accept',
          label: OO.ui.deferMsg('ooui-dialog-message-accept'),
          flags: ['primary', 'destructive']
        },
        {
          action: 'reject',
          label: OO.ui.deferMsg('ooui-dialog-message-reject'),
          flags: 'safe'
        }
      ]
    }).done(function(confirmed) {
      if (!confirmed) return;
      $.ajax({
        url: event.target.href,
        success: function() {
          location.href = mw.util.getUrl('Special:Contributions/' + mw.util.getParamValue('from', event.target.href).replace(/\+/g, '_')) + '?vanarticle=' + encodeURIComponent(mw.util.getParamValue('title', event.target.href).replace(/_/g, ' '));
        },
        error: function() {
          event.target.text(function(index, text) {
            return text + ' [failed]';
          });
        }
      });
    });
  });
});

//</nowiki>