User:Chlod/Scripts/AjaxRollbackSummary.js

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.
// Global User Toolbox
// Author: Chlod
// Version: 1.0.0-REL

// <nowiki>
jQuery(document).ready(function ($) {
    $('span.mw-rollback-link a').on("click", function(e) {
        e.preventDefault();
        var $rblink = $(this);
        var href = this.getAttribute("href");
        this.innerHTML = '<img src="https://upload.wikimedia.org/wikipedia/commons/f/f8/Ajax-loader%282%29.gif" style="vertical-align: baseline;" height="15" width="15" border="0" alt="Rolling back..." />';
        var summary = prompt("Enter rollback summary");
        if (summary == null) {
            $rblink.text(function (i, val) {return val + '[rollback cancelled]';});
            return;
        }
        $.ajax({
            url: href.replace("?", "?summary=" + encodeURIComponent(summary) + "&"),
            success: function() {
                $rblink.text(function (i, val) {return val + '[reverted]';});
            },
            error: function() {
                $rblink.text(function (i, val) {return val + '[rollback failed]';});
            }
        });
        return false;
    });
});
// </nowiki>