-
Notifications
You must be signed in to change notification settings - Fork 27
/
mb_HIDE-DIGITAL-RELEASES.user.js
109 lines (109 loc) · 5.29 KB
/
mb_HIDE-DIGITAL-RELEASES.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
99
100
101
102
103
104
105
106
107
108
109
// ==UserScript==
// @name mb. HIDE DIGITAL RELEASES
// @version 2023.1.19
// @description musicbrainz.org: Release group page: Hide digital releases
// @namespace https://github.com/jesus2099/konami-command
// @supportURL https://github.com/jesus2099/konami-command/labels/mb_HIDE-DIGITAL-RELEASES
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/mb_HIDE-DIGITAL-RELEASES.user.js
// @author jesus2099
// @licence CC-BY-NC-SA-4.0; https://creativecommons.org/licenses/by-nc-sa/4.0/
// @licence GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @since 2021-02-25; https://community.metabrainz.org/t/digital-releases/361875/125?u=jesus2099
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/artist\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}\/releases($|\?)/
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/collection\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}($|\?)/
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/label\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}($|\?)/
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/release-group\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}($|\?)/
// @include /^https?:\/\/(\w+\.)?musicbrainz\.org\/search\?query=.+\btype=release\b/
// @run-at document-ready
// ==/UserScript==
"use strict";
var userjs = {
id: GM_info.script.name.replace(/\.\s/, "_").replace(/\s/g, "-")
};
var MBGlossary = {
"medium-format": {
12: {
"de": "Digitales Medium",
"el-gr": "Ψηφιακό μέσο",
"en": "Digital Media",
"es-es": "Digital",
"et": "audiofailid",
"fi": "Digitaalinen media",
"fr": "Support numérique",
"it": "Supporto digitale",
"ja": "デジタルメディア",
"nl": "digitale media",
}
}
};
var account = document.querySelector("ul.menu li.account");
var lang = document.getElementsByTagName("html")[0].getAttribute("lang");
// find download releases and apply style class
var releaseRows = document.querySelectorAll("table.tbl > tbody > tr:not(.subh)");
markDownloadReleases(releaseRows);
var css = document.createElement("style");
css.setAttribute("type", "text/css");
document.head.appendChild(css);
css = css.sheet;
css.insertRule("body." + userjs.id + " tr." + userjs.id + " { display: none; }", 0);
css.insertRule("body." + userjs.id + " div.jesus2099userjs154481bigbox > a." + userjs.id + " { display: none !important; }", 0); // link to mb_FUNKEY-ILLUSTRATED-RECORDS
css.insertRule("body." + userjs.id + " table.tbl > tbody > tr.even > td { background-color: #FEF; }", 0);
css.insertRule("tr." + userjs.id + " td, tr." + userjs.id + " td * { color: #F66; }", 0);
// hide only if there are physical releases
var hiddenReleases = document.querySelectorAll("tr." + userjs.id);
if (hiddenReleases.length > 0 && releaseRows.length > hiddenReleases.length) {
toggleDLReleases();
// toggle button
var mergeButton = document.querySelector("div.row > span.buttons > button[type='submit']");
var toggleButton = document.createElement("button");
toggleButton.appendChild(document.createTextNode("Show/hide the " + hiddenReleases.length + " DL releases"));
toggleButton.style.setProperty("background-color", "#FEF");
toggleButton.setAttribute("title", userjs.id);
toggleButton.setAttribute("type", "");
toggleButton.addEventListener("click", toggleDLReleases);
mergeButton.parentNode.appendChild(toggleButton);
}
// Hide associated mb_FUNKEY-ILLUSTRATED-RECORDS
setTimeout(function() {
var hiddenReleases = document.querySelectorAll("tr." + userjs.id + " a[href^='/release/']");
for (var r = 0; r < hiddenReleases.length; r++) {
var hiddenReleaseCAA = document.querySelector("div.jesus2099userjs154481bigbox > a[href*='" + hiddenReleases[r].getAttribute("href") + "']");
if (hiddenReleaseCAA) {
hiddenReleaseCAA.classList.add(userjs.id);
}
}
}, 500);
function markDownloadReleases(releaseRows) {
var formatRowIndex = !account || location.pathname.match(/\/search\b/) ? 2 : 3;
for (var r = 0; r < releaseRows.length; r++) {
if (
// don’t match half physical releases
!releaseRows[r].cells[formatRowIndex].textContent.match(/\+/)
// match fully digital releases
&& releaseRows[r].cells[formatRowIndex].textContent.match(new RegExp("([0-9]+×)?" + MBGlossary["medium-format"][12][lang], "iu"))
) {
releaseRows[r].classList.add(userjs.id);
}
}
}
function toggleDLReleases(event) {
// do not submit merge_queue form
if (event) event.preventDefault();
// toggle DL release visibility
document.body.classList.toggle(userjs.id);
// redistribute MBS odd/even style for visible rows
var rows = document.querySelectorAll("table.tbl > tbody > tr");
for (var r = 0, vr = 1; r < rows.length; r++) {
if (rows[r].classList.contains("subh")) {
vr = 1;
continue;
} else if (self.getComputedStyle(rows[r]).getPropertyValue("display") != "none") {
var odd = (vr % 2);
rows[r].classList.remove(odd ? "even" : "odd");
rows[r].classList.add(odd ? "odd" : "even");
vr += 1;
}
}
}