forked from jesus2099/konami-command
-
Notifications
You must be signed in to change notification settings - Fork 2
/
mb_INLINE-STUFF.user.js
560 lines (560 loc) · 25.2 KB
/
mb_INLINE-STUFF.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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
// ==UserScript==
// @name mb. INLINE STUFF
// @version 2015.1.31.2345
// @description musicbrainz.org release page: Inline recording names, comments, ISRC and AcoustID. Displays CAA count and add link if none. Highlights duplicates in releases and edits.
// @homepage http://userscripts-mirror.org/scripts/show/81127
// @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_INLINE-STUFF.user.js
// @updateURL https://raw.githubusercontent.com/jesus2099/konami-command/master/mb_INLINE-STUFF.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-07-09
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @grant none
// @include http*://*musicbrainz.org/release/*
// @include http*://*musicbrainz.org*edit*
// @include http*://*musicbrainz.org*edits*
// @include http*://*musicbrainz.org/show/edit/?editid=*
// @include http*://*musicbrainz.org/mod/search/results.html*
// @include http*://*musicbrainz.org/artist/*/recordings*
// @exclude http*://*musicbrainz.org/ws/*
// @exclude http*://*musicbrainz.org/release/add
// @exclude http*://*musicbrainz.org/release/add?artist*
// @exclude http*://*musicbrainz.org/release/add?release-group*
// @exclude http*://*musicbrainz.org/release/*annotation*
// @exclude http*://*musicbrainz.org/release/*cover-art*
// @exclude http*://*musicbrainz.org/release/*/relationships
// @exclude http*://*musicbrainz.org/release/*/discids
// @exclude http*://*musicbrainz.org/release/*/tags
// @exclude http*://*musicbrainz.org/release/*/details
// @exclude http*://*musicbrainz.org/release/*/edit
// @exclude http*://*musicbrainz.org/search?*type=*
// @exclude http*://blog.musicbrainz.org*
// @exclude http*://bugs.musicbrainz.org*
// @exclude http*://forums.musicbrainz.org*
// @exclude http*://lists.musicbrainz.org*
// @exclude http*://tickets.musicbrainz.org*
// @exclude http*://wiki.musicbrainz.org*
// @run-at document-end
// ==/UserScript==
(function(){
/* - --- - --- - --- - START OF CONFIGURATION - --- - --- - --- - */
var dupeColour = "pink";
var infoColour = "lightcyan";
var contractFingerPrints = true; /* more compact AcoustIDs but brwoser can still inline search/find full AcoustID */
var pleaseWaitText = "Fetching %s AcoustID and ISRC…"; /* put "" to disable this pleasewait message */
/* track/recording name diff: null for no marking and no inline recording disambiguation comment either,
"" for no name change, %br% is return to new line feed
ex.: "%track-name%*", "%track-name% (%recording-name%)" or even %recording-name% */
var markTrackRecNameDiff = "%track-name%%br%%recording-name%";
var recUseInRelationshipLink = "+relate"; /* null or delete for no such tool */
var recAddToMergeLink = "+merge"; /* null or delete for no such tool */
/* - --- - --- - --- - END OF CONFIGURATION - --- - --- - --- - */
var userjs = "jesus2099userjs81127";
var hasDupeISRCs = 0;
var hasDupeAcoustIDs = 0;
var shownisrcs = [];
var isrcDone = false;
var shownacoustids = [];
var acoustidDone = false;
var shownworks = {"count":0};
var isrcURL = "/isrc/%s";
var acoustidURL = "//acoustid.org/track/%s";
var releasewsURL = "/ws/2/release/%s/?inc=recordings+isrcs"; /* http://wiki.musicbrainz.org/XMLWebService#release_resources */
var str_GUID = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
var re_GUID = new RegExp(str_GUID, "i");
var AcoustIDlinkingURL = "//acoustid.org/edit/toggle-track-mbid?track_gid=%acoustid&mbid=%mbid&state=%state";
var pssh = location.protocol+"//"+location.host;
var css_recording = "td:not(.pos):not(.video) a[href^='"+pssh+"/recording/']";
var css_work = "td:not(.pos):not(.video) div.ars > dl.ars > dd > a[href^='"+pssh+"/work/']";
var pleaseWaitFragment = null;
var tracksHtml = null;
var pagecat = location.href.match(/\/show\/edit\/|\/mod\/search\/|\/edit|\/edits|\/open_edits/i)? "edits" : "release";
if (location.href.match(/\/recordings/i)) { pagecat = "recordings"; }
if (pagecat) {
switch(pagecat) {
case "release":
var relMBID = location.href.match(re_GUID);
if (relMBID && (tracksHtml = document.querySelectorAll("div#content > table.tbl > tbody > tr[id]:not(.subh)")).length > 0) {
if (recUseInRelationshipLink || recAddToMergeLink) {
for (var ith=0; ith < tracksHtml.length; ith++) {
var toolzone = tracksHtml[ith].querySelector("td.treleases");
if (toolzone) {
toolzone = toolzone.appendChild(document.createElement("div"));
toolzone.className = userjs+"toolzone";
toolzone.style.setProperty("display", "none");
if (recUseInRelationshipLink && (rec = tracksHtml[ith].querySelector(css_recording))) {
toolzone.appendChild(createA(recUseInRelationshipLink, rec.getAttribute("href")+"/relate", "Use this recording in a relationship…"));
}
if (recAddToMergeLink && (rat = tracksHtml[ith].querySelector("span.star-rating a.set-rating"))) {
if (recUseInRelationshipLink) { toolzone.appendChild(document.createElement("br")); }
toolzone.appendChild(createA(recAddToMergeLink, "/recording/merge_queue?add-to-merge="+rat.getAttribute("href").match(/id=([0-9]+)/)[1], "Merge this recording…"));
}
toolzone = toolzone.parentNode.appendChild(document.createElement("div"));
toolzone.className = userjs+"editbutt";
toolzone.style.setProperty("display", "none");
toolzone.appendChild(createA("Edit", rec.getAttribute("href")+"/edit", "Edit this recording"));
}
if (works = tracksHtml[ith].querySelectorAll(css_work)) {
for (var w=0; w<works.length; w++) {
if (workid = works[w].getAttribute("href").match(new RegExp("/work/("+str_GUID+")$"))) {
if (!shownworks[workid[1]]) {
shownworks[workid[1]] = 0;
shownworks.count++;
}
shownworks[workid[1]]++;
}
}
}
}
}
idCount("Track", tracksHtml.length);
if (shownworks.count > 0) { idCount("Work", shownworks.count); }
var url = releasewsURL.replace(/%s/, relMBID);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = isrcFish;
xhr.open("GET", url, true);
xhr.overrideMimeType("text/xml");
pleaseWait(true);
xhr.send(null);
}
break;
case "recordings":
var rectable = document.querySelector("div#content table.tbl");
rectable.className += " add-isrcs";/*for later duplicate spot*/
var reclines = rectable.getElementsByTagName("tr");
var icol;
var rectabhd = reclines[0].getElementsByTagName("th");
for (icol=0; icol < rectabhd.length; icol++) {
if (rectabhd[icol].textContent.toLowerCase() == "isrcs") {
break;
}
}
for (var irl=1; irl < reclines.length; irl++) {
var isrctd = reclines[irl].getElementsByTagName("td")[icol];
var tdi = isrctd.textContent.trim();
if (tdi != "") {
tdi = tdi.replace(/[^\w]{2,}/g, " ").split(" ");
removeChildren(isrctd);
for (var itdi=0; itdi < tdi.length; itdi++) {
if (itdi>0) { isrctd.appendChild(document.createElement("br")); }
isrctd.appendChild(createA(tdi[itdi], isrcURL.replace(/%s/, tdi[itdi])));
}
}
}/*no-break, do the duplicate spot below*/
case "edits":
var iedits = document.querySelectorAll("div#page table.add-isrcs");
for (var ied=0; ied<iedits.length; ied++) {
shownisrcs = [];
var as = iedits[ied].getElementsByTagName("a");
for (var ia=0; ia<as.length; ia++) {
var href = as[ia].getAttribute("href").match(/isrc[=/]([^?]+)$/);
if (href) {
as[ia].replaceChild(coolifyISRC(as[ia].textContent), as[ia].firstChild);
if (shownisrcs[href[1]]) {
hasDupeISRCs++;
shownisrcs[href[1]].style.setProperty("background-color", dupeColour);
as[ia].style.setProperty("background-color", dupeColour);
} else {
shownisrcs[href[1]] = as[ia];
}
}
}
}
}
}
function createA(text, link, title, target) {
var a = document.createElement("a");
if (link) { a.setAttribute("href", link); }
else { a.style.setProperty("cursor", "pointer"); }
if (typeof text == "string") { a.appendChild(document.createTextNode(text)); }
else { a.appendChild(text); }
if (title){ a.setAttribute("title", title); }
if (target){ a.setAttribute("target", target); }
return a;
}
function addAfter(n, e) {
if (n && e) {
if (e.nextSibling) { return e.parentNode.insertBefore(n, e.nextSibling); }
else { return e.parentNode.appendChild(n); }
} else { return null; }
}
function removeChildren(p) {
while (p && p.hasChildNodes()) { p.removeChild(p.firstChild); }
}
function pleaseWait(on) {
if (on && pleaseWaitText) {
var pwf = getPleaseWaitFragment();
pwf.appendChild(document.createTextNode(pleaseWaitText.replace(/%s/, " "+pagecat+" ")));
} else if (!on && pleaseWaitFragment) {
document.body.removeChild(pleaseWaitFragment);
pleaseWaitFragment = null;
}
}
function getPleaseWaitFragment() {
if (pleaseWaitFragment == null) {
var pwf = document.createElement("div");
pwf.style.setProperty("position", "fixed");
pwf.style.setProperty("left", "0");
pwf.style.setProperty("bottom", "0");
pwf.style.setProperty("padding", "0 4px");
pwf.style.setProperty("background-color", "#ff0");
pwf.style.setProperty("color", "black");
pwf.style.setProperty("border-right", "2px solid #660");
pwf.style.setProperty("border-top", "2px solid #ffc");
pleaseWaitFragment = document.body.appendChild(pwf);
}
return pleaseWaitFragment;
}
function isrcFish() {
if (this.readyState == 4 && this.status == 200 && tracksHtml) {
var res = this.responseXML;
if (
(CAAcnt = res.documentElement.querySelector("release > cover-art-archive > count")) &&
(CAAtab = document.querySelector("div.tabs > ul.tabs > li > a[href$='/cover-art']")) &&
(CAAtxt = "CAA")
) {
CAAcnt = parseInt(CAAcnt.textContent, 10);
if (CAAcnt > 0) {
CAAtxt += " ("+CAAcnt+")";
CAAtab.style.setProperty("background-color", "#6f9");
}
else {
CAAtxt = "Add "+CAAtxt;
CAAtab.setAttribute("href", CAAtab.getAttribute("href").replace(/cover-art/, "add-cover-art"));
CAAtab.style.setProperty("background-color", "#ff6");
}
CAAtab.style.setProperty("width", self.getComputedStyle(CAAtab).getPropertyValue("width"));
CAAtab.style.setProperty("height", self.getComputedStyle(CAAtab).getPropertyValue("height"));
CAAtab.style.setProperty("text-align", "center");
CAAtab.replaceChild(document.createTextNode(CAAtxt), CAAtab.firstChild);
}
var isrcNet = {};
var recnameNet = {};
var acoustidNet = [];
var tracks = res.evaluate("//mb:recording", res, nsr, XPathResult.ANY_TYPE, null);
for (var pos=1; track = tracks.iterateNext(); pos++) {
var trackMBID = track.getAttribute("id");
if (acoustidNet.indexOf(trackMBID) < 0) { acoustidNet.push(trackMBID); }
isrcNet[trackMBID] = [];
recnameNet[trackMBID] = {};
var isrcs = res.evaluate(".//mb:isrc", track, nsr, XPathResult.ANY_TYPE, null);
while (isrc = isrcs.iterateNext()) {
isrcNet[trackMBID].push(isrc.getAttribute("id"));
}
var recnames = res.evaluate(".//mb:title/text()", track, nsr, XPathResult.ANY_TYPE, null);
while (recname = recnames.iterateNext()) {
recnameNet[trackMBID].name = recname.textContent;
}
var recdisambigs = res.evaluate(".//mb:disambiguation/text()", track, nsr, XPathResult.ANY_TYPE, null);
while (recdisambig = recdisambigs.iterateNext()) {
recnameNet[trackMBID].comment = recdisambig.textContent;
}
}
acoustidFishBatch(acoustidNet);
for (var i=0 ; i < tracksHtml.length ; i++) {
var aRec = tracksHtml[i].querySelector(css_recording);
if (aRec) {
var mbid = aRec.getAttribute("href").match(re_GUID);
var trackTitleCell = tracksHtml[i].querySelector("td:not(.pos):not(.video)");
var trackLinksCell = tracksHtml[i].querySelector("td.links");
if (isrcNet[mbid].length > 0) {
insertBeforeARS(trackTitleCell, createStuffFragment("ISRC", isrcNet[mbid], shownisrcs, isrcURL, null, mbid));
}
if (aRec.textContent != recnameNet[mbid].name) {
var ntit = aRec.getAttribute("title");
ntit = (ntit?ntit+" —\u00a0":"")+"track name: "+aRec.textContent+"\n≠rec. name: "+recnameNet[mbid].name;
aRec.setAttribute("title", ntit);
if (markTrackRecNameDiff != null) {
if (typeof markTrackRecNameDiff == "string" && markTrackRecNameDiff != "") {
var patf = document.createDocumentFragment();
var patt = markTrackRecNameDiff.replace(/%track-name%/ig, aRec.textContent).replace(/%recording-name%/ig, recnameNet[mbid].name).split("%br%");
for (var p=0; p<patt.length; p++) {
if (p>0) { patf.appendChild(document.createElement("br")); }
patf.appendChild(document.createTextNode(patt[p]));
}
aRec.replaceChild(patf, aRec.firstChild);
}
aRec.style.setProperty("text-shadow", "1px 2px 2px #999");
aRec.style.setProperty("color", "maroon");
}
}
if (markTrackRecNameDiff != null && recnameNet[mbid].comment) {
var recdis = document.createElement("span");
recdis.className = userjs+"recdis";
recdis.appendChild(document.createTextNode(" ("+recnameNet[mbid].comment+")"));
addAfter(recdis, aRec);
}
}
}
isrcDone = true;
idCount("ISRC", shownisrcs);
}
}
function createStuffFragment(stufftype, stuffs, shownstuffs, url, trackid, recid) {
var td = document.createElement("dd");
for (var i=0; i < stuffs.length; i++) {
var adisabled = (stufftype == "AcoustID" && stuffs[i][1]);
var stuff = (stufftype == "AcoustID"?stuffs[i][0]:stuffs[i]);
if (i > 0) {
td.appendChild(document.createTextNode(", "));
}
var a = document.createElement("a");
a.style.setProperty("white-space", "nowrap");
a.setAttribute("href", url.replace(/%s/, stuff));
var code = document.createElement("code");
if (stufftype == "ISRC") {
code = coolifyISRC(stuff);
}
else {/*AcoustID*/
if (contractFingerPrints) {
a.style.setProperty("display", "inline-block");
a.style.setProperty("overflow-x", "hidden");
a.style.setProperty("vertical-align", "bottom");
code.setAttribute("title", stuff);
}
code.appendChild(document.createTextNode(stuff));
}
a.appendChild(code);
if (adisabled) {
code.style.setProperty("text-decoration", "line-through");
code.style.setProperty("opacity", ".2");
a.addEventListener("mouseover",function(e){this.firstChild.style.removeProperty("text-decoration");this.firstChild.style.removeProperty("opacity");},false);
a.addEventListener("mouseout",function(e){this.firstChild.style.setProperty("text-decoration","line-through");this.firstChild.style.setProperty("opacity",".2");},false);
}
td.appendChild(a);
if (!adisabled) {
if (shownstuffs[stuff]) {
var bgColour = dupeColour;
if (recid && shownstuffs[stuff]["recid"] == recid) {
bgColour = infoColour;
}
else {
eval("hasDupe"+stufftype+"s++");
}
if (shownstuffs[stuff]["a"].style.getPropertyValue("background-color") != dupeColour) {
shownstuffs[stuff]["a"].style.setProperty("background-color", bgColour);
}
a.style.setProperty("background-color", bgColour);
}
else {
shownstuffs[stuff] = { "a": a, "trackid": trackid, "recid": recid };
}
}
if (stufftype == "AcoustID") {
a.parentNode.appendChild(togAID(recid, stuff, adisabled));
}
}
var tr = document.createElement("dl");
tr.className = "ars";
tr.appendChild(document.createElement("dt").appendChild(document.createTextNode(stufftype+(stuffs.length>1?"s":"")+":")).parentNode);
tr.appendChild(td);
var table = document.createElement("div");
table.className = "ars "+stufftype+"81127";
table.style.setProperty("display", localStorage.getItem("hide"+stufftype+"81127")=="1"?"none":"block");
table.appendChild(tr);
return table;
}
function togAID(rec, aid, dis) {
var acoustracktoggle = createA(dis?"+":"×", AcoustIDlinkingURL.replace(/%acoustid/, aid).replace(/%mbid/, rec).replace(/%state/, dis?"0":"1"), dis?"Link AcoustID to this recording":"Unlink AcoustID from this recording", "_blank");
acoustracktoggle.style.setProperty("color", dis?"green":"red");
return acoustracktoggle;
}
function insertBeforeARS(par, chi) {
var ars = par.getElementsByClassName("ars");
if (ars.length > 0) { return par.insertBefore(chi, ars[0]); }
else { return par.appendChild(chi); }
}
function nsr(prefix) {
switch (prefix) {
case "mb":
return "http://musicbrainz.org/ns/mmd-2.0#";
default:
return null;
}
}
var bonusclicks = [];
function idCount(type, hash) {
var idCountZone = document.querySelector("div#sidebar div#"+userjs+"idcountzone");
if (!idCountZone) {
idCountZone = document.querySelector("div#sidebar > dl.properties").appendChild(document.createElement("div"));
idCountZone.setAttribute("id", userjs+"idcountzone");
idCountZone.style.setProperty("border", "1px dashed silver");
var showTZ = idCountZone.appendChild(document.createElement("dd")).appendChild(document.createElement("label")).appendChild(document.createElement("input"));
showTZ.setAttribute("type", "checkbox");
showTZ.parentNode.appendChild(document.createTextNode(" Show relate/merge tools"));
showTZ.addEventListener("click", function(e) {
var tzs = document.querySelectorAll("div."+userjs+"toolzone");
for (var tz = 0; tz < tzs.length; tz++) {
tzs[tz].style.setProperty("display", this.checked?"block":"none");
}
}, false);
var showEB = idCountZone.appendChild(document.createElement("dd")).appendChild(document.createElement("label")).appendChild(document.createElement("input"));
showEB.setAttribute("type", "checkbox");
showEB.parentNode.appendChild(document.createTextNode(" Show Edit rec. buttons"));
showEB.addEventListener("click", function(e) {
var ebs = document.querySelectorAll("div."+userjs+"editbutt");
for (var eb = 0; eb < ebs.length; eb++) {
ebs[eb].style.setProperty("display", this.checked?"block":"none");
}
}, false);
}
var count = 0;
if (typeof hash == "number") { count = hash; }
else { for (key in hash) { if (hash.hasOwnProperty(key)) { count++; } } }
if (count != 0) {
var errorMsg = { "-20": "acoustid.org unreachable", "-21": "Strange result from acoustid.org" };
var cooldt = idCountZone.appendChild(document.createElement("dt")).appendChild(document.createTextNode(type+(count>1?"s":"")+":")).parentNode;
var cooldd = idCountZone.appendChild(document.createElement("dd")).appendChild(document.createTextNode(count<0?errorMsg[count]+" (or\u00a0something\u00a0like\u00a0that)":count)).parentNode;
if (count<0) {
cooldt.setAttribute("title", "Error "+count);
cooldt.style.setProperty("background-color", dupeColour);
}
else if (count >= 0 && type != "Track" && type != "Work") {
var dupes = 0;
try { eval("dupes = hasDupe"+type+"s;"); } catch(e) {}
if (dupes > 0) {
cooldt.setAttribute("title", "There "+(dupes==1?"is 1":"are "+dupes)+" duplicate"+(dupes==1?"":"s"));
cooldt.style.setProperty("background-color", dupeColour);
}
cooldd.appendChild(document.createTextNode(" ("));
var typetoggle = cooldd.appendChild(createA(localStorage.getItem("hide"+type+"81127")=="1"?"show":"hide", null, "shift+click to hide/show all"));
typetoggle.style.setProperty("cursor", "pointer");
typetoggle.setAttribute("id", "tog81127"+type);
typetoggle.addEventListener("click", function(e) {
var type = this.getAttribute("id").match(/^tog81127([a-z]+)$/i)[1];
var show = (this.textContent == "show");
localStorage.setItem("hide"+type+"81127", show?"0":"1");
var togstuffs = document.getElementsByClassName(type+81127);
for (var itog=0; itog < togstuffs.length; itog++) {
togstuffs[itog].style.setProperty("display", show?"block":"none");
}
this.replaceChild(document.createTextNode(show?"hide":"show"), this.firstChild);
if (e.shiftKey && bonusclicks.length == 0) {
if (showHideARSButt = document.querySelector("a."+(show?"show":"hide")+"-credits")) {
showHideARSButt[0].click();
} else {
var ars = document.querySelectorAll("div.ars");
for (var iar=0; iar< ars.length; iar++) {
ars[iar].style.setProperty("display", show?"block":"none");
}
}
if ((showToolZones = document.querySelectorAll("div#sidebar div#"+userjs+"idcountzone input[type='checkbox']"))) {
for (var stz=0; stz < showToolZones.length; stz++) {
if (showToolZones[stz].checked != show) showToolZones[stz].click();
}
}
var otogs = ["AcoustID", "ISRC"];
for (var iotog=0; iotog < otogs.length; iotog++) {
var togid = "tog81127"+otogs[iotog];
var toglnk = document.getElementById(togid);
if (this.id != togid && toglnk && toglnk.textContent == (show?"show":"hide")) {
bonusclicks.push(toglnk);
}
}
}
if (bonusclicks.length > 0) {
bonusclicks.pop().click();
}
}, false);/*onclick*/
cooldd.appendChild(document.createTextNode(")"));
}
}
if (isrcDone && acoustidDone) {
pleaseWait(false);
}
}
function coolifyISRC(isrc) {
function truc(txt, i) {
var ivt = document.createElement("span");
ivt.appendChild(document.createTextNode(txt));
if (i) {
ivt.style.setProperty("color", "red");
ivt.style.setProperty("margin", "0 .1em");
ivt.style.setProperty("text-shadow", "1px 2px 2px yellow");
}
return ivt;
}
if (isrc.match(/[a-z]{2}\-?[a-z0-9]{3}\-?[0-9]{2}\-?[0-9]{5}/i)) {
var coolISRC = document.createElement("code");
coolISRC.appendChild(truc(isrc.substr(0,2), true));
coolISRC.appendChild(truc(isrc.substr(2,3), false));
coolISRC.appendChild(truc(isrc.substr(5,2), true));
coolISRC.appendChild(truc(isrc.substr(7,5), false));
return coolISRC;
}
else { return document.createTextNode(isrc); }
}
/* http://tiffanybbrown.com/presentations/2011/xhr2/ */
function acoustidFishBatch(recids) {
if (recids.length > 0) {
var xhr = new XMLHttpRequest();
xhr.onload = function(e) {
if (
this.status == 200 &&
(res = this.responseXML.documentElement) &&
(wsstatus = res.querySelector("response > status")) &&
wsstatus.textContent == "ok" &&
(mbids = res.querySelectorAll("response > mbids > mbid > mbid:not(:empty)"))
) {
var acoustids = {};
for (var m = 0; m < mbids.length; m++) {
if ((mbid = mbids[m].textContent) && mbid.match(re_GUID)) {
if (!acoustids[mbid]) { acoustids[mbid] = []; }
var trackids = mbids[m].parentNode.querySelectorAll("track > id:not(:empty)");
for (var ti = 0; ti < trackids.length; ti++) {
if ((trackid = trackids[ti].firstChild.textContent) && trackid.match(re_GUID)) {
var disabled = trackids[ti].parentNode.querySelector("disabled");
disabled = disabled && disabled.textContent.match(/true/i);
var duo = [trackid, disabled];
if (disabled) { acoustids[mbid].push(duo); }
else { acoustids[mbid].unshift(duo); }
}
}
}
}
for (var th = 0; th < tracksHtml.length; th++) {
if (
(recmbid = tracksHtml[th].querySelector(css_recording)) &&
(recmbid = recmbid.getAttribute("href").match(new RegExp("/("+str_GUID+")$"))) &&
(recmbid = recmbid[1]) &&
acoustids[recmbid].length > 0 &&
(trackTitleCell = tracksHtml[th].querySelector("td:not(.pos):not(.video)"))
) {
var aidtable = insertBeforeARS(trackTitleCell, createStuffFragment("AcoustID", acoustids[recmbid], shownacoustids, acoustidURL, null, recmbid));
if (contractFingerPrints) {
var show = aidtable.style.getPropertyValue("display") == "block";
aidtable.style.setProperty("display", "block");
var aids = aidtable.querySelectorAll("a > code[title]");
for (var aid=0; aid<aids.length; aid++) {
aids[aid].parentNode.style.setProperty("width", parseInt(self.getComputedStyle(aids[aid].parentNode).getPropertyValue("width").match(/^\d+/)+"", 10)/aids[aid].textContent.length*6+"px");
}
aidtable.style.setProperty("display", show?"block":"none");
}
}
}
}
else {
shownacoustids = -21;
}
acoustidDone = true;
idCount("AcoustID", shownacoustids);
};
xhr.onerror = function(e) {
acoustidDone = true;
idCount("AcoustID", -20);
};
xhr.open("post", "//api.acoustid.org/v2/track/list_by_mbid", true);
var params = "client=A6AsOfBc&format=xml&batch=1&disabled=1";
for (var m = 0; m < recids.length; m++) {
params += "&mbid="+recids[m];
}
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.setRequestHeader("Content-length", params.length);
xhr.setRequestHeader("Connection", "close");
xhr.overrideMimeType("text/xml");
xhr.send(params);
}
}
})();