-
Notifications
You must be signed in to change notification settings - Fork 5
/
spotify_atisket_link.user.js
82 lines (69 loc) · 2.62 KB
/
spotify_atisket_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
71
72
73
74
75
76
77
78
79
80
81
82
// ==UserScript==
// @name Add a-tisket import link to Spotify
// @version 2023.7.08
// @description Adds a link to Spotify to import a release into MusicBrainz via a-tisket
// @author atj
// @license MIT; https://opensource.org/licenses/MIT
// @namespace https://github.com/atj/userscripts
// @downloadURL https://raw.github.com/atj/userscripts/master/spotify_atisket_link.user.js
// @updateURL https://raw.github.com/atj/userscripts/master/spotify_atisket_link.user.js
// @match *://open.spotify.com/*
// @require https://code.jquery.com/jquery-3.5.1.slim.min.js
// @grant none
// @run-at document-idle
// ==/UserScript==
// change this to link to a different a-tisket instance
// const ATISKET = `https://etc.marlonob.info/atisket`;
const ATISKET = `https://atisket.pulsewidth.org.uk`;
// change this to your preferred country codes
const COUNTRIES = encodeURIComponent(`GB,US,DE`);
// prevent JQuery conflicts, see http://wiki.greasespot.net/@grant
this.$ = this.jQuery = jQuery.noConflict(true);
function addAtisketLink(path) {
let spotifyReleaseId = getReleaseIdFromPath(path);
if (spotifyReleaseId === null) {
return;
}
// remove any old instances of the button in the DOM
$('#atisket').remove();
let atisketLink = `${ATISKET}/?preferred_countries=${COUNTRIES}&spf_id=${spotifyReleaseId}&preferred_vendor=spf`;
let moreButton = $('button[aria-label*="More"]').first();
let atisketButton = $(
`<button type="button" id="atisket" class="${moreButton.attr(
'class'
)}" style="padding:6px;border:1px solid;border-radius:5px;">
<a href="${atisketLink}" target="_blank">
→ a-tisket
</a>
</button>`
).hide();
moreButton.before(atisketButton);
atisketButton.show();
}
function getReleaseIdFromPath(path) {
let matchData = path.match(/^\/album\/([0-9a-z]+)[^/]*$/i);
if (matchData !== null) {
return matchData[1];
}
return null;
}
// Intercept pushState and popstate so that the script works with the Spotify SPA
(function () {
window.history.pushState = function () {
let path = arguments[2];
window.setTimeout(function () {
addAtisketLink(path);
}, 500);
};
window.addEventListener('popstate', function () {
window.setTimeout(function () {
addAtisketLink(window.location.pathname);
}, 500);
});
})();
$(document).ready(function () {
// allow 1 second for the Spotify SPA to initialize
window.setTimeout(function () {
addAtisketLink(window.location.pathname);
}, 1000);
});