Jump to content

User:Anomie/rollback-prompt.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.
/* This script modifies all "rollback" links to prompt for an edit summary (and prevent accidental rollbacks).
 */
 
$(document).ready(function(){
    var rollbackPrompt=function(ev){
        var summary = prompt("Enter rollback summary:", "<use default>");
        if(summary == null || summary == "") {
            ev=ev || window.event;
            if(ev.preventDefault) ev.preventDefault();
            if(ev.stopPropagation) ev.stopPropagation();
            ev.returnValue = false;
            ev.cancelBubble = true;
            return false;
        }
        if(summary != "<use default>")
            this.href = this.href.replace("?", "?summary=" + encodeURIComponent(summary) + "&");
        return true;
    };

    var links=document.getElementById('content').getElementsByTagName('a');
    for(var i=links.length-1; i>=0; i--){
        if(/[?&]action=rollback([&#]|$)/.test(links[i].href))
            links[i].onclick=rollbackPrompt;
    }

});