forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mb_SPOT-DUPLICATE-RECORDINGS.user.js
74 lines (74 loc) · 3.81 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
63
64
65
66
67
68
69
70
71
72
73
74
// ==UserScript==
// @name mb. SPOT DUPLICATE RECORDINGS
// @version 2014.11.24.1447
// @description musicbrainz.org: Spot recordings that are linked multiple times to the same work
// @homepage http://userscripts-mirror.org/scripts/show/106145
// @supportURL https://github.com/jesus2099/konami-command/issues
// @namespace https://github.com/jesus2099/konami-command
// @downloadURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_SPOT-DUPLICATE-RECORDINGS.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_SPOT-DUPLICATE-RECORDINGS.user.js
// @author PATATE12 aka. jesus2099/shamo
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2011-07-05
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include http://*musicbrainz.org/work/*
// @include https://*musicbrainz.org/work/*
// @exclude *musicbrainz.org/work/*/*
// @include http://*musicbrainz.org/recording/*
// @include https://*musicbrainz.org/recording/*
// @exclude *musicbrainz.org/recording/*/*
// @run-at document-end
// ==/UserScript==
(function(){"use strict";
var userjs = "jesus2099userjs106145";
for (var tables=document.querySelectorAll("div#content table.details > 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 pn = alllinks[i].parentNode;
if (pn.tagName.toLowerCase() == "span" && pn.className.indexOf("mp") >= 0) { pn = pn.parentNode; }
if (href && href.match(/\/recording\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}/) && pn.tagName.toLowerCase() != "h1" && pn.parentNode.className.indexOf("tabs") < 0 && pn.className.indexOf("pageselector") < 0) {
if (parsedlinks[href]) { /*dupelink*/
if (!parsedlinks[href].dup) {
parsedlinks[href].obj.parentNode.insertBefore(dupetxt(parsedlinks[href].idx), parsedlinks[href].obj);
parsedlinks[href].dup = true;
}
alllinks[i].parentNode.insertBefore(dupetxt(parsedlinks[href].idx), alllinks[i]);
}
else { /*newlink*/
parsedlinks[href] = { obj: alllinks[i], idx: it+"-"+i, dup: false };
}
}
}
}
function dupetxt(txt) {
var cont = document.createElement("span");
cont.appendChild(document.createTextNode("duplicate #"+txt));
cont.setAttribute("class", userjs+txt);
cont.style.setProperty("background-color", "yellow");
cont.style.setProperty("color", "red");
cont.style.setProperty("padding", "0 4px");
cont.addEventListener("mouseover", dupehl, false);
cont.addEventListener("mouseout", dupehl, false);
return cont;
}
function dupehl(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");
}
}
function getParent(obj, tag, cls) {
var cur = obj;
if (cur.parentNode) {
cur = cur.parentNode;
if (cur.tagName.toUpperCase() == tag.toUpperCase() && (!cls || cls && cur.className.match(new RegExp("\\W*"+cls+"\\W*")))) {
return cur;
} else {
return getParent(cur, tag, cls);
}
} else {
return null;
}
}
})();