-
Notifications
You must be signed in to change notification settings - Fork 26
/
mb_SPOT-DUPLICATE-RECORDINGS.user.js
62 lines (62 loc) · 3.22 KB
/
mb_SPOT-DUPLICATE-RECORDINGS.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
// ==UserScript==
// @name mb. SPOT DUPLICATE RECORDINGS
// @version 2022.9.26.1
// @description musicbrainz.org: Spot recordings that are linked multiple times to the same work
// @namespace https://github.com/jesus2099/konami-command
// @supportURL https://github.com/jesus2099/konami-command/labels/mb_SPOT-DUPLICATE-RECORDINGS
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/mb_SPOT-DUPLICATE-RECORDINGS.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 2011-07-05; https://web.archive.org/web/20131103163405/userscripts.org/scripts/show/106145 / https://web.archive.org/web/20141011084009/userscripts-mirror.org/scripts/show/106145
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @require https://github.com/jesus2099/konami-command/raw/de88f870c0e6c633e02f32695e32c4f50329fc3e/lib/SUPER.js?version=2022.3.24.224
// @grant none
// @match *://*.musicbrainz.org/recording/*
// @match *://*.musicbrainz.org/work/*
// @exclude *.org/recording/*/*
// @exclude *.org/work/*/*
// @run-at document-end
// ==/UserScript==
"use strict";
var userjs = "jesus2099userjs106145";
var count = 1;
for (var tables = document.querySelectorAll("div#content table > tbody"), it = 0; it < tables.length; it++) {
for (var alllinks = tables[it].getElementsByTagName("a"), parsedlinks = [], i = 0; i < alllinks.length; i++) {
var href = alllinks[i].getAttribute("href");
var parent = alllinks[i].parentNode;
if (parent.tagName == "SPAN" && parent.classList.contains("mp")) {
parent = parent.parentNode;
}
if (
href
&& href.match(/\/recording|work\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/)
&& parent.tagName != "H1"
&& !parent.parentNode.classList.contains("tabs")
&& !parent.classList.contains("pageselector")
) {
if (parsedlinks[href]) { /* duplicate link */
if (!parsedlinks[href].hasDupe) {
parsedlinks[href].node.parentNode.insertBefore(dupetxt(parsedlinks[href].index), parsedlinks[href].node);
parsedlinks[href].hasDupe = true;
}
alllinks[i].parentNode.insertBefore(dupetxt(parsedlinks[href].index), alllinks[i]);
} else { /* new link */
parsedlinks[href] = {node: alllinks[i], index: "#" + count++ + "/" + alllinks.length, hasDupe: false};
}
}
}
}
function dupetxt(txt) {
return createTag("span", {
a: {class: userjs + txt.replace(/[#/]/g, "-")},
s: {backgroundColor: "yellow", color: "red", padding: "0 4px"},
e: {mouseover: dupeHighlight, mouseout: dupeHighlight}
}, "duplicate " + txt);
}
function dupeHighlight(e) {
for (var dupes = getParent(this, "tbody").getElementsByClassName(this.className), d = 0; d < dupes.length; d++) {
dupes[d].style.setProperty("background-color", e.type == "mouseover" ? "red" : "yellow");
dupes[d].style.setProperty("color", e.type == "mouseover" ? "yellow" : "red");
}
}