2015-04-07 19:00:24 +00:00
|
|
|
// ==UserScript==
|
2014-11-05 21:53:59 +00:00
|
|
|
// @name MusicBrainz: Set recording comments for a release
|
2017-03-10 18:50:20 +00:00
|
|
|
// @description Batch set recording comments from a Release page.
|
2024-06-18 06:18:35 +00:00
|
|
|
// @version 2024.6.18.1
|
2014-11-05 21:53:59 +00:00
|
|
|
// @author Michael Wiencek
|
2017-03-10 18:14:00 +00:00
|
|
|
// @license X11
|
2014-11-05 21:55:10 +00:00
|
|
|
// @namespace 790382e7-8714-47a7-bfbd-528d0caa2333
|
2017-03-10 18:57:54 +00:00
|
|
|
// @downloadURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/set-recording-comments.user.js
|
|
|
|
// @updateURL https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/master/set-recording-comments.user.js
|
2024-06-18 06:18:35 +00:00
|
|
|
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/release\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}(\/disc\/\d+|(\?.+?)?$)/
|
2014-11-11 15:27:43 +00:00
|
|
|
// @grant none
|
2021-08-05 17:18:39 +00:00
|
|
|
// @run-at document-idle
|
2014-11-05 21:53:59 +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==
|
|
|
|
|
2022-02-03 17:45:49 +00:00
|
|
|
setTimeout(function () {
|
|
|
|
const scr = document.createElement('script');
|
|
|
|
scr.textContent = `$(${setRecordingComments});`;
|
|
|
|
document.body.appendChild(scr);
|
|
|
|
}, 1000);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
|
|
|
function setRecordingComments() {
|
2018-11-20 22:18:49 +00:00
|
|
|
let $tracks;
|
|
|
|
let $inputs = $();
|
|
|
|
let EDIT_RECORDING_EDIT = 72;
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$('head').append(
|
|
|
|
$('<style></style>').text(
|
|
|
|
'input.recording-comment { background: inherit; border: 1px #999 solid; width: 32em; margin-left: 0.5em; }'
|
|
|
|
)
|
|
|
|
);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2020-09-13 11:25:23 +00:00
|
|
|
const delay = setInterval(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
$tracks = $('.medium tbody tr[id]');
|
2014-11-05 21:53:59 +00:00
|
|
|
|
|
|
|
if ($tracks.length) {
|
|
|
|
clearInterval(delay);
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$tracks.each(function () {
|
|
|
|
let $td = $(this).children('td:not(.pos):not(.video):not(.rating):not(.treleases)').has('a[href^=\\/recording\\/]'),
|
2018-11-20 22:18:49 +00:00
|
|
|
node = $td.children('td > .mp, td > .name-variation, td > a[href^=\\/recording\\/]').filter(':first'),
|
2020-04-05 14:01:21 +00:00
|
|
|
$input = $('<input />').addClass('recording-comment').insertAfter(node);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2022-02-08 19:40:21 +00:00
|
|
|
let link = $("a[href^='/recording/']", $td).first().attr('href');
|
|
|
|
let mbid = link.match(MBID_REGEX)[0];
|
|
|
|
$input.data('mbid', mbid);
|
|
|
|
|
2014-11-05 21:53:59 +00:00
|
|
|
if (!editing) {
|
|
|
|
$input.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
$inputs = $inputs.add($input);
|
|
|
|
});
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let release = location.pathname.match(MBID_REGEX)[0];
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$.get(`/ws/2/release/${release}?inc=recordings&fmt=json`, function (data) {
|
2022-02-08 19:40:21 +00:00
|
|
|
let recordings = Array.from(data.media)
|
2020-09-13 11:09:08 +00:00
|
|
|
.map(medium => medium.tracks)
|
|
|
|
.flat()
|
2022-02-08 19:40:21 +00:00
|
|
|
.map(track => track.recording);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2022-02-08 19:40:21 +00:00
|
|
|
$inputs.each(function () {
|
|
|
|
let mbid = $(this).data('mbid');
|
|
|
|
let recording = recordings.find(recording => recording.id === mbid);
|
|
|
|
let comment = recording ? recording.disambiguation : '';
|
|
|
|
$(this).val(comment).data('old', comment);
|
|
|
|
});
|
2014-11-05 21:53:59 +00:00
|
|
|
});
|
|
|
|
}, 1000);
|
|
|
|
|
2022-02-03 17:45:49 +00:00
|
|
|
if (!location.pathname.match(/^\/release\/[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/)) {
|
2014-11-05 21:53:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-13 11:25:23 +00:00
|
|
|
const MBID_REGEX = /[a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12}/;
|
|
|
|
let editing = false,
|
2014-11-05 21:53:59 +00:00
|
|
|
activeRequest = null;
|
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$('body').on('input.rc', '.recording-comment', function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
$(this).css('border-color', this.value === $(this).data('old') ? '#999' : 'red');
|
2014-11-05 21:53:59 +00:00
|
|
|
});
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let $container = $('<div></div>').insertAfter('h2.tracklist');
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$('<button>Edit recording comments</button>')
|
|
|
|
.addClass('styled-button')
|
2020-04-05 14:01:21 +00:00
|
|
|
.on('click', function () {
|
2014-11-05 21:53:59 +00:00
|
|
|
editing = !editing;
|
2020-04-05 14:01:21 +00:00
|
|
|
$('#set-recording-comments').add($inputs).toggle(editing);
|
2018-11-20 22:18:49 +00:00
|
|
|
$(this).text(`${editing ? 'Hide' : 'Edit'} recording comments`);
|
2015-06-24 11:00:19 +00:00
|
|
|
if (editing) {
|
2018-11-20 22:18:49 +00:00
|
|
|
$('#all-recording-comments').focus();
|
2015-06-24 11:00:19 +00:00
|
|
|
}
|
2014-11-05 21:53:59 +00:00
|
|
|
})
|
|
|
|
.appendTo($container);
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$container.append(
|
|
|
|
'\
|
2014-11-05 21:53:59 +00:00
|
|
|
<table id="set-recording-comments">\
|
|
|
|
<tr>\
|
2015-06-24 11:00:19 +00:00
|
|
|
<td><label for="all-recording-comments">Set all visible comments to:</label></td>\
|
2014-11-07 13:59:12 +00:00
|
|
|
<td><input type="text" id="all-recording-comments" style="width: 32em;"></td>\
|
2014-11-05 21:53:59 +00:00
|
|
|
</tr>\
|
|
|
|
<tr>\
|
|
|
|
<td><label for="recording-comments-edit-note">Edit note:</label></td>\
|
2014-11-07 13:59:12 +00:00
|
|
|
<td><textarea id="recording-comments-edit-note" style="width: 32em;" rows="5"></textarea></td>\
|
2014-11-05 21:53:59 +00:00
|
|
|
</tr>\
|
2019-05-10 09:19:59 +00:00
|
|
|
<tr>\
|
|
|
|
<td colspan="2" class="auto-editor">\
|
|
|
|
<label>\
|
|
|
|
<input id="make-recording-comments-votable" type="checkbox">\
|
|
|
|
Make all edits votable.\
|
|
|
|
</label>\
|
|
|
|
</td>\
|
|
|
|
</tr>\
|
2014-11-05 21:53:59 +00:00
|
|
|
<tr>\
|
|
|
|
<td colspan="2">\
|
2015-06-24 11:00:19 +00:00
|
|
|
<button id="submit-recording-comments" class="styled-button">Submit changes (visible and marked red)</button>\
|
2014-11-05 21:53:59 +00:00
|
|
|
</td>\
|
|
|
|
</tr>\
|
2018-11-20 22:18:49 +00:00
|
|
|
</table>'
|
|
|
|
);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$('#set-recording-comments').hide();
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$('#all-recording-comments').on('input', function () {
|
|
|
|
$inputs.filter(':visible').val(this.value).trigger('input.rc');
|
2014-11-05 21:53:59 +00:00
|
|
|
});
|
|
|
|
|
2020-09-13 11:25:23 +00:00
|
|
|
const $submitButton = $('#submit-recording-comments').on('click', function () {
|
2014-11-05 21:53:59 +00:00
|
|
|
if (activeRequest) {
|
|
|
|
activeRequest.abort();
|
|
|
|
activeRequest = null;
|
2018-11-20 22:18:49 +00:00
|
|
|
$submitButton.text('Submit changes (marked red)');
|
|
|
|
$inputs.prop('disabled', false).trigger('input.rc');
|
2014-11-05 21:53:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
$submitButton.text('Submitting...click to cancel!');
|
|
|
|
$inputs.prop('disabled', true);
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let editData = [],
|
|
|
|
deferred = $.Deferred();
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2020-04-05 14:01:21 +00:00
|
|
|
$.each($tracks, function (i, track) {
|
2018-11-20 22:18:49 +00:00
|
|
|
if ($(track).filter(':visible').length > 0) {
|
|
|
|
let $input = $inputs.eq(i),
|
|
|
|
comment = $input.val();
|
|
|
|
if (comment === $input.data('old')) {
|
|
|
|
$input.prop('disabled', false);
|
2015-06-24 11:00:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
deferred
|
2020-04-05 14:01:21 +00:00
|
|
|
.done(function () {
|
|
|
|
$input.data('old', comment).trigger('input.rc').prop('disabled', false);
|
2015-06-24 11:00:19 +00:00
|
|
|
})
|
2020-04-05 14:01:21 +00:00
|
|
|
.fail(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
$input.css('border-color', 'red').prop('disabled', false);
|
2015-06-24 11:00:19 +00:00
|
|
|
});
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
let link = track.querySelector("td a[href^='/recording/']"),
|
2015-06-24 11:00:19 +00:00
|
|
|
mbid = link.href.match(MBID_REGEX)[0];
|
|
|
|
|
2018-11-20 22:18:49 +00:00
|
|
|
editData.push({ edit_type: EDIT_RECORDING_EDIT, to_edit: mbid, comment: comment });
|
2014-11-05 21:53:59 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (editData.length === 0) {
|
2018-11-20 22:18:49 +00:00
|
|
|
$inputs.prop('disabled', false);
|
|
|
|
$submitButton.prop('disabled', false).text('Submit changes (marked red)');
|
2014-11-05 21:53:59 +00:00
|
|
|
} else {
|
2018-11-20 22:18:49 +00:00
|
|
|
let editNote = $('#recording-comments-edit-note').val();
|
2019-05-10 09:19:59 +00:00
|
|
|
let makeVotable = document.getElementById('make-recording-comments-votable').checked;
|
2014-11-05 21:53:59 +00:00
|
|
|
|
2015-04-07 19:00:24 +00:00
|
|
|
activeRequest = $.ajax({
|
2018-11-20 22:18:49 +00:00
|
|
|
type: 'POST',
|
|
|
|
url: '/ws/js/edit/create',
|
|
|
|
dataType: 'json',
|
2019-05-10 09:19:59 +00:00
|
|
|
data: JSON.stringify({ edits: editData, editNote: editNote, makeVotable: makeVotable }),
|
2020-04-05 14:01:21 +00:00
|
|
|
contentType: 'application/json; charset=utf-8',
|
2018-11-20 22:18:49 +00:00
|
|
|
})
|
2020-04-05 14:01:21 +00:00
|
|
|
.always(function () {
|
2018-11-20 22:18:49 +00:00
|
|
|
$submitButton.prop('disabled', false).text('Submit changes (marked red)');
|
2015-04-07 19:00:24 +00:00
|
|
|
})
|
2020-04-05 14:01:21 +00:00
|
|
|
.done(function () {
|
2014-11-05 21:53:59 +00:00
|
|
|
deferred.resolve();
|
|
|
|
})
|
2020-04-05 14:01:21 +00:00
|
|
|
.fail(function () {
|
2014-11-05 21:53:59 +00:00
|
|
|
deferred.reject();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|