Difference between revisions of "User:CRLF/common.js"
(try) |
(ok comment it out) |
||
Line 23: | Line 23: | ||
$('.mw-diff-undo > a').attr('onclick', 'rvt(' + undop + ',' + undoafterp + ',1)');} catch(e) {console.log(e);console.log("assumed not undoable");} | $('.mw-diff-undo > a').attr('onclick', 'rvt(' + undop + ',' + undoafterp + ',1)');} catch(e) {console.log(e);console.log("assumed not undoable");} | ||
+ | |||
+ | /* following doesn't work bc async stuff probably, may revisit later | ||
function makeLinks(page, elem) { // Implements undo links on contribs page | function makeLinks(page, elem) { // Implements undo links on contribs page | ||
$.ajax({ | $.ajax({ | ||
Line 41: | Line 43: | ||
} | } | ||
+ | */ |
Revision as of 02:14, 21 May 2022
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/common.js]]", token: mw.user.tokens.get('csrfToken') }, dataType: 'json', type: 'POST', success: function () { if (c) { $('.mw-diff-undo > a').text("success"); } else { $('#link' + undop).text("success"); } } }); } 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");} /* following doesn't work bc async stuff probably, may revisit later function makeLinks(page, elem) { // Implements undo links on contribs page $.ajax({ url: 'https://www.explainxkcd.com/wiki/api.php', type: 'GET', dataType: 'json', data: { action: 'query', prop: 'revisions', titles: page, rvprop: 'ids', formatversion: 2 }, success: function (data) { $('<a id="link' + data["query"]["pages"][0]["revisions"][0]["revid"] + '" onclick="rvt(' + data["query"]["pages"][0]["revisions"][0]["revid"] + ',' + data["query"]["pages"][0]["revisions"][0]["parentid"] + ',0)">[rvt]</a>').insertAfter(elem); } }) } cs= $('.mw-contributions-title'); for (var i =0;i<cs.length;i++) { var title = cs[i].getAttribute("title"); makeLinks(title,cs[i]); } */