-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmb_spotify_isrc_link.user.js
70 lines (58 loc) · 2.02 KB
/
mb_spotify_isrc_link.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// ==UserScript==
// @name MusicBrainz: Add Spotify ISRC link to release pages
// @version 2024.11.16.1
// @description Adds an "import ISRCs" link to MusicBrainz release pages with a Spotify URL
// @author atj
// @license MIT; https://opensource.org/licenses/MIT
// @namespace https://github.com/atj/userscripts
// @downloadURL https://raw.github.com/atj/userscripts/main/mb_spotify_isrc_link.user.js
// @updateURL https://raw.github.com/atj/userscripts/main/mb_spotify_isrc_link.user.js
// @match *://*.musicbrainz.org/release/*
// @grant none
// @run-at document-idle
// ==/UserScript==
const SpotifyLinkRegexp = new RegExp(
'^https?://open.spotify.com/album/([0-9a-z]+)',
'i'
);
function addImportIsrcsLink() {
const releaseRels = document.getElementById('release-relationships');
if (!releaseRels) {
return;
}
let spotifyLink;
let spotifyId;
for (const bdi of releaseRels.getElementsByTagName('bdi')) {
const matches = SpotifyLinkRegexp.exec(bdi.innerText);
if (matches) {
spotifyId = matches[1];
spotifyLink = bdi.parentElement;
break;
}
}
if (spotifyId === undefined) {
return;
}
// ISRCHunt doesn't require an MBID
// const mbId = window.location.href.replace(
// /^.+\/release\/([-0-9a-f]{36}).*$/i,
// '$1'
// );
let curElem = spotifyLink.nextElementSibling.nextSibling;
let elem = document.createTextNode(' [');
curElem = insertAfter(elem, curElem);
elem = document.createElement('a');
elem.target = '_blank';
elem.href = `https://isrchunt.com/spotify/importisrc?releaseId=${spotifyId}`;
elem.innerText = 'import ISRCs';
curElem = insertAfter(elem, curElem);
elem = document.createTextNode(']');
insertAfter(elem, curElem);
}
function insertAfter(elem, after) {
if (after.parentNode) {
after.parentNode.insertBefore(elem, after.nextSibling);
}
return elem;
}
window.setTimeout(addImportIsrcsLink, 250);