Skip to content

Commit bdf7341

Browse files
authored
fix(mb_discids_detector): adapt to DOM changes in Orpheus and derive the ID from adjacent elements (#1001)
1 parent f79db7e commit bdf7341

2 files changed

Lines changed: 61 additions & 6 deletions

File tree

src/userscripts/mb_discids_detector/gazalle-forum-logic/gazalle-logic.ts

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@ import { checkAndDisplayDiscs } from '../utils/check-and-display-disks';
55

66
interface ResolveLogActionProps {
77
onclick: string;
8+
link: HTMLAnchorElement;
89
serverHost: string;
910
}
1011

11-
const resolveLogAction = ({ onclick, serverHost }: ResolveLogActionProps): LogAction | null => {
12+
const resolveLogAction = ({ onclick, link, serverHost }: ResolveLogActionProps): LogAction | null => {
13+
if (serverHost.match(/orpheus/) && link.classList.contains('view-riplog')) {
14+
LOGGER.debug('Orpheus');
15+
return 'viewlog';
16+
}
1217
if (onclick.match(/show_logs/)) {
18+
// TODO: Orpheus had changed the way to show logs, so this is not working anymore. Will keep it here just in case and remove in the future.
1319
if (serverHost.match(/orpheus/)) {
1420
LOGGER.debug('Orpheus');
1521
return 'viewlog';
@@ -31,6 +37,56 @@ const resolveLogAction = ({ onclick, serverHost }: ResolveLogActionProps): LogAc
3137
return null;
3238
};
3339

40+
const getTorrentIdFromHref = (link: HTMLAnchorElement): string | null => {
41+
const href = link.getAttribute('href');
42+
if (!href) {
43+
return null;
44+
}
45+
46+
const url = new URL(href, window.location.origin);
47+
const torrentId = url.searchParams.get('torrentid');
48+
if (torrentId) {
49+
return torrentId;
50+
}
51+
52+
const action = url.searchParams.get('action');
53+
if (
54+
(url.pathname.endsWith('/torrents.php') && action === 'download') ||
55+
(url.pathname.endsWith('/ajax.php') && action === 'torrent') ||
56+
(url.pathname.endsWith('/reportsv2.php') && action === 'report')
57+
) {
58+
return url.searchParams.get('id');
59+
}
60+
61+
return null;
62+
};
63+
64+
const resolveTorrentId = (link: HTMLAnchorElement, onclick: string): string | null => {
65+
const inlineHandlerMatch = /(show_logs|get_log|show_log)\('(\d+)/.exec(onclick);
66+
if (inlineHandlerMatch?.[2]) {
67+
return inlineHandlerMatch[2];
68+
}
69+
70+
const dataIdContainer = link.closest<HTMLElement>('[data-id]');
71+
if (dataIdContainer?.dataset['id']) {
72+
return dataIdContainer.dataset['id'];
73+
}
74+
75+
const torrentInfo = link.closest('tr') ?? link.parentElement;
76+
if (!torrentInfo) {
77+
return null;
78+
}
79+
80+
for (const torrentLink of torrentInfo.querySelectorAll<HTMLAnchorElement>('a[href]')) {
81+
const torrentId = getTorrentIdFromHref(torrentLink);
82+
if (torrentId) {
83+
return torrentId;
84+
}
85+
}
86+
87+
return null;
88+
};
89+
3490
interface ProcessLogLinkProps {
3591
link: HTMLAnchorElement;
3692
artistName: string;
@@ -45,14 +101,13 @@ function processLogLink({ link, artistName, releaseName, serverHost }: ProcessLo
45101

46102
LOGGER.debug('Log link', link);
47103
const onclick = link.getAttribute('onclick') ?? '';
48-
const logAction = resolveLogAction({ onclick, serverHost });
104+
const logAction = resolveLogAction({ onclick, link, serverHost });
49105
if (!logAction) {
50106
return;
51107
}
52108

53-
const targetContainer = link.closest('.linkbox');
54-
const torrentIdMatch = /(show_logs|get_log|show_log)\('(\d+)/.exec(onclick);
55-
const torrentId = torrentIdMatch?.[2];
109+
const targetContainer = link.closest('.linkbox') ?? link.closest('[data-id]') ?? link.parentElement;
110+
const torrentId = resolveTorrentId(link, onclick);
56111
if (!torrentId) {
57112
return;
58113
}

src/userscripts/mb_discids_detector/meta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Musicbrainz DiscIds Detector",
33
"description": "Generate MusicBrainz DiscIds from online EAC logs, and check existence in MusicBrainz database.",
4-
"version": "2026.07.05.10",
4+
"version": "2026.07.17.1",
55
"author": "[unknown]",
66
"namespace": "https://github.com/murdos/musicbrainz-userscripts",
77
"downloadURL": "https://raw.githubusercontent.com/murdos/musicbrainz-userscripts/dist/mb_discids_detector.user.js",

0 commit comments

Comments
 (0)