forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mb_TAGGER-LINKS-NOW.user.js
152 lines (152 loc) · 6.97 KB
/
mb_TAGGER-LINKS-NOW.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// ==UserScript==
// @name mb. TAGGER LINKS NOW
// @version 2014.11.24.1411
// @description musicbrainz.org: Quickly show or update "TAGGER" links with desired port
// @homepage http://userscripts-mirror.org/scripts/show/88065
// @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_TAGGER-LINKS-NOW.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_TAGGER-LINKS-NOW.user.js
// @author PATATE12 aka. jesus2099/shamo
// @licence CC BY-NC-SA 3.0 (https://creativecommons.org/licenses/by-nc-sa/3.0/)
// @since 2010-10-13
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include http*://*musicbrainz.org/area/*/releases*
// @include http*://*musicbrainz.org/artist/*/releases*
// @include http*://*musicbrainz.org/cdtoc/*
// @include http*://*musicbrainz.org/label/*
// @include http*://*musicbrainz.org/recording/*
// @include http*://*musicbrainz.org/release*
// @include http*://*musicbrainz.org/search*type=release*
// @include http://*.mbsandbox.org/area/*/releases*
// @include http://*.mbsandbox.org/artist/*/releases*
// @include http://*.mbsandbox.org/cdtoc/*
// @include http://*.mbsandbox.org/label/*
// @include http://*.mbsandbox.org/recording/*
// @include http://*.mbsandbox.org/release*
// @include http://*.mbsandbox.org/search*type=release*
// @exclude *.org/cdtoc/*/set-durations*
// @exclude *.org/cdtoc/attach?toc=*medium=*
// @exclude *.org/cdtoc/search*type=release_group*
// @exclude *.org/cdtoc/search*type=release-group*
// @exclude *.org/release*/*/*edits*
// @exclude *//*/*mbsandbox.org/*
// @exclude *//*/*musicbrainz.org/*
// @run-at document-end
// ==/UserScript==
(function(){"use strict";
var userjs = "jesus2099userjs88065";
/* ----- - ----- CONFIG */
var automatic = true; /*will background load tport (only when none) so TAGGER buttons do appear on next page browsing without bother triggering it manually*/
var url = "/search?query=artist%3AAJICO+AND+release%3A%22AJICO+SHOW%22+AND+format%3AVHS&type=release&method=advanced&tport=%tagger-port%";
var txt_notaggerlinks = "%tagger-img% (%tagger-port%)"; /* %tagger-port% variable shows the current port and %tagger-img% the tagger image */
var txt_taggerlinksloaded = "%tagger-img% (%tagger-port%)";
var txt_loading = "⌛ loading…";
var bgcolour = "#6f9";
var taggerImgUrl = "/static/images/icons/mblookup-tagger.png"; /*replaces %tagger-img% in txt and chgtxt*/
/* ----- - END OF CONFIG */
var RE_GUID = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
var portStorage = userjs+"_tport";
var isOK = document.cookie.match(new RegExp(userjs+"_ok=1"));
var shouldhavetaggerlink = location.pathname.match(new RegExp("^/(artist/"+RE_GUID+"/releases|label/"+RE_GUID+"|recording/"+RE_GUID+"|release[-_]group/"+RE_GUID+"|release/"+RE_GUID+"(/(relationships|discids|tags|details|((add|edit|remove|reorder)-)?cover-art(/\\d+)?|edit))?)/?$")) && document.querySelector("a[href*='/release/']:not([href*='/release/add'])");
var taggerlink = document.querySelector("a.tagger-icon");
var con, a, menu;
var savedport = localStorage.getItem(portStorage);
var tagger_port = savedport?savedport:"8000";
if (taggerlink) {
document.cookie = userjs+"_ok=1; path=/";
isOK = true;
var tport = taggerlink.getAttribute("href");
if (tport) {
tport = tport.match(/^https?:\/\/[^/]+:([0-9]+)\//);
if (tport) {
tagger_port = tport[1];
if (tagger_port != savedport) {
localStorage.setItem(portStorage, tagger_port);
}
}
}
}
if (menu = document.querySelector("table#mainmenu-table table tr, div#header-menu ul")) {
a = document.createElement("a");
var wtxt = (taggerlink?txt_taggerlinksloaded:txt_notaggerlinks).replace(/%tagger-port%/, tagger_port);
var wfrg = document.createDocumentFragment();
var warr = wtxt.split("%tagger-img%");
if (warr.length > 1) {
wfrg.appendChild(document.createTextNode(warr[0]));
var img = document.createElement("img");
img.setAttribute("src", taggerImgUrl);
img.setAttribute("alt", "tagger");
img.style.setProperty("vertical-align", "bottom");
wfrg.appendChild(img);
wfrg.appendChild(document.createTextNode(warr[1]));
}
else {
wfrg.appendChild(document.createTextNode(wtxt));
}
a.appendChild(wfrg);
a.style.setProperty("cursor", "pointer");
a.setAttribute("title", (!taggerlink?"CTRL+":"")+"CLICK to change port (currently on port "+tagger_port+")");
a.addEventListener("click", function(e) {
if (e.ctrlKey || taggerlink) {
var tport = window.prompt("CHANGE TAGGER PORT\n\nCurrent tagger port is "+tagger_port+".\nEnter new tagger port below:", tagger_port);
if (!tport || (tport == tagger_port && taggerlink)) {
return false;
}
else {
tagger_port = tport;
localStorage.setItem(portStorage, tport);
}
}
loadu(e, false);
}, false);
con = document.createElement("li");
con.appendChild(a);
if (!taggerlink && shouldhavetaggerlink || !isOK) {
con.style.setProperty("background-color", bgcolour);
if (automatic) {
loadu(null, shouldhavetaggerlink);
}
}
menu.insertBefore(con, menu.firstChild);
}
function loadu(e, reload) {
con.style.setProperty("opacity", ".5");
if (reload) {
removeChildren(a);
a.appendChild(document.createTextNode(txt_loading));
}
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if (this.readyState == 4) {
if (this.status < 400 && this.status > 199 && this.responseText.match(/class="tagger-icon"/)) {
document.cookie = userjs+"_ok=1; path=/";
isOK = true;
if (reload) {
top.location.reload(true);
} else {
con.style.setProperty("opacity", "1");
con.style.removeProperty("background-color");
a.setAttribute("title", a.getAttribute("title")+" \n ☞ AUTO-LOAD seems to have WORKED");
}
}
else {
con.style.setProperty("opacity", "1");
con.style.setProperty("background-color", "gold");
if (reload) {
a.setAttribute("title", a.getAttribute("title")+" \n ☞ AUTO-LOAD seems to have FAILED");
} else {
removeChildren(a);
a.appendChild(document.createTextNode("Error "+this.status+" (retry)"));
}
}
}
};
xhr.open("get", url.replace(/%tagger-port%/, tagger_port), true);
xhr.send(null);
}
function removeChildren(p) {
while (p && p.hasChildNodes()) { p.removeChild(p.firstChild); }
}
})();