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

fix(inline recs): Crash when no existing div.ars #763

Merged
merged 2 commits into from
May 2, 2024
Merged
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
13 changes: 9 additions & 4 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 2022.6.14
// @version 2024.5.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 Down Expand Up @@ -84,12 +84,17 @@ function insertRows(recordingTd, recordingInfo) {
.map(formatRow)
.map(row => '<dl class="ars"><dt>appears on:</dt><dd>' + row + '</dd></dl>')
.join('\n');
recordingTd.querySelector('div.ars')
.insertAdjacentHTML('beforebegin', '<div class="ars ROpdebee_inline_tracks">' + rowElements + '</div>');
rowElements = '<div class="ars ROpdebee_inline_tracks">' + rowElements + '</div>';
let existingArs = recordingTd.querySelector('div.ars');
if (existingArs) {
existingArs.insertAdjacentHTML('beforebegin', rowElements);
} else {
recordingTd.insertAdjacentHTML('beforeend', rowElements);
}
}

function loadAndInsert() {
let recAnchors = document.querySelectorAll('table.medium td > a[href^="/recording/"]:first-child, table.medium td > span:first-child > a[href^="/recording/"]:first-child');
let recAnchors = document.querySelectorAll('table.medium td > a[href^="/recording/"]:first-child, table.medium td > span:first-child > a[href^="/recording/"]:first-child, table.medium td > span:first-child > span:first-child > a[href^="/recording/"]:first-child');
let todo = [...recAnchors]
.map((a) => [a.closest('td'), a.href.split('/recording/')[1]])
.filter(([td]) => !td.querySelector('div.ars.ROpdebee_inline_tracks'));
Expand Down