-
Notifications
You must be signed in to change notification settings - Fork 15
/
mb-reledit-release_rel_to_recording_rel.user.js
72 lines (69 loc) · 3 KB
/
mb-reledit-release_rel_to_recording_rel.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* global $ MB server relEditor */
'use strict';
// ==UserScript==
// @name MusicBrainz relation editor: Replace release relations by recording relations
// @namespace mbz-loujine
// @author loujine
// @version 2023.3.9
// @downloadURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-reledit-release_rel_to_recording_rel.user.js
// @updateURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-reledit-release_rel_to_recording_rel.user.js
// @supportURL https://github.com/loujine/musicbrainz-scripts
// @icon https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/icon.png
// @description musicbrainz.org relation editor: Replace release relations by recording relations
// @compatible firefox+tampermonkey
// @license MIT
// @require https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mbz-loujine-common.js
// @include http*://*musicbrainz.org/release/*/edit-relationships
// @grant none
// @run-at document-end
// ==/UserScript==
function moveAR() {
const release = MB.relationshipEditor.state.entity;
const recordings = MB.tree.toArray(MB.relationshipEditor.state.selectedRecordings);
release.relationships.filter(
rel => Object.keys(server.releaseLinkTypeID).includes(String(rel.linkTypeID))
).map(artistRel => {
recordings.map(rec => {
MB.relationshipEditor.dispatch({
type: 'update-relationship-state',
sourceEntity: rec,
...relEditor.dispatchDefaults,
newRelationshipState: {
...relEditor.stateDefaults,
_status: 1,
attributes: relEditor.createAttributeTree(artistRel.attributes),
begin_date: artistRel.begin_date,
entity0: artistRel.target,
entity1: rec,
end_date: artistRel.end_date,
ended: artistRel.ended,
id: MB.relationshipEditor.getRelationshipStateId(),
linkTypeID: server.releaseToRecordingLink(artistRel.linkTypeID),
},
});
});
if (recordings.length) {
document.getElementById(
`remove-relationship-${artistRel.target_type}-` +
`${artistRel.source_type}-${artistRel.id}`
).click();
}
});
}
(function displayToolbar() {
relEditor.container(document.querySelector('div.tabs'))
.insertAdjacentHTML('beforeend', `
<h3>Move release relations to recordings</h3>
<input type="button" id="moveAR" value="Move release relations to selected recordings">
`);
})();
$(document).ready(function () {
document.getElementById('moveAR').addEventListener('click', () => {
moveAR();
relEditor.editNote(
GM_info.script,
'Move performers in release relations to individual recordings'
);
});
return false;
});