Restore work language list #175

Load language list from /release/add page
as it is no longer available from /work/create page
Emphasise and order [No lyrics] equivalent No linguistic content
This commit is contained in:
jesus2099 2023-06-29 17:03:36 +02:00
parent e54d39a1e5
commit edc79dffba

View file

@ -1,13 +1,15 @@
// ==UserScript==
// @name MusicBrainz: Batch-add "performance of" relationships
// @description Batch link recordings to works from artist Recordings page.
// @version 2023.6.30.1538
// @version 2023.6.30.19
// @author Michael Wiencek
// @license X11
// @downloadURL https://github.com/murdos/musicbrainz-userscripts/raw/master/batch-add-recording-relationships.user.js
// @match *://*.musicbrainz.org/artist/*/recordings*
// ==/UserScript==
/* global MB:readonly */
// ==License==
// Copyright (C) 2014 Michael Wiencek
//
@ -389,16 +391,31 @@ function batch_recording_rels(gm_info) {
$container.find('table').find('td').css('width', 'auto');
$container.children('tbody').children('tr').children('td').css({ padding: '0.5em', 'vertical-align': 'top' });
// Get actual work types/languages
// Get actual work types
ws_requests.unshift_get('/dialog?path=%2Fwork%2Fcreate', function (data) {
let nodes = $.parseHTML(data);
Object.entries($work_options).forEach(function populate([kind, $obj]) {
$obj.append($(`#id-edit-work\\.${kind}_id`, nodes).children())
.val(setting(`work_${kind}`) || 0)
.on('change', function () {
setting(`work_${kind}`, this.value);
});
});
$work_options.type
.append($(`#id-edit-work\\.type_id`, nodes).children())
.val(setting(`work_type`) || 0)
.on('change', function () {
setting(`work_type`, this.value);
});
});
// Get actual (release) languages
ws_requests.unshift_get('/release/add', function (data) {
let nodes = $.parseHTML(data);
$work_options.language
.append($(`select#language`, nodes).children())
.val(setting(`work_language`) || 0)
.on('change', function () {
setting(`work_language`, this.value);
});
// move [No lyrics] equivalent up besides [Multiple languages], to mimick work language list
$work_options.language
.find(`option[value='${MB.constants.LANGUAGE_MUL_ID}']`)
.first()
.after($work_options.language.find(`option[value='${MB.constants.LANGUAGE_ZXX_ID}']`).first().prepend('[').append(']'));
});
$('<span></span>').append('<img src="/static/images/icons/loading.gif"/> ', $recordings_load_msg).insertBefore($relate_table);
@ -1111,11 +1128,12 @@ function batch_recording_rels(gm_info) {
function create_new_work(title, callback, edit_mode) {
function post_edit() {
let data = `edit-work.name=${encodeURIComponent(title)}`;
Object.entries($work_options).forEach(function ([kind, $obj]) {
if ($obj.val()) {
data += `&edit-work.${kind}_id=${$obj.val()}`;
}
});
if ($work_options.type.val()) {
data += `&edit-work.type_id=${$work_options.type.val()}`;
}
if ($work_options.language.val()) {
data += `&edit-work.languages.0=${$work_options.language.val()}`;
}
data += `&edit-work.edit_note=${encodeURIComponent(
document.getElementById('bpr-edit-note').value.trim() + edit_note_signature.replace(/%edit-mode%/g, edit_mode)
)}`;