mirror of
https://github.com/murdos/musicbrainz-userscripts
synced 2024-11-10 05:04:13 +00:00
recording-comments: Fill input based on recording MBID instead of index
Otherwise the script always loads the disambiguation comments for the first tracks on the release, independent of the currently expanded medium. This lead to wrong initial comments for /disc URLs. Edit submission is already based on MBIDs, so there is no problem with that.
This commit is contained in:
parent
41b34e57df
commit
cfbe1a5531
1 changed files with 13 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
|||
// ==UserScript==
|
||||
// @name MusicBrainz: Set recording comments for a release
|
||||
// @description Batch set recording comments from a Release page.
|
||||
// @version 2022.2.3
|
||||
// @version 2022.2.8.1
|
||||
// @author Michael Wiencek
|
||||
// @license X11
|
||||
// @namespace 790382e7-8714-47a7-bfbd-528d0caa2333
|
||||
|
@ -70,6 +70,10 @@ function setRecordingComments() {
|
|||
node = $td.children('td > .mp, td > .name-variation, td > a[href^=\\/recording\\/]').filter(':first'),
|
||||
$input = $('<input />').addClass('recording-comment').insertAfter(node);
|
||||
|
||||
let link = $("a[href^='/recording/']", $td).first().attr('href');
|
||||
let mbid = link.match(MBID_REGEX)[0];
|
||||
$input.data('mbid', mbid);
|
||||
|
||||
if (!editing) {
|
||||
$input.hide();
|
||||
}
|
||||
|
@ -80,16 +84,17 @@ function setRecordingComments() {
|
|||
let release = location.pathname.match(MBID_REGEX)[0];
|
||||
|
||||
$.get(`/ws/2/release/${release}?inc=recordings&fmt=json`, function (data) {
|
||||
let comments = Array.from(data.media)
|
||||
let recordings = Array.from(data.media)
|
||||
.map(medium => medium.tracks)
|
||||
.flat()
|
||||
.map(track => track.recording)
|
||||
.map(recording => recording.disambiguation);
|
||||
.map(track => track.recording);
|
||||
|
||||
for (let i = 0, len = comments.length; i < len; i++) {
|
||||
let comment = comments[i];
|
||||
$inputs.eq(i).val(comment).data('old', comment);
|
||||
}
|
||||
$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);
|
||||
});
|
||||
});
|
||||
}, 1000);
|
||||
|
||||
|
|
Loading…
Reference in a new issue