-
Notifications
You must be signed in to change notification settings - Fork 16
/
mb-display_count_alias.user.js
63 lines (59 loc) · 2.72 KB
/
mb-display_count_alias.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
/* global requests helper */
'use strict';
// ==UserScript==
// @name MusicBrainz: Display alias count
// @namespace mbz-loujine
// @author loujine
// @version 2024.11.25
// @downloadURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-display_count_alias.user.js
// @updateURL https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mb-display_count_alias.user.js
// @supportURL https://github.com/loujine/musicbrainz-scripts
// @icon https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/icon.png
// @description musicbrainz.org: Display alias count on entities pages
// @compatible firefox+tampermonkey
// @license MIT
// @require https://raw.githubusercontent.com/loujine/musicbrainz-scripts/master/mbz-loujine-common.js
// @include http*://*musicbrainz.org/work/*
// @exclude http*://*musicbrainz.org/work/add*
// @exclude http*://*musicbrainz.org/work/create*
// @exclude http*://*musicbrainz.org/work/*/edits
// @include http*://*musicbrainz.org/release/*
// @exclude http*://*musicbrainz.org/release/add*
// @exclude http*://*musicbrainz.org/release/create*
// @exclude http*://*musicbrainz.org/release/*/edits
// @include http*://*musicbrainz.org/release-group/*
// @exclude http*://*musicbrainz.org/release-group/add*
// @exclude http*://*musicbrainz.org/release-group/create*
// @exclude http*://*musicbrainz.org/release-group/*/edits
// @include http*://*musicbrainz.org/event/*
// @exclude http*://*musicbrainz.org/event/add*
// @exclude http*://*musicbrainz.org/event/create*
// @exclude http*://*musicbrainz.org/event/*/edits
// @include http*://*musicbrainz.org/artist/*
// @exclude http*://*musicbrainz.org/artist/add*
// @exclude http*://*musicbrainz.org/artist/create*
// @exclude http*://*musicbrainz.org/artist/*/edits
// @grant none
// @run-at document-end
// ==/UserScript==
// adapted from jesus2099 mb. INLINE STUFF
function parseCount(resp, tab) {
const cnt = resp.aliases.length;
if (cnt > 0) {
tab.style.setProperty('background-color', '#6f9');
}
tab.textContent += ' (' + cnt + ')';
let locales = resp.aliases.map(alias => alias.locale).filter(locale => locale !== null);
if (locales.length > 0) {
locales = Array.from(new Set(locales));
tab.textContent += ' ' + locales.sort().join(',');
}
}
(function showCountAliases() {
const tab = document.querySelector("a[href$='/aliases']");
const entityType = document.URL.split('/')[3];
const url = helper.wsUrl(entityType, ['aliases']);
requests.GET(url, function (resp) {
parseCount(JSON.parse(resp), tab);
});
})();