-
Notifications
You must be signed in to change notification settings - Fork 1
/
Musicbrainz_list destroyer.user.js
98 lines (91 loc) · 4.64 KB
/
Musicbrainz_list destroyer.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// ==UserScript==
// @name Musicbrainz: Ultimate list destroyer
// @version 2021.2.25
// @description Hide/show very long work and/or country lists
// @namespace https://github.com/otringal/MB-userscripts
// @grant none
// @match *://*.musicbrainz.org/artist/*/works*
// @match *://*.musicbrainz.org/release/*
// @match *://*.musicbrainz.org/release-group/*
// @match *://*.musicbrainz.org/artist/*/releases*
// @match *://*.musicbrainz.org/label/*
// @exclude *musicbrainz.org/release/*/edit
// @exclude *musicbrainz.org/release/*/edit-relationships
// @run-at document-end
// ==/UserScript==
//
/*----/ USER SETTINGS /----*/
var removeWorksArtist = true; //set to "true" to enable "show/hide works", "false" to disable.
var removeCountries = true; //set to "true" to enable "show/hide countries", "false" to disable.
var alwaysShowWorks = 5; //the minimum number of work ACs that always are shown on the artist/works page. Must be higher than 0.
var alwaysShowCountries = 5; //same as above but for countries
//var removeWorksRelease = false; //change this to "false" to display translated works rels, etc, on the release page
/*----/ USER SETTINGS /----*/
var showcss = document.createElement("style");
showcss.type = "text/css";
showcss.innerHTML = ".hidelist {display:none;} .showworks span {white-space: nowrap; margin: 0.4em 0em; padding: 0.1em 0.3em; font-size: smaller; text-transform: uppercase; font-weight: 600; background-color: rgba(250, 200, 35, 0.5); cursor: pointer;}";
document.body.appendChild(showcss);
var url = window.location.href;
var listpath = "";
var listpath2 = "";
var hiddenlength = 0;
if (removeWorksArtist && url.match(/works/) && alwaysShowWorks !=0) {
listpath = $(".tbl tr td:nth-last-child(6) ul");
$(listpath).each(function(){
if ($(this).find("li").length > alwaysShowWorks){
hiddenlength = $(this).find("li").length - alwaysShowWorks;
$(this).find("li:gt("+(alwaysShowWorks-1)+")").addClass("hidelist").hide().end().prepend("<li class='showworks allworks'><span>show all (+"+hiddenlength+")</span></li>");
}
});
showhide();
}
else if (removeCountries && alwaysShowCountries !=0 && url.match(/(release\/)/)) {
listpath = $(".release-events").next();
$(listpath).each(function(){
if ($(this).find("li").length > alwaysShowCountries){
hiddenlength = $(this).find("li").length - alwaysShowCountries;
$(this).find("li:gt("+(alwaysShowCountries-1)+")").addClass("hidelist").hide().end().prepend("<li class='showworks allworks'><span>show all (+"+hiddenlength+")</span></li>");
}
});
showhide();
}
else if (removeCountries && alwaysShowCountries !=0 && (url.match(/release-group/) || url.match(/(artist).+(releases)/) || url.match(/label/) )) {
if (url.match(/release-group/)){
listpath = $(".tbl tr td:nth-last-child(4) ul");
listpath2 = $(".tbl tr td:nth-last-child(5) ul");
}
else if (url.match(/(artist).+(releases)/)){
listpath = $(".tbl tr td:nth-last-child(4) ul");
listpath2 = $(".tbl tr td:nth-last-child(5) ul");
}
else if (url.match(/label/)){
listpath = $(".tbl tr td:nth-last-child(3) ul");
listpath2 = $(".tbl tr td:nth-last-child(4) ul");
}
$(listpath).each(function(){
if ($(this).find("li").length > alwaysShowCountries){
hiddenlength = $(this).find("li").length - alwaysShowCountries;
$(this).find("li:gt("+(alwaysShowCountries-1)+")").addClass("hidelist").hide().end().prepend("<li class='showworks allworks'><span>show all (+"+hiddenlength+")</span></li>");
}
});
$(listpath2).each(function(){
if ($(this).find("li").length > alwaysShowCountries){
hiddenlength = $(this).find("li").length - alwaysShowCountries;
//no "show all" button, since most examples i've seen all have the same date.
$(this).find("li:gt("+(alwaysShowCountries-1)+")").hide().end().prepend("<li><span style='margin: 0.4em 0em; padding: 0.1em 0.3em;'></span></li>");
}
});
showhide();
}
function showhide(){
$(".showworks").on("click", function(){
$(this).parent().children('.hidelist').toggle();
if($(this).hasClass("allworks")){
$(this).addClass("lessworks").removeClass("allworks").children(0).html("show less");
}
else if($(this).hasClass("lessworks")){
hiddenlength = $(this).parent().children('.hidelist').length+1;
$(this).addClass("allworks").removeClass("lessworks").children(0).html("show all (+"+(hiddenlength-1)+")");
}
});
}