-
Notifications
You must be signed in to change notification settings - Fork 15
/
mb-display_count_alias.user.js
51 lines (47 loc) · 2.06 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
/* global requests helper */
'use strict';
// ==UserScript==
// @name MusicBrainz: Display alias count
// @namespace mbz-loujine
// @author loujine
// @version 2020.11.16
// @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 work/artist 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/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);
});
})();