Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(inline recs): Show track durations; Dim current release occurrences #789

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions mb_qol_inline_recording_tracks.user.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ==UserScript==
// @name MB: QoL: Inline all recording's tracks on releases
// @version 2024.7.25
// @version 2024.8.2
// @description Display all tracks and releases on which a recording appears from the release page.
// @author ROpdebee
// @license MIT; https://opensource.org/licenses/MIT
Expand All @@ -15,6 +15,11 @@
// @grant none
// ==/UserScript==

let releaseMbid = location.pathname.match(/\/release\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/);
if (releaseMbid) {
releaseMbid = releaseMbid[1];
}

function splitChunks(arr, chunkSize) {
let chunks = [];
for (let i = 0; i < arr.length; i += chunkSize) {
Expand Down Expand Up @@ -77,14 +82,17 @@ function getReleaseName(release) {
}

function formatRow(release) {
return `${getReleaseName(release)} (${getTrackIndices(release.media)})`;
let rowHead = '<dl class="ars"';
if (releaseMbid === release.id) {
rowHead = rowHead + ' style="opacity: .6; filter: contrast(.2);" title="current release"';
}
return `${rowHead}><dt>appears on:</dt><dd>${getReleaseName(release)} (${getTrackIndices(release.media)}) <span class="comment">${toIntelligibleTime(release.media[0].track[0].length)}</span></dd></dl>`;
}

function insertRows(recordingTd, recordingInfo) {
let rowElements = recordingInfo.releases
.sort(compareReleases)
.map(formatRow)
.map(row => '<dl class="ars"><dt>appears on:</dt><dd>' + row + '</dd></dl>')
.join('\n');
rowElements = '<div class="ars ROpdebee_inline_tracks">' + rowElements + '</div>';
let existingArs = recordingTd.querySelector('div.ars');
Expand Down Expand Up @@ -151,3 +159,12 @@ onReactHydrated(document.querySelector('.tracklist-and-credits'), () => {
document.querySelector('span#medium-toolbox')
.firstChild.before(button, ' | ');
});

function toIntelligibleTime(_ms) {
var ms = typeof _ms == "string" ? parseInt(_ms, 10) : _ms;
if (ms > 0) {
var d = new Date(ms);
return (d.getUTCHours() > 0 ? d.getUTCHours() + ":" + d.getUTCMinutes().toString().padStart(2, "0") : d.getUTCMinutes()) + ":" + d.getUTCSeconds().toString().padStart(2, "0") + (d.getUTCMilliseconds() > 0 ? "." + d.getUTCMilliseconds().toString().padStart(3, "0") : "");
}
return "?:??";
}