2015-08-03 14:38:39 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name MusicBrainz: Fast cancel edits
|
2015-09-15 17:56:13 +00:00
|
|
|
// @version 2015.9.15
|
2015-08-03 14:38:39 +00:00
|
|
|
// @author Michael Wiencek
|
2015-08-03 14:49:45 +00:00
|
|
|
// @downloadURL https://bitbucket.org/mwiencek/userscripts/raw/master/fast-cancel-edits.user.js
|
|
|
|
// @updateURL https://bitbucket.org/mwiencek/userscripts/raw/master/fast-cancel-edits.user.js
|
2015-08-03 14:38:39 +00:00
|
|
|
// @include *://musicbrainz.org/user/*/edits/open*
|
|
|
|
// @include *://musicbrainz.org/*/*/open_edits*
|
|
|
|
// @include *://musicbrainz.org/*/*/edits*
|
|
|
|
// @include *://musicbrainz.org/search/edits*
|
|
|
|
// @include *://*.musicbrainz.org/user/*/edits/open*
|
|
|
|
// @include *://*.musicbrainz.org/*/*/open_edits*
|
|
|
|
// @include *://*.musicbrainz.org/*/*/edits*
|
|
|
|
// @include *://*.musicbrainz.org/search/edits*
|
|
|
|
// @include *://*.mbsandbox.org/user/*/edits/open*
|
|
|
|
// @include *://*.mbsandbox.org/*/*/open_edits*
|
|
|
|
// @include *://*.mbsandbox.org/*/*/edits*
|
|
|
|
// @include *://*.mbsandbox.org/search/edits*
|
|
|
|
// @match *://musicbrainz.org/user/*/edits/open*
|
|
|
|
// @match *://musicbrainz.org/*/*/open_edits*
|
|
|
|
// @match *://musicbrainz.org/*/*/edits*
|
|
|
|
// @match *://musicbrainz.org/search/edits*
|
|
|
|
// @match *://*.musicbrainz.org/user/*/edits/open*
|
|
|
|
// @match *://*.musicbrainz.org/*/*/open_edits*
|
|
|
|
// @match *://*.musicbrainz.org/*/*/edits*
|
|
|
|
// @match *://*.musicbrainz.org/search/edits*
|
|
|
|
// @match *://*.mbsandbox.org/user/*/edits/open*
|
|
|
|
// @match *://*.mbsandbox.org/*/*/open_edits*
|
|
|
|
// @match *://*.mbsandbox.org/*/*/edits*
|
|
|
|
// @match *://*.mbsandbox.org/search/edits*
|
2015-08-03 14:45:26 +00:00
|
|
|
// @grant none
|
2015-08-03 14:38:39 +00:00
|
|
|
// ==/UserScript==
|
|
|
|
//**************************************************************************//
|
|
|
|
|
|
|
|
var scr = document.createElement("script");
|
|
|
|
scr.textContent = "(" + fastCancelScript + ")();";
|
|
|
|
document.body.appendChild(scr);
|
|
|
|
|
|
|
|
function fastCancelScript() {
|
|
|
|
var totalCancels = 0;
|
|
|
|
|
|
|
|
var $status = $("<div></div>")
|
|
|
|
.css({
|
|
|
|
"position": "fixed",
|
|
|
|
"right": "0",
|
|
|
|
"bottom": "0",
|
|
|
|
"background": "#FFBA58",
|
|
|
|
"border-top": "1px #000 solid",
|
|
|
|
"border-left": "1px #000 solid",
|
|
|
|
"padding": "0.5em"
|
|
|
|
})
|
|
|
|
.appendTo("body")
|
|
|
|
.hide();
|
|
|
|
|
|
|
|
function updateStatus() {
|
|
|
|
if (totalCancels === 0) {
|
|
|
|
$status.hide();
|
|
|
|
} else {
|
|
|
|
$status.text("Canceling " + totalCancels + " edit" +
|
|
|
|
(totalCancels > 1 ? "s" : "") + "...").show();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$("a.negative").on("click", function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
totalCancels += 1;
|
|
|
|
updateStatus();
|
|
|
|
|
|
|
|
var $self = $(this),
|
|
|
|
$edit = $self.parents("div.edit-list:eq(0)");
|
|
|
|
|
|
|
|
pushRequest(function () {
|
|
|
|
var editNote = $edit.find("div.add-edit-note textarea").val();
|
|
|
|
var data = { "confirm.edit_note": editNote };
|
|
|
|
|
2015-08-03 14:45:26 +00:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: $self.attr("href"),
|
|
|
|
data: data,
|
|
|
|
error: function (request, status, error) {
|
|
|
|
$self
|
|
|
|
.css({
|
|
|
|
"background": "red",
|
|
|
|
"color": "yellow",
|
|
|
|
"cursor": "help"
|
|
|
|
})
|
2015-08-21 11:12:46 +00:00
|
|
|
.attr("title", "Error cancelling this edit: “" + error + "”");
|
2015-08-03 14:45:26 +00:00
|
|
|
$edit
|
|
|
|
.css({border: "6px solid red"})
|
|
|
|
.show();
|
|
|
|
},
|
|
|
|
complete: function () {
|
2015-09-15 17:56:13 +00:00
|
|
|
$edit.remove();
|
2015-08-03 14:45:26 +00:00
|
|
|
totalCancels -= 1;
|
|
|
|
updateStatus();
|
|
|
|
}
|
2015-08-03 14:38:39 +00:00
|
|
|
});
|
|
|
|
});
|
2015-08-03 14:45:26 +00:00
|
|
|
$edit.hide();
|
2015-08-03 14:38:39 +00:00
|
|
|
});
|
|
|
|
|
2015-09-15 17:56:13 +00:00
|
|
|
$("div#edits > form[action$='/edit/enter_votes']").on("submit", function(event) {
|
|
|
|
if (totalCancels > 0) {
|
|
|
|
event.preventDefault();
|
|
|
|
alert("Please wait, " + (totalCancels > 1 ? totalCancels + " edits are" : "an edit is") + " being cancelled in the background.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-08-03 14:38:39 +00:00
|
|
|
var pushRequest = (function () {
|
|
|
|
var queue = [],
|
|
|
|
last = 0,
|
|
|
|
active = false,
|
|
|
|
rate = 2000;
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
if (queue.length === 0) {
|
|
|
|
active = false;
|
|
|
|
} else {
|
|
|
|
queue.shift()();
|
|
|
|
last = new Date().getTime();
|
|
|
|
setTimeout(next, rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return function (req) {
|
|
|
|
queue.push(req);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
active = true;
|
|
|
|
var now = new Date().getTime();
|
|
|
|
if (now - last >= rate) {
|
|
|
|
next();
|
|
|
|
} else {
|
|
|
|
var timeout = rate - now + last;
|
|
|
|
setTimeout(next, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
}
|