forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mb_ALL-LINKS.user.js
412 lines (412 loc) · 18.8 KB
/
mb_ALL-LINKS.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
// ==UserScript==
// @name mb. ALL LINKS
// @version 2014.11.24.1504
// @description Hidden links include fanpage, social network, etc. (NO duplicates) Generated links (configurable) includes plain web search, auto last.fm, Discogs and LyricWiki searches, etc. Dates on URLs
// @homepage http://userscripts-mirror.org/scripts/show/108889
// @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_ALL-LINKS.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_ALL-LINKS.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-08-02
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include http*://*musicbrainz.org/artist/*
// @exclude http*://*musicbrainz.org/artist/*/edit
// @exclude http*://*musicbrainz.org/artist/*/split
// @include http*://*musicbrainz.org/release/*
// @run-at document-end
// ==/UserScript==
(function(){
/* hint for Opera 12 users allow opera:config#UserPrefs|Allowscripttolowerwindow and opera:config#UserPrefs|Allowscripttoraisewindow */
/*------------settings*/
var nonLatinName = /[\u0384-\u1cf2\u1f00-\uffff]/;/*U+2FA1D is currently out of js range*/
var autolinksOpacity = ".5"; /*can be dimmer than existing links*/
/*
%artist-id% (MBID)
%arist-name%
%artist-sort-name%
%artist-family-name-first%
*/
var artist_autolinks = {
"Web pages": "//duckduckgo.com/?q=%artist-name%",
"Web pages (strict)": "//duckduckgo.com/?q=%2B%22%artist-name%%22",
/*"Fun stuff": null, // you can insert headers this way (IMPORTANT: don't use space as first character)*/
"Images": "//duckduckgo.com/?q=%artist-name%+!i",
"Videos": "//duckduckgo.com/?q=%artist-name%+!v",
"Credits": null,
"SACEM (Interprète)": {"accept-charset":"ISO-8859-1", "action":"http://www.sacem.fr/oeuvres/oeuvre/rechercheOeuvre.do", "parameters":{"ftin":"true","tiers":"%artist-name%"}},
"SACEM (Auteur-Compositeur-Éditeur)": {"accept-charset":"ISO-8859-1", "action":"http://www.sacem.fr/oeuvres/oeuvre/rechercheOeuvre.do", "parameters":{"ftad":"true","tiers":"%artist-name%"}},
"JASRAC(アーティスト)": {"title":"requires JASRAC direct link", "method":"post", "accept-charset":"Shift_JIS", "enctype":"multipart/form-data", "action":"http://www2.jasrac.or.jp/eJwid/main.jsp?trxID=A00401-3", "parameters":{"IN_ARTIST_NAME_OPTION1":"0","IN_ARTIST_NAME1":"%artist-name%","IN_DEFAULT_WORKS_KOUHO_MAX":"100","IN_DEFAULT_WORKS_KOUHO_SEQ":"1","IN_DEFAULT_SEARCH_WORKS_NAIGAI":"0","RESULT_CURRENT_PAGE":"1"}},
"JASRAC(著作者)": {"title":"requires JASRAC direct link", "method":"post", "accept-charset":"Shift_JIS", "enctype":"multipart/form-data", "action":"http://www2.jasrac.or.jp/eJwid/main.jsp?trxID=A00401-3", "parameters":{"IN_KEN_NAME_OPTION1":"0","IN_KEN_NAME1":"%artist-family-name-first%","IN_KEN_NAME_JOB1":"0","IN_DEFAULT_WORKS_KOUHO_MAX":"100","IN_DEFAULT_WORKS_KOUHO_SEQ":"1","IN_DEFAULT_SEARCH_WORKS_NAIGAI":"0","RESULT_CURRENT_PAGE":"1"}},
"音楽の森(アーティスト)": "//www.minc.gr.jp/db/ArtNmSrch.aspx?ArtNm=%artist-name%",
"音楽の森(著作者)": "//www.minc.gr.jp/db/KenriSrch.aspx?KENRISYANM=%artist-family-name-first%",
"Lyrics": null,
"decoda": "http://decoda.com/search?q=%artist-name%",
"LyricWiki": "//lyrics.wikia.com/%artist-name%",
"うたまっぷ(アーティスト)": {"accept-charset":"euc-jp", "action":"http://www.utamap.com/searchkasi.php", "parameters":{"searchname":"artist","word":"%artist-name%"}},
"うたまっぷ(作詞者)": {"accept-charset":"euc-jp", "action":"http://www.utamap.com/searchkasi.php", "parameters":{"searchname":"sakusi","word":"%artist-name%"}},
"うたまっぷ(作曲者)": {"accept-charset":"euc-jp", "action":"http://www.utamap.com/searchkasi.php", "parameters":{"searchname":"sakyoku","word":"%artist-name%"}},
"J-Lyric(歌手)": "http://j-lyric.net/index.php?ka=%artist-name%",
"歌詞タイム": "//duckduckgo.com/?q=site%3Akasi-time.com+subcat+intitle:%artist-name%",
"Japanese stuff": null,
"VGMdb": "http://vgmdb.net/search?q=%artist-name%",
"ja.Wikipedia": "//ja.wikipedia.org/w/index.php?search=%artist-name%",
"CDJournal search": {"accept-charset":"euc-jp", "action":"//cdjournal.com/search/do/", "parameters":{"k":"%artist-name%","target":"a"}},
"Joshinweb search": {"accept-charset":"Shift_JIS", "action":"//joshinweb.jp/cdshops/Dps", "parameters":{"KEY":"ARTIST","FM":"0","KEYWORD":"%artist-name%"}},
"Yunisan": "//duckduckgo.com/?q=site:www22.big.or.jp+%22%2F%7Eyunisan%2Fvi%2F%22+%artist-name%",
"VKDB": "//duckduckgo.com/?q=site:vkdb.jp+%artist-name%",
"Vietnamese stuff": null,
"vi.Wikipedia": "//vi.wikipedia.org/w/index.php?search=%artist-name%",
"nhạc số": "http://nhacso.net/tim-nghe-si/trang-1/%artist-name%.html",
"Korean stuff": null,
"maniadb": "http://www.maniadb.com/search.asp?sr=PO&q=%artist-name%",
"Other databases": null,
"AllMusic": "http://www.allmusic.com/search/artist/%artist-name%",
"Discogs": "http://www.discogs.com/search?q=%artist-name%&type=artist",
"ISNI": "http://isni.oclc.nl/xslt/CMD?ACT=SRCHA&IKT=8006&TRM=%artist-name%",
"Rate Your Music": "http://rateyourmusic.com/search?searchtype=a&searchterm=%artist-name%",
"Second hand songs": "http://www.secondhandsongs.com/cgi/topsearch.php?search_object=artist&search_text=%artist-name%",
"WhoSampled": "//www.whosampled.com/search/artists/?h=1&q=%artist-name%",
"Other stuff": null,
"en.Wikipedia": "//en.wikipedia.org/w/index.php?search=%artist-name%",
"*.Wikipedia": "//duckduckgo.com/?q=site:wikipedia.org+%22%artist-name%%22",
"Lastfm (mbid)": "http://last.fm/mbid/%artist-id%",
"Lastfm (name)": "http://last.fm/music/%artist-name%",
"BBC Music": "http://www.bbc.co.uk/music/artists/%artist-id%",
};
var favicons = {
"allmusic.com": "http://allmusic.com/img/favicon.ico",
"ameblo.jp": "http://ameblo.jp/favicon.ico",
"bbc.co.uk": "http://www.bbc.co.uk/favicon.ico",
"discogs.com": "http://musicbrainz.org/static/images/favicons/discogs-16.png",
"exblog.jp": "http://exblog.jp/favicon.ico",
"joshinweb.jp": "http://joshinweb.jp/favicon.ico",
"last.fm": "http://musicbrainz.org/static/images/favicons/lastfm-16.png",
"lastfm.": "http://musicbrainz.org/static/images/favicons/lastfm-16.png",
"livedoor.jp": "http://blog.livedoor.jp/favicon.ico",
"lyrics.wikia.com": "http://lyrics.wikia.com/favicon.ico",
"metal-archives.com": "http://www.metal-archives.com/favicon.ico",
"musicbrainz.org": "http://musicbrainz.org/favicon.ico",
"rakuten.co.jp": "http://plaza.rakuten.co.jp/favicon.ico",
"secondhandsongs.com": "http://www.secondhandsongs.com/art/icons/shs.png",
"soundcloud.com": "http://musicbrainz.org/static/images/favicons/soundcloud-16.png",
"vgmdb.net": "http://vgmdb.net/favicon.ico",
"vkdb.jp": "http://www.vkdb.jp/favicon.ico",
"wikipedia.org": "http://en.wikipedia.org/favicon.ico",
"yahoo.": "http://blogs.yahoo.co.jp/favicon.ico",
};
var guessOtherFavicons = true;
var hideAffiliates = true;
var hideDupeRelationshipsLink = true; /*"View all relationships" link = "Relationships" tab*/
/*------------end of settings (don't edit below) */
var userjs = "j2ujs108889";
var sidebar = document.getElementById("sidebar");
var arelsws = "/ws/2/artist/%artist-id%?inc=url-rels";
var existingLinks, extlinks;
function do108889() {
if (sidebar) {
var rgextrels = sidebar.querySelector("ul.external_links_2 > li");
if (rgextrels && (rgextrels = rgextrels.parentNode) && rgextrels.previousSibling.tagName == "UL") {
rgextrels.parentNode.insertBefore(document.createElement("h2"), rgextrels).appendChild(document.createTextNode("Release group external links"));
}
var artistid = self.location.href.match(/musicbrainz.org\/artist\/([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}).*/i);
var artistname = document.querySelector("div#content > div.artistheader > h1 a, div#content > div.artistheader > h1 span[href]"); /* for compatibilly with https://gist.github.com/jesus2099/4111760 */
var artistsortname, artistsortnameSwapped = "";
if (artistid && artistname) {
artistid = artistid[1];
arelsws = arelsws.replace(/%artist-id%/, artistid);
artistsortname = artistname.getAttribute("title");
var tmpsn = artistsortname.split(",");
for (var isn=tmpsn.length-1; isn>=0; isn--) {
artistsortnameSwapped += tmpsn[isn].trim();
if (isn != 0) {artistsortnameSwapped += " "; }
}
artistname = artistname.textContent.trim();
extlinks = sidebar.getElementsByClassName("external_links");
if (extlinks && extlinks.length>0) {
extlinks = extlinks[0];
loading(true);
/*attached missing links*/
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(e) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
loading(false);
var res = xhr.responseXML;
var urls = res.evaluate("//mb:relation-list[@target-type='url']/mb:relation", res, nsr, XPathResult.ANY_TYPE, null);
var haslinks = false;
while (url = urls.iterateNext()) {
var target = res.evaluate("./mb:target", url, nsr, XPathResult.ANY_TYPE, null);
var turl = target.iterateNext();
var begin, end;
if (begin = res.evaluate("./mb:begin", url, nsr, XPathResult.ANY_TYPE, null).iterateNext()) { begin = begin.textContent; }
if (end = res.evaluate("./mb:end", url, nsr, XPathResult.ANY_TYPE, null).iterateNext()) { end = end.textContent; }
else if (res.evaluate("./mb:ended", url, nsr, XPathResult.ANY_TYPE, null).iterateNext()) { end = "????"; }
if (turl) {
if (addExternalLink(url.getAttribute("type"), turl.textContent, begin, end)) {
if (!haslinks) {
haslinks = true;
addExternalLink(" Hidden links");
}
}
}
}
/*artist_autolinks*/
extlinksOpacity = autolinksOpacity;
haslinks = false;
for (var link in artist_autolinks) if (artist_autolinks.hasOwnProperty(link)) {
var target = artist_autolinks[link];
var sntarget = null;
if (target) {
if (typeof target == "string") {
target = target.replace(/%artist-id%/, artistid);
if (target.match(/%artist-name%/) && artistname != artistsortnameSwapped && artistname.match(nonLatinName)) {
sntarget = target.replace(/%artist-name%/, encodeURIComponent(artistsortnameSwapped));
}
target = target.replace(/%artist-name%/, encodeURIComponent(artistname));
target = target.replace(/%artist-family-name-first%/, encodeURIComponent(artistname.match(nonLatinName)?artistname:artistsortname));
}
else {
var aname = target["accept-charset"];
aname = aname&&aname.match(/iso-8859/i)&&artistname!=artistsortnameSwapped&&artistname.match(nonLatinName)?artistsortnameSwapped:artistname;
for (var param in target.parameters) if (target.parameters.hasOwnProperty(param)) {
target.parameters[param] = target.parameters[param].replace(/%artist-id%/, artistid).replace(/%artist-name%/, aname).replace(/%artist-family-name-first%/, artistname.match(nonLatinName)?artistname:artistsortname);
}
}
}
if (addExternalLink(link, target, null, null, sntarget)) {
if (!haslinks) {
haslinks = true;
addExternalLink(" Generated links");
}
}
}
} else if (xhr.status >= 400) {
var txt = xhr.responseText.match(/<error><text>(.+)<\/text><text>/);
txt = txt?txt[1]:"";
error(xhr.status, txt);
}
}
};
xhr.open("GET", arelsws, true);
xhr.send(null);
}
}/*artist*/
if (hideAffiliates) {
var affs = document.getElementById("sidebar-affiliates");
if (affs) {
affs.parentNode.removeChild(affs);
}
}
}
}
var favicontry = [];
var extlinksOpacity = "1";
function addExternalLink(text, target, begin, end, sntarget) {
var newLink = true;
var lis = extlinks.getElementsByTagName("li");
if (!existingLinks) {
existingLinks = [];
for (ilis=0; ilis<lis.length; ilis++) {
var lisas = lis[ilis].getElementsByTagName("a");
if (lisas.length>0) { existingLinks.push(lisas[0].getAttribute("href").trim().replace(/^https?:/,"")); }
}
}
if (target) {
var li;
if (typeof target != "string") {
var form = document.createElement("form");
form.setAttribute("action", target.action);
if (target.title) {
form.style.setProperty("cursor", "help");
}
var info = "\n"+target.action;
for (var attr in target) if (target.hasOwnProperty(attr)) {
if (attr == "parameters") {
for (var param in target.parameters) if (target.parameters.hasOwnProperty(param)) {
info += "\n"+param+"="+target.parameters[param];
var input = document.createElement("input");
input.setAttribute("type", "hidden");
input.setAttribute("name", param);
input.setAttribute("value", target.parameters[param]);
form.appendChild(input);
}
} else {
if (attr.match(/accept-charset|enctype|method/)) { info = target[attr]+" "+info; }
form.setAttribute(attr, target[attr]);
}
}
var a = createA(text);
a.setAttribute("title", info);
a.addEventListener("mousedown", function (e) {
e.preventDefault();
if (e.button == 1) {
this.parentNode.setAttribute("target", weirdobg());
this.parentNode.submit();
}
}, false);
a.addEventListener("click", function (e) {
if (e.button == 0) {
/*lame browsers;)*/
if (typeof opera == "undefined") {
if (e.shiftKey) {
this.parentNode.setAttribute("target", "_blank");
} else if (e.ctrlKey) {
this.parentNode.setAttribute("target", weirdobg());
}
}
this.parentNode.submit();
}
}, false);
form.appendChild(a);
form.appendChild(document.createTextNode("*"));
li = document.createElement("li");
li.appendChild(form);
}
else {
var exi = existingLinks.indexOf(target.trim().replace(/^https?:/,""));
if (exi == -1) {
existingLinks.push(target.trim().replace(/^https?:/,""));
li = document.createElement("li");
li.className = text;
li.appendChild(createA(text, target));
}
else {
newLink = false;
li = lis[exi];
}
if (sntarget && newLink) {
li.appendChild(document.createTextNode(" ("));
li.appendChild(createA("lat.", sntarget, "search with latin name"));
li.appendChild(document.createTextNode(")"));
}
if (begin || end) {
var dates = " (";
if (begin) { dates += begin; }
if (begin != end) { dates += "—"; }
if (end && begin != end) { dates += end; }
dates += ")";
li.appendChild(document.createElement("span").appendChild(document.createTextNode(dates)).parentNode).style.whiteSpace = "nowrap";
}
}
var favurltest = (typeof target == "string")?target:target.action;
var favurlfound = false;
for (var part in favicons) if (favicons.hasOwnProperty(part)) {
if (favurltest.indexOf(part) != -1) {
favurlfound = favicons[part];
break;
}
}
if (guessOtherFavicons && !favurlfound) {
favurlfound = favurltest.substr(0, favurltest.indexOf("/", 7))+"/favicon.ico";
}
var ifit = favicontry.length;
favicontry[ifit] = new Image();
/*favicontry.addEventListener("error", function (e) {
}, false);*/
favicontry[ifit].addEventListener("load", function (e) {
clearTimeout(this.to);
if (this.width == 16) {
this.li.style.backgroundImage = "url("+this.src+")";
}
}, false);
favicontry[ifit].li = li;
favicontry[ifit].src = favurlfound;
favicontry[ifit].to = setTimeout(function(){ favicontry[ifit].src = "/"; }, 5000);
}
else {
var li = document.createElement("li");
li.style.background = "transparent";
li.style.marginTop = ".5em";
li.appendChild(document.createTextNode(text));
if (text.indexOf(" ") == 0) {
li.style.fontWeight = "bold";
extlinks.insertBefore(li, extlinks.lastChild);
}
else {
extlinks.appendChild(li);
}
}
if (newLink) {
li.style.opacity = extlinksOpacity;
if (target) { extlinks.appendChild(li); }
}
return newLink;
}
function weirdobg() {
var weirdo = userjs+(new Date().getTime());
try { self.open("", weirdo).blur(); } catch(e) {}
self.focus();
return weirdo;
}
function error(code, text) {
var ldng = document.getElementById("jesus2099loading108889");
if (ldng) {
ldng.setAttribute("id", "jesus2099error108889");
ldng.style.background = "pink";
ldng.replaceChild(document.createTextNode("Error "+code), ldng.firstChild);
ldng.appendChild(createA("*", arelsws));
ldng.appendChild(document.createTextNode(" in "));
ldng.appendChild(createA("all links", "http://userscripts.org/scripts/show/108889"));
ldng.appendChild(document.createTextNode(" ("));
var retrybtn = createA("retry");
retrybtn.addEventListener("click", function (e) {
var err = document.getElementById("jesus2099error108889");
if (err) { err.parentNode.removeChild(err); }
do108889();
}, false);
ldng.appendChild(retrybtn);
ldng.appendChild(document.createTextNode(")"));
ldng.appendChild(document.createElement("br"));
ldng.appendChild(document.createElement("i").appendChild(document.createTextNode(text)));
}
else {
loading(true);
error(code, text);
}
}
function loading(on) {
var ldng = document.getElementById("jesus2099loading108889");
if (on) {
if (!ldng) {
var li = document.createElement("li");
li.setAttribute("id", "jesus2099loading108889");
li.style.background = "#ff6";
li.appendChild(document.createTextNode("loading…"));
var lis = extlinks.getElementsByTagName("li");
if (hideDupeRelationshipsLink && lis[lis.length-1].textContent.match(/View all relationships/)) {
extlinks.removeChild(lis[lis.length-1]);
}
extlinks.appendChild(li);
}
}
else {
if (ldng) {
ldng.parentNode.removeChild(ldng);
}
}
}
function createA(text, link, title) {
var a = document.createElement("a");
if (link) {
a.setAttribute("href", link);
}
else {
a.style.cursor = "pointer";
}
if (title){ a.setAttribute("title", title); }
a.appendChild(document.createTextNode(text));
return a;
}
function nsr(prefix) {
switch (prefix) {
case "mb":
return "http://musicbrainz.org/ns/mmd-2.0#";
default:
return null;
}
}
do108889();
})();