Repository navigation
Expand file tree
/
Copy pathlistenbrainz-search-missing-data.user.js
More file actions
172 lines (138 loc) · 5.42 KB
/
Copy pathlistenbrainz-search-missing-data.user.js
File metadata and controls
172 lines (138 loc) · 5.42 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// ==UserScript==
// @name Search Missing Data
// @namespace http://tampermonkey.net/
// @version 2025-01-12.1
// @description Add linksto listenbrainz's missing data page
// @author You
// @match https://listenbrainz.org/settings/link-listens/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=listenbrainz.org
// @namespace https://github.com/RustyNova016/MusicBrainz-UserScripts/
// @downloadURL https://github.com/RustyNova016/MusicBrainz-UserScripts/raw/main/listenbrainz-search-missing-data.user.js
// @updateURL https://github.com/RustyNova016/MusicBrainz-UserScripts/raw/main/listenbrainz-search-missing-data.user.js
// @homepageURL https://github.com/RustyNova016/MusicBrainz-UserScripts/
// @supportURL https://github.com/RustyNova016/MusicBrainz-UserScripts/issues
// @grant none
// ==/UserScript==
'use strict';
let global_albums = new Map();
let running_update = false;
let schedule_update = false;
let globalPromises = []
let form, entity, formString;
let previousAlbumCount = 0;
// Spotify integration variables
let card_root_class_name = "bEHVkp"; // Change every CSS refresh.
new MutationObserver(function(mutations) {
// Prevent running if there's already an update in progress
if (running_update) {
schedule_update = true
return
}
running_update = true
on_mutation();
// If an update got scheduled, then rerun
if (schedule_update) {
on_mutation();
}
// Remove running lock
running_update = false
}).observe(document, {subtree: true, childList: true});
function on_mutation() {
globalPromises.push(get_all_cards())
Promise.all(globalPromises)
}
async function get_all_cards() {
let all_cards = document.getElementsByClassName("card listen-card");
if (all_cards.length === 0) {
console.log("[MB Status] No cards found. If you expect some, the CSS might have changed.");
return
}
console.log("[MB Status] card count: " + all_cards.length)
if (all_cards.length === 0) {return}
console.log(all_cards);
for (const card of all_cards) {
await handle_card(card);
}
}
function get_title_from_root(card_root) {
return card_root.childNodes[0].childNodes[0].childNodes[0].childNodes[0].innerHTML
}
function get_artist_from_root(card_root) {
return card_root.childNodes[0].childNodes[0].childNodes[1].innerHTML
}
function get_anchor(card_root){
return card_root.childNodes[0].childNodes[1]
}
function is_card_anchored(card_root) {
return card_root.childNodes[0].childNodes[1].childNodes[0].classList[0] === "search-link-container"
}
function is_data_loaded(card_root) {
return card_root.childNodes[0].childNodes[1] !== undefined && card_root.childNodes[0].childNodes[0].childNodes[1] !== undefined
}
async function handle_card(card_root) {
if (!is_data_loaded(card_root) || is_card_anchored(card_root)) {
// No data! Let's bail
return;
}
// Let's get the title.
let title = get_title_from_root(card_root);
console.log(`Title: ${title}`);
let artist = get_artist_from_root(card_root);
console.log(`artist: ${artist}`);
let anchor = get_anchor(card_root);
let container = document.createElement("div");
container.setAttribute("class", "search-link-container");
anchor.prepend(container);
add_icon(container, `https://musicbrainz.org/taglookup/index?tag-lookup.artist=${artist}&tag-lookup.track=${title}`, "musicbrainz");
add_icon(container, `https://listenbrainz.org/search/?search_term=${title} ${artist}&search_type=track`, "listenbrainz");
add_icon(container, `https://open.spotify.com/search/${title} ${artist}`, "spot");
add_icon(container, `https://www.deezer.com/search/${title} ${artist}`, "deez");
add_icon(container, `https://music.apple.com/gb/search?term=${title} ${artist}`, "apple");
}
function add_icon(container, link, pref) {
let icon = document.createElement("a");
icon.href = link
icon.setAttribute("class", `search-link ${pref}-search-icon`);
icon.target="_blank";
container.append(icon);
}
// Insert CSS into the Head
function main() {
let head = document.getElementsByTagName('head')[0];
if (head) {
let style = document.createElement('style');
style.setAttribute('type', 'text/css');
style.textContent = `
.search-link-container{
display: flex;
padding: 0px 10px
}
.search-link {
margin: 0px 5px;
background: 0 0 no-repeat;
background-image: none;
background-size: auto;
background-size: 32px;
width: 32px;
height: 32px;
}
.spot-search-icon {
background-image: url("https://open.spotifycdn.com/cdn/images/favicon32.b64ecc03.png") !important;
}
.deez-search-icon {
background-image: url("https://e-cdn-files.dzcdn.net/cache/images/common/favicon/favicon-32x32.ed120c279a693bed3a44.png") !important;
}
.apple-search-icon {
background-image: url("https://www.google.com/s2/favicons?sz=64&domain=music.apple.com") !important;
}
.listenbrainz-search-icon {
background-image: url("https://www.google.com/s2/favicons?sz=64&domain=listenbrainz.org") !important;
}
.musicbrainz-search-icon {
background-image: url("https://www.google.com/s2/favicons?sz=64&domain=musicbrainz.org") !important;
}
`;
head.appendChild(style);
}
}
main();