-
Notifications
You must be signed in to change notification settings - Fork 15
/
mb-edit-fill_event_setlist.user.js
75 lines (72 loc) · 3.07 KB
/
mb-edit-fill_event_setlist.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
73
74
75
/* global $ sidebar relEditor */
'use strict';
// ==UserScript==
// @name MusicBrainz event editor: Fill event setlist
// @namespace mbz-loujine
// @author loujine
// @version 2021.10.30
// @downloadURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-edit-fill_event_setlist.user.js
// @updateURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-edit-fill_event_setlist.user.js
// @supportURL https://github.com/loujine/musicbrainz-scripts
// @icon https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/icon.png
// @description musicbrainz.org event editor: Fill event setlist
// @compatible firefox+tampermonkey
// @license MIT
// @require https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mbz-loujine-common.js
// @include http*://*musicbrainz.org/event/*/edit
// @include http*://*musicbrainz.org/event/create*
// @grant none
// @run-at document-end
// ==/UserScript==
(function displayToolbar() {
document.getElementsByClassName('half-width')[0].insertAdjacentHTML(
'afterend', '<div id="side-col" style="float: right;"></div>');
relEditor.container(document.getElementById('side-col')).insertAdjacentHTML(
'beforeend', `
<h3>Complete entity in setlist</h3>
<p>Select text in the setlist box and click one of the buttons
to add the right symbol and MBID</p>
<input type="button" id="fillArtist" value="Fill artist MBID">
<input type="button" id="fillWork" value="Fill work MBID">
`);
document.getElementById('loujine-menu').style.marginLeft = '550px';
})();
function fillEventSetlist(entityType) {
const area = document.getElementById('id-edit-event.setlist');
// document.getSelection() does not work on textarea
const entity = area.value.substring(area.selectionStart, area.selectionEnd);
fetch(`/ws/2/${entityType}?query=${entityType}:${entity}&limit=1&fmt=json`).then(
resp => resp.json()
).then(
resp => {
const filledEntity = entityType === 'artist' ?
`@ [${resp.artists[0].id}|${resp.artists[0].name}]` :
`* [${resp.works[0].id}|${resp.works[0].title}]`;
area.value = area.value.replace(entity, filledEntity);
}
)
}
$(document).ready(function () {
let appliedNote = false;
document.getElementById('fillArtist').addEventListener('click',
() => {
fillEventSetlist('artist')
if (!appliedNote) {
document.getElementById('id-edit-event.edit_note')
.value = sidebar.editNote(GM_info.script);
appliedNote = true;
}
}
);
document.getElementById('fillWork').addEventListener('click',
() => {
fillEventSetlist('work')
if (!appliedNote) {
document.getElementById('id-edit-event.edit_note')
.value = sidebar.editNote(GM_info.script);
appliedNote = true;
}
}
);
return false;
});