Greasy Fork is available in English.
Auto sets track lengths for media by unique attached disc id.
当前为
// ==UserScript==
// @name MB Auto Track Lengths
// @version 1.00
// @match https://musicbrainz.org/release/*/discids
// @match https://beta.musicbrainz.org/release/*/discids
// @match https://musicbrainz.org/cdtoc/*
// @match https://beta.musicbrainz.org/cdtoc/*
// @run-at document-end
// @author Anakunda
// @namespace http://greasyfork.icu/users/321857
// @copyright 2024, Anakunda (http://greasyfork.icu/users/321857)
// @license GPL-3.0-or-later
// @description Auto sets track lengths for media by unique attached disc id.
// @require https://openuserjs.org/src/libs/Anakunda/xhrLib.js
// ==/UserScript==
'use strict';
function getTrackLengths(tr) {
const setTrackLengths = Array.prototype.find.call(tr.querySelectorAll('td a'),
a => a.textContent.trim() == 'Set track lengths');
return setTrackLengths || null;
}
const isDiscIdRow = tr => ['odd', 'even'].some(cls => tr.classList.contains(cls));
const sections = document.location.pathname.startsWith('/release/') ? Array.from(document.body.querySelectorAll('table.tbl > tbody > tr.subh'), function(subh) {
const discIds = [ ];
for (let tr = subh.nextElementSibling; tr != null && isDiscIdRow(tr); tr = tr.nextElementSibling)
discIds.push(getTrackLengths(tr));
return discIds;
}) : document.location.pathname.startsWith('/cdtoc/') ?
Array.prototype.filter.call(document.body.querySelectorAll('table.tbl > tbody > tr'), isDiscIdRow)
.map(getTrackLengths) : null;
if (sections != null) sections.forEach(function(section) {
if (section.length != 1) return;
let unsetDiscId = section.filter(Boolean);
if (unsetDiscId.length == 1) unsetDiscId = unsetDiscId[0]; else return;
const postData = new URLSearchParams({ 'confirm.edit_note': '' });
//postData.set('make_votable', 1);
localXHR(unsetDiscId.href, { responseType: null }, postData).then(function(statusCode) {
unsetDiscId.replaceWith(Object.assign(document.createElement('span'), {
textContent: 'Track lengths successfully set',
style: 'color: green;',
title: 'Status code: ' + statusCode,
}));
}, function(reason) {
unsetDiscId.replaceWith(Object.assign(document.createElement('span'), {
textContent: 'Error setting track lengths',
style: 'color: red;',
title: reason,
}));
});
});