Difference between revisions of "User:CRLF/OneClickUndo.js"
(Create) |
(No difference)
|
Revision as of 02:18, 21 May 2022
// This script implements a very crude one-click undo. If you go onto a diff page with an undo link, this will change it to work in one single click rather than two.
function rvt(undop, undoafterp, c) { // Implements one-click undo
$.ajax({
url: 'https://www.explainxkcd.com/wiki/api.php',
data: {
format: 'json',
action: 'edit',
title: $("#firstHeading").text().substr(33, $("#firstHeading").text().length - 34),
undo: undop,
undoafter: undoafterp,
summary: "Reverted vandalism with [[User:CRLF/OneClickUndo.js]]",
token: mw.user.tokens.get('csrfToken')
},
dataType: 'json',
type: 'POST',
success: function () { if (c) { $('.mw-diff-undo > a').text("success"); $('.mw-diff-undo > a').removeAttr("onclick"); } else { $('#link' + undop).text("success"); $('.mw-diff-undo > a').removeAttr("onclick"); } }
});
}
try{
var href = $('.mw-diff-undo > a').attr('href').split("=");
var undop = href[4];
var undoafterp = href[3].substr(0, href[3].length - 5);
$('.mw-diff-undo > a').removeAttr('href');
$('.mw-diff-undo > a').attr('onclick', 'rvt(' + undop + ',' + undoafterp + ',1)');} catch(e) {console.log(e);console.log("assumed not undoable");}
