2015-08-03 14:38:39 +00:00
|
|
|
// ==UserScript==
|
|
|
|
// @name MusicBrainz: Fast cancel edits
|
2017-03-10 18:50:20 +00:00
|
|
|
// @description Mass cancel open edits with optional edit notes.
|
2018-02-18 17:16:45 +00:00
|
|
|
// @version 2018.2.18.1
|
2015-08-03 14:38:39 +00:00
|
|
|
// @author Michael Wiencek
|
2017-03-10 18:14:00 +00:00
|
|
|
// @license X11
|
2017-03-10 18:57:54 +00:00
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/fast-cancel-edits.user.js
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/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==
|
2017-03-10 18:14:00 +00:00
|
|
|
|
|
|
|
// ==License==
|
|
|
|
// Copyright (C) 2014 Michael Wiencek
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights
|
|
|
|
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
// copies of the Software, and to permit persons to whom the Software is
|
|
|
|
// furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
// THE SOFTWARE.
|
|
|
|
//
|
|
|
|
// Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
// holders shall not be used in advertising or otherwise to promote the sale,
|
|
|
|
// use or other dealings in this Software without prior written
|
|
|
|
// authorization.
|
|
|
|
// ==/License==
|
|
|
|
|
2015-08-03 14:38:39 +00:00
|
|
|
//**************************************************************************//
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
var scr = document.createElement('script');
|
|
|
|
scr.textContent = `(${fastCancelScript})();`;
|
2015-08-03 14:38:39 +00:00
|
|
|
document.body.appendChild(scr);
|
|
|
|
|
|
|
|
function fastCancelScript() {
|
2018-11-20 22:18:49 +00:00
|
|
|
let totalCancels = 0;
|
2015-08-03 14:38:39 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let $status = $('<div></div>')
|
2015-08-03 14:38:39 +00:00
|
|
|
.css({
|
2018-11-20 22:18:49 +00:00
|
|
|
position: 'fixed',
|
|
|
|
right: '0',
|
|
|
|
bottom: '0',
|
|
|
|
background: '#FFBA58',
|
|
|
|
'border-top': '1px #000 solid',
|
|
|
|
'border-left': '1px #000 solid',
|
2020-04-05 14:01:21 +00:00
|
|
|
padding: '0.5em',
|
2015-08-03 14:38:39 +00:00
|
|
|
})
|
2018-11-20 22:18:49 +00:00
|
|
|
.appendTo('body')
|
2015-08-03 14:38:39 +00:00
|
|
|
.hide();
|
|
|
|
|
|
|
|
function updateStatus() {
|
|
|
|
if (totalCancels === 0) {
|
|
|
|
$status.hide();
|
|
|
|
} else {
|
2018-11-20 22:18:49 +00:00
|
|
|
$status.text(`Canceling ${totalCancels} edit${totalCancels > 1 ? 's' : ''}...`).show();
|
2015-08-03 14:38:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
document.body.addEventListener('click', function (event) {
|
2018-11-20 22:18:49 +00:00
|
|
|
if (event.target && event.target.tagName && event.target.tagName == 'A' && event.target.classList.contains('negative')) {
|
2016-06-07 12:29:09 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
event.preventDefault();
|
|
|
|
totalCancels += 1;
|
|
|
|
updateStatus();
|
2015-08-03 14:38:39 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let $self = $(event.target),
|
|
|
|
$edit = $self.parents('div.edit-list:eq(0)');
|
2015-08-03 14:38:39 +00:00
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
pushRequest(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
let editNote = $edit.find('div.add-edit-note textarea').val();
|
|
|
|
let data = { 'confirm.edit_note': editNote };
|
2015-08-03 14:38:39 +00:00
|
|
|
|
2016-06-07 12:29:09 +00:00
|
|
|
$.ajax({
|
2018-11-20 22:18:49 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: $self.attr('href'),
|
2016-06-07 12:29:09 +00:00
|
|
|
data: data,
|
2020-04-05 14:01:21 +00:00
|
|
|
error: function (request, status, error) {
|
2016-06-07 12:29:09 +00:00
|
|
|
$self
|
|
|
|
.css({
|
2018-11-20 22:18:49 +00:00
|
|
|
background: 'red',
|
|
|
|
color: 'yellow',
|
2020-04-05 14:01:21 +00:00
|
|
|
cursor: 'help',
|
2016-06-07 12:29:09 +00:00
|
|
|
})
|
2018-11-20 22:18:49 +00:00
|
|
|
.attr('title', `Error cancelling this edit: “${error}”`);
|
|
|
|
$edit.css({ border: '6px solid red' }).show();
|
2016-06-07 12:29:09 +00:00
|
|
|
},
|
2020-04-05 14:01:21 +00:00
|
|
|
complete: function () {
|
2016-06-07 12:29:09 +00:00
|
|
|
$edit.remove();
|
|
|
|
totalCancels -= 1;
|
|
|
|
updateStatus();
|
2020-04-05 14:01:21 +00:00
|
|
|
},
|
2016-06-07 12:29:09 +00:00
|
|
|
});
|
2015-08-03 14:38:39 +00:00
|
|
|
});
|
2016-06-07 12:29:09 +00:00
|
|
|
$edit.hide();
|
|
|
|
}
|
2015-08-03 14:38:39 +00:00
|
|
|
});
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$("div#edits > form[action$='/edit/enter_votes']").on('submit', function (event) {
|
2018-11-20 22:18:49 +00:00
|
|
|
if (totalCancels > 0) {
|
|
|
|
event.preventDefault();
|
|
|
|
alert(`Please wait, ${totalCancels > 1 ? `${totalCancels} edits are` : 'an edit is'} being cancelled in the background.`);
|
|
|
|
}
|
2015-09-15 17:56:13 +00:00
|
|
|
});
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
var pushRequest = (function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
let queue = [],
|
2015-08-03 14:38:39 +00:00
|
|
|
last = 0,
|
|
|
|
active = false,
|
|
|
|
rate = 2000;
|
|
|
|
|
|
|
|
function next() {
|
|
|
|
if (queue.length === 0) {
|
|
|
|
active = false;
|
|
|
|
} else {
|
|
|
|
queue.shift()();
|
|
|
|
last = new Date().getTime();
|
|
|
|
setTimeout(next, rate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
return function (req) {
|
2015-08-03 14:38:39 +00:00
|
|
|
queue.push(req);
|
|
|
|
|
|
|
|
if (!active) {
|
|
|
|
active = true;
|
2018-11-20 22:18:49 +00:00
|
|
|
let now = new Date().getTime();
|
2015-08-03 14:38:39 +00:00
|
|
|
if (now - last >= rate) {
|
|
|
|
next();
|
|
|
|
} else {
|
2018-11-20 22:18:49 +00:00
|
|
|
let timeout = rate - now + last;
|
2015-08-03 14:38:39 +00:00
|
|
|
setTimeout(next, timeout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2018-11-20 22:18:49 +00:00
|
|
|
})();
|
2015-08-03 14:38:39 +00:00
|
|
|
}
|