From 2ea6bef953c944821774979e25c1b70fc6b5f458 Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Mon, 3 Aug 2015 16:38:39 +0200 Subject: [PATCH] =?UTF-8?q?Added=20=E2=80=9CMusicBrainz:=20Fast=20cancel?= =?UTF-8?q?=20edits=E2=80=9D=20from=20http://userscripts-mirror.org/script?= =?UTF-8?q?s/show/125781=20=E2=86=92=20http://userscripts-mirror.org/scrip?= =?UTF-8?q?ts/source/125781.user.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jesus2099 --- fast-cancel-edits.user.js | 112 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 fast-cancel-edits.user.js diff --git a/fast-cancel-edits.user.js b/fast-cancel-edits.user.js new file mode 100644 index 0000000..9e40c13 --- /dev/null +++ b/fast-cancel-edits.user.js @@ -0,0 +1,112 @@ +// ==UserScript== +// @name MusicBrainz: Fast cancel edits +// @version 2013-08-07 +// @author Michael Wiencek +// @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* +// ==/UserScript== +//**************************************************************************// + +var scr = document.createElement("script"); +scr.textContent = "(" + fastCancelScript + ")();"; +document.body.appendChild(scr); + +function fastCancelScript() { + var totalCancels = 0; + + var $status = $("
") + .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 }; + + $.post($self.attr("href"), data, function () { + totalCancels -= 1; + updateStatus(); + }); + }); + $edit.remove(); + }); + + 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); + } + } + }; + }()); +}