-
Notifications
You must be signed in to change notification settings - Fork 27
/
jasrac-mb-minc_WORK-IMPORT-CROSS-LINKING.user.js
1359 lines (1359 loc) · 67.2 KB
/
jasrac-mb-minc_WORK-IMPORT-CROSS-LINKING.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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name JASRAC. work importer/editor into MusicBrainz + MB-JASRAC-音楽の森 links + MB back search links
// @version 2024.3.14
// @description One click imports JASRAC works into MusicBrainz (name, iswc, type, credits, edit note, sort name, search hint) and マス歌詞®(mass-lyrics) and wikipedia links. It will do the same magic in work editor. Work links to both JASRAC and 音楽権利情報検索ナビ (ex-音楽の森 aka MINC and Music Forest) and back to MB
// @namespace https://github.com/jesus2099/konami-command
// @supportURL https://github.com/jesus2099/konami-command/labels/jasrac-mb-minc_WORK-IMPORT-CROSS-LINKING
// @downloadURL https://github.com/jesus2099/konami-command/raw/master/jasrac-mb-minc_WORK-IMPORT-CROSS-LINKING.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-01-14; https://web.archive.org/web/20131103163356/userscripts.org/scripts/show/94676 / https://web.archive.org/web/20141011084012/userscripts-mirror.org/scripts/show/94676
// @icon data:image/gif;base64,R0lGODlhEAAQAKEDAP+/3/9/vwAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh/glqZXN1czIwOTkAIfkEAQACAwAsAAAAABAAEAAAAkCcL5nHlgFiWE3AiMFkNnvBed42CCJgmlsnplhyonIEZ8ElQY8U66X+oZF2ogkIYcFpKI6b4uls3pyKqfGJzRYAACH5BAEIAAMALAgABQAFAAMAAAIFhI8ioAUAIfkEAQgAAwAsCAAGAAUAAgAAAgSEDHgFADs=
// @require https://github.com/jesus2099/konami-command/raw/84cae2328f2dca0bc750e0961d669005771f16b8/lib/CONTROL-POMME.js?version=2024.3.14
// @require https://github.com/jesus2099/konami-command/raw/de88f870c0e6c633e02f32695e32c4f50329fc3e/lib/SUPER.js?version=2022.3.24.224
// @grant none
// @match *://*.musicbrainz.org/work/*
// @include /https?:\/\/www\.minc\.or\.jp\/((music|product)\/list|saku\/detail)/
// @match *://www2.jasrac.or.jp/eJwid/main?trxID=*WORKS_CD=*
// @exclude *.org/work/*/*edits*
// @run-at document-end
// ==/UserScript==
"use strict";
let userjs = {
id: "jesus2099userjs94676",
name: GM_info.script.name.substr(4).replace(/\s/g, "\u00a0"),
version: GM_info.script.version
};
/*
https://github.com/jesus2099/konami-command/issues/14
POST work credits NG https://chatlogs.musicbrainz.org/musicbrainz/2015/2015-04/2015-04-09.html#T16-34-38-396540
GET JASRAC ID (work attributes) NG http://tickets.musicbrainz.org/browse/MBS-8341
*/
var MBS7313 = "This script has been partially fixed now but is back to VERY EXPERIMENTAL status!\n(ノ ゜Д゜)ノ 彡┻━┻ Work credits are back on import (not on edit yet). Aliases are still disabled (maybe forever?).";
var DEBUG = localStorage.getItem("jesus2099debug");
var RE_GUID = "[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";
var reISWC = "T- ?\\d{3}\\.\\d{3}.\\d{3}-\\d";
var reCode = "\\d[A-Z\\d]\\d-\\d{4}-\\d";
var reAnnotCode = "(?:jasrac|作品コード)\\W+(" + reCode + ")";
var MBS = self.location.protocol + "//" + self.location.host;
var pagecat = self.location.href.match(new RegExp("(jasrac(?=\\.or\\.jp)|minc(?=\\.or\\.jp)|work(/" + RE_GUID + "/edit$|/create)|work)"));
var oldTitle = document.title;
var xhrForm = {}, xhrWork = {}, h1, iname;
var MBlookups = [];
var joblist = [];
var xhrJobs = {
"workinfo-get": {
info: "PLEASE WAIT (get current work info)",
async: true,
method: "get",
init: function() {
xhrJobs["workinfo-get"].url = MBS + "/ws/2/work/" + xhrWork.mbid + "?fmt=json&inc=annotation+aliases";
},
onload: function() {
if (this.status > 199 && this.status < 400 && this.responseText.match(new RegExp(xhrWork.mbid))) {
var res = JSON.parse(this.responseText);
xhrWork.error = res.error;
if (!xhrWork.error) {
xhrWork.aliases = res.aliases;
xhrWork.annotation = res.annotation ? res.annotation : "";
var code = xhrWork.annotation.match(new RegExp(reAnnotCode, "i"));
if (code) {
insertBefore(createTag("div", {a: {class: "row"}}, [createTag("label", {}, "JASRAC作品コード:"), createTag("b", {s: {backgroundColor: background}}, createA(code[1], workLookupURL("jasrac", "code", code[1]), "JASRAC work code from annotation", "_blank"))]), /* xhrForm.name */ iname.parentNode);
}
aliasTable();
}
document.title = oldTitle;
}
},
},
"work-create/edit": {
method: "post",
async: true,
init: function() {
xhrJobs["work-create/edit"].info = (self.location.pathname.match(/^\/work\/create/) ? "create" : "edit") + " work";
xhrJobs["work-create/edit"].url = xhrForm.form.getAttribute("action");
var inps = xhrForm.form.querySelectorAll("form > div > fieldset:not(." + userjs.id + ") input[name]:not([name='']):not([type='button']), form > div > fieldset:not(." + userjs.id + ") textarea[name], form > div > fieldset:not(." + userjs.id + ") select[name]");
xhrJobs["work-create/edit"].params = "";
for (let inp = 0; inp < inps.length; inp++) {
xhrJobs["work-create/edit"].params += (inp > 0 ? "&" : "") + inps[inp].getAttribute("name") + "=" + encodeURIComponent(inps[inp].value);
}
},
onload: function() {
var mbid = this.responseText.match(new RegExp("<h1>(?:<span class=\"mp\">)?<a[^>]+(" + RE_GUID + ")\""));
xhrWork.id = this.responseText.match(new RegExp("<a[^>]+/work/merge_queue\\?add-to-merge=([0-9]+)\""));
if (!xhrWork.edit && mbid) {
xhrWork.mbid = mbid[1];
if (self.location.pathname.match(/^\/work\/create/) && h1) {
h1.appendChild(document.createTextNode(" "));
h1.appendChild(createA(iname.value, "/work/" + xhrWork.mbid, null, "_blank"));
}
}
if (xhrWork.mbid && xhrWork.id && xhrWork.mbid == mbid[1]) {
xhrMachine();
} else {
alert("Work create (or edit) error #" + this.status + ".\n\n" + this.responseText);
h1.style.setProperty("background-color", "pink");
joblist = [];
disable(xhrForm.form, false);
}
},
},
"batch-relationship-create": {
method: "post",
async: false,
url: "/relationship-editor",
init: function() {
var inps = xhrForm.form.querySelectorAll("div#" + userjs.id + "wcs input.name.lookup-performed, form > div > fieldset:not(." + userjs.id + ") textarea.edit-note");
xhrJobs["batch-relationship-create"].params = "rel-editor.as_auto_editor=" + (isAutoEdit() ? "1" : "0");
var reli = 0;
for (let inp = 0; inp < inps.length; inp++) {
var input = inps[inp];
if (input.classList.contains("lookup-performed")) {
var row = getParent(input, "div", "row");
var rel = "&rel-editor.rels." + (reli++) + ".";
xhrJobs["batch-relationship-create"].params +=
rel + "action=add" +
+ rel + "link_type=" + row.querySelector("input[name='ar.link_type_id']").value
+ rel + "period.ended=0"
+ rel + "entity.0.gid=" + encodeURIComponent(row.querySelector("input[class='gid']").value)
+ rel + "entity.0.type=" + input.parentNode.className.match(/artist|label/)
+ rel + "entity.1.gid=" + xhrWork.mbid
+ rel + "entity.1.type=work";
if (row.querySelector("input[name='ar.attrs.additional']")) {
xhrJobs["batch-relationship-create"].params += rel + "attrs.additional=1";
}
if (row.querySelector("input[name='ar.attrs.translated']")) { // TODO: obsolete, cf. da6c5d8a-ce13-474d-9375-61feb29039a5
xhrJobs["batch-relationship-create"].params += rel + "attrs.translated=1";
}
} else if (input.tagName == "TEXTAREA") {
xhrJobs["batch-relationship-create"].params += "&rel-editor.edit_note=" + encodeURIComponent(input.value.replace(/('''PERFORMERS'''|'''MAIN TITLE''')[^※]+※/, "''{…} cf. MB add work edit for full JASRAC extract''\n\n※").replace(/\u00a0(.+)/g, "") + "\n" + MBlinks());
}
}
},
},
"annotation-get": {
async: true,
info: "get current work annotation",
method: "get",
init: function() {
xhrJobs["annotation-get"].url = MBS + "/ws/2/work/" + xhrWork.mbid + "?inc=annotation";
},
onload: function() {
if (this.status > 199 && this.status < 400 && this.responseText.match(new RegExp("<work.+id=\"" + xhrWork.mbid + "\">"))) {
var oldannot = this.responseText.match(/<annotation><text>([^<]+)<\/text><\/annotation>/);
if (!oldannot || oldannot && !oldannot[1].match(new RegExp(xhrWork.code))) {
if (oldannot) {
xhrWork.annotation = oldannot[1];
}
}
}
xhrMachine();
},
},
"annotation-add": {
async: false,
info: "JASRAC work code annotation",
method: "post",
init: function() {
xhrJobs["annotation-add"].url = MBS + "/work/" + xhrWork.mbid + "/edit_annotation";
var curl = workLookupURL("jasrac", "code", xhrWork.code);
xhrJobs["annotation-add"].params = "edit-annotation.text=" + encodeURIComponent("JASRAC: '''" + xhrWork.code + "''' ([http://tickets.musicbrainz.org/browse/MBS-7359|MBS-7359])" + (xhrWork.annotation ? "\n" + xhrWork.annotation : "")) + "&edit-annotation.changelog=" + encodeURIComponent("JASRAC: " + xhrWork.code + " (MBS-7359)") + "&edit-annotation.edit_note=" + encodeURIComponent("JASRAC: '''" + xhrWork.code + "''' (" + curl + ") ← requires JASRACへの直リンク ('''jasrac_DIRECT-LINK''')\nStill needed for JASRAC auto‐linking (until http://tickets.musicbrainz.org/browse/MBS-7359).\n\n" + MBlinks());
},
},
"alias-add": {
async: false,
method: "post",
init: function() {
xhrJobs["alias-add"].url = MBS + "/work/" + xhrWork.mbid + "/add-alias";
xhrJobs["alias-add"].params = "edit-alias.as_auto_editor=" + (isAutoEdit() ? "1" : "0");
var newAlias = xhrWork.newAliases.shift();
if (newAlias) {
xhrJobs["alias-add"].info = newAlias["edit-alias.name"] + " alias";
if (newAlias["edit-alias.sort_name"].length > 0 && newAlias["edit-alias.sort_name"] != newAlias["edit-alias.name"]) {
xhrJobs["alias-add"].info += "(" + newAlias["edit-alias.sort_name"] + ")";
}
for (let p in newAlias) if (Object.prototype.hasOwnProperty.call(newAlias, p)) {
xhrJobs["alias-add"].params += "&" + p + "=" + encodeURIComponent(newAlias[p]);
}
xhrJobs["alias-add"].params += "&edit-alias.period.ended=&edit-alias.edit_note=" + encodeURIComponent(teditnote.value.replace(/'''CREDITS'''[^※] + '''MAIN TITLE'''/, "'''MAIN TITLE'''") + "\n" + MBlinks());
}
},
},
};
if (pagecat && !document.title.match(/slow down!/i)) {
pagecat = pagecat[1].replace(new RegExp(RE_GUID + "/"), "");
var background = "#FF6"; // favourite game
var cOK = "#CFC"; // bad for ozone layer
var cWARN = "gold";
var cERR = "pink";
var hasLyrics = "詞";
var hasCredits = "作曲";
var vocal = "vocal";
var instrumental = "instrumental";
if (DEBUG) console.log(userjs.id + " pagecat : " + pagecat);
let sakuhinCode, sakuhin;
switch (pagecat) {
case "jasrac":
waitForElement("#management-tabs", function() { // quick and dirty patch
var workName;
var iswc;
var summary = "";
var createWork = "https://musicbrainz.org/work/create?edit-work.name=";
var isVocal = false;
var tables = document.getElementsByTagName("table");
if (tables) {
var work = tables[1];
if (true || work) { // quick and dirty patch
workName = document.querySelector(".baseinfo--name").textContent.trim();
sakuhinCode = document.querySelector(".baseinfo--code strong");
sakuhinCode = {node: sakuhinCode, value: sakuhinCode.textContent};
document.title = workName + " " + sakuhinCode.value + " " + document.title;
createWork += encodeURIComponent(fullwidthToHalfwidth(workName)).replace(/%20/g, "+");
summary += workName + " (work code '''" + sakuhinCode.value + "'''/" + sakuhinCode.value.replace(/-/g, "");
iswc = document.querySelector(".baseinfo--iswc strong");
if (iswc) {
iswc = {node: iswc, value: iswc.textContent};
summary += " — ISWC '''" + iswc.value + "'''/" + iswc.value.replace(/[-.]/g, "");
}
summary += ")\n";
/* var srccred = tables[3];
if (srccred) {
var tmpcred = "";
var credtr = srccred.getElementsByTagName("tr");
if (credtr) {
for (let icred = 2; icred < credtr.length; icred++) {
var credtd = credtr[icred].getElementsByTagName("td");
if (credtd) {
var credit = {role: credtd[2].textContent.trim(), who: credtd[1].textContent.trim()};
credit["trust"] = credtd[4].textContent.trim();
if (credit.trust != "") {
credit.trust = "\u00a0(信託状況:" + credit.trust; // + (!credit.trust.match(/全信託/) ? "sic" : "")
}
credit["manager"] = credtd[5].textContent.trim();
if (credit.manager != "") {
credit.trust += (credit.trust!="" ? "/" : "(") + credit.manager;
}
if (credit.trust != "") {
credit.trust += ")";
}
if (!isVocal && credit.role.indexOf(hasLyrics) > -1) {
isVocal = true;
}
credit["line"] = credit.role + ":" + credit.who + credit.trust + "\n";
if (credit.who != "UNKNOWN PUBLISHER" && tmpcred.indexOf(credit.line) < 0) {
tmpcred += credit.line;
}
}
}
}
if (tmpcred != "") {
summary += "\n'''CREDITS'''\n" + tmpcred;
}
}
var perf = tables[6];
if (perf) {
var perfs = perf.getElementsByTagName("tr");
var max = Math.min(perfs.length, 13);
var tmpperf = "\n'''PERFORMERS'''" + (perfs.length > max ? " (" + (perfs.length - 3) + ")" : "") + "\n";
var isperf = true;
for (let iperf = 3; iperf < max; iperf++) {
var artist = perfs[iperf].getElementsByTagName("td")[1].textContent.trim();
if (artist == "") {
isperf = false;
break;
}
tmpperf += (iperf > 3 ? "\n" : "") + fullwidthToHalfwidth(artist);
}
if (perfs.length > max) tmpperf += "\n…";
if (isperf) {
summary += tmpperf + "\n";
}
}
var alias = tables[5];
if (alias) {
var transtypes = ["'''genuine'''", "''yomikata''", "latin"];
var aliases = alias.getElementsByTagName("tr");
var tmptran = "\n'''MAIN TITLE'''";
var hastran = false;
var tmpali = "\n'''ALIASES/SUBTITLES/SEARCHES/TRANSLATIONS'''";
var hasali = false;
for (let iali = 2; iali < aliases.length; iali++) {
var type = aliases[iali].getElementsByTagName("td")[0].textContent.match(/(正題|タイトルの続き)/);
if (type) {
type = type[1];
} else {
type = "";
}
var alis = aliases[iali].getElementsByTagName("div");
for (let itran = 0; itran < 3; itran++) {
var ali = alis[itran].textContent.trim();
if(type == "正題") {
if (!hastran) {
hastran = true;
}
tmptran += "\n" + ali + " (" + transtypes[itran] + ")";
} else {
if (type == "タイトルの続き") {
if (!ali.match(/^[--]$/)) {
var prevalias = tmpali.substring(tmpali.lastIndexOf("\n")).split("◇");
prevalias[itran] += ali;
tmpali = tmpali.substring(0, tmpali.lastIndexOf("\n")) + prevalias.join("◇");
}
} else {
if (!hasali) {
hasali = true;
}
tmpali += (itran>0 ? "◇" : "\n") + ali;
}
}
}
}
if (hastran) {
summary += tmptran + "\n";
}
if (hasali) {
summary += tmpali + "\n";
}
summary += "\n";
} */
/* -- vv ------ copiable full summary ------ vv -- */
var tr = document.createElement("tr");
var td = document.createElement("td");
td.setAttribute("colspan", "3");
td.style.setProperty("text-align", "center");
td.style.setProperty("background-image", "/eJwid/img/kokoronelogo_A-2out.jpg");
summary += "※ '''JASRAC work importer''' (" + userjs.version + ")\n" + workLookupURL("jasrac", "code", sakuhinCode.value) + " ← requires '''JASRAC direct links enabler'''\n" + workLookupURL("minc", "code", sakuhinCode.value) + " ← mirror, requires account\n";
td.appendChild(document.createTextNode("click to select → "));
var ta = createTag("textarea", {a: {name: "tsummary"}}, summary);
ta.setAttribute("id", ta.getAttribute("name"));
ta.style.setProperty("width", "40%");
ta.setAttribute("rows", "1");
ta.style.setProperty("color", "black");
ta.style.setProperty("background", background);
ta.addEventListener("focus", function(event) {
this.setAttribute("rows", "20");
this.select();
}, false);
ta.addEventListener("mousemove", function(event) {
this.blur();
this.focus();
}, false);
ta.addEventListener("mouseout", function(event) {
this.setAttribute("rows", "1");
}, false);
td.appendChild(ta);
td.appendChild(document.createTextNode(" ← CONTROL key + mouse over to expand + select"));
tr.appendChild(td);
work.appendChild(tr);
/* -- vv ------ Add to MB ------ vv -- */
var form = createTag("form", {a: {action: createWork.split("?")[0], method: "post", "accept-charset": "utf-8", title: "PLEASE REVIEW before final submission!"}, s: {display: "inline", background: background}});
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.attributes.0.type_id", value: "3"}}));
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.attributes.0.value", value: sakuhinCode.value}}));
createWork += "&edit-work.attributes.0.type_id=3&edit-work.attributes.0.value=" + sakuhinCode.value;
if (iswc) {
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.iswcs.0", value: iswc.value}}));
createWork += "&edit-work.iswcs.0=" + iswc.value;
}
if (isVocal) {
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.type_id", value: "17"}}));
createWork += "&edit-work.type_id=17";
} else {
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.language_id", value: "486"}}));
createWork += "&edit-work.language_id=486";
}
/* https://musicbrainz.org/relationships */
createWork += getWorkCredits({
/* artist-work */
"作詞": { nomatch: /^権利者 /, type: "3e48faba-ec01-47fd-8e89-30e81161661c" },
"訳詞": { nomatch: /^権利者 /, type: "da6c5d8a-ce13-474d-9375-61feb29039a5" },
"補詞": { nomatch: /^権利者 /, type: "3e48faba-ec01-47fd-8e89-30e81161661c", additional: "1" },
"作曲": { nomatch: /^権利者 /, type: "d59d99ea-23d4-4a80-b066-edca32ee158f" },
"作曲作詞": { type: "a255bca1-b157-4518-9108-7b147dc3fc68" },
"不明": { type: "a255bca1-b157-4518-9108-7b147dc3fc68" }
}, summary, createWork);
createWork += getWorkCredits({
/* label-work */
"作詞": { match: /^権利者 (.+)$/, type: "05ee6f18-4517-342d-afdf-5897f64276e3" },
"訳詞": { match: /^権利者 (.+)$/, type: "05ee6f18-4517-342d-afdf-5897f64276e3" },
"補詞": { match: /^権利者 (.+)$/, type: "05ee6f18-4517-342d-afdf-5897f64276e3" },
"作曲": { match: /^権利者 ㈱?(.+)$/, type: "05ee6f18-4517-342d-afdf-5897f64276e3" },
"出版者": { type: "05ee6f18-4517-342d-afdf-5897f64276e3" },
"サブ出版": { type: "05ee6f18-4517-342d-afdf-5897f64276e3" }
}, summary, createWork);
form.appendChild(createTag("input", {a: {type: "hidden", name: "edit-work.edit_note", value: summary}}));
createWork += "&edit-work.edit_note=" + encodeURIComponent(summary).replace(/%20/g, "+");
/* form.appendChild(createTag("a", {a: {title: MBS7313 + "\nImport this work in MusicBrainz (name, iswc, type, edit note)"}, s: {background: background, cursor: "pointer", textDecoration: "underline", color: "blue"}, e: {click: function(event) {
this.parentNode.setAttribute("target", event.shiftKey || event.ctrlKey ? "_blank" : "_self");
this.parentNode.submit();
return stop(event);
}}}, "Add to MB")) */
form.appendChild(createTag("a", {a: {href: createWork, title: MBS7313 + "\nImport this work in MusicBrainz (name, iswc, type, edit note)"}, s: {background: background, cursor: "pointer", textDecoration: "blink line-through underline", color: "blue"}}, "Add to MusicBrainz"));
var sakuhin = document.querySelector(".baseinfo--name").firstChild; // quick and dirty patch
sakuhin.parentNode.appendChild(document.createTextNode(" ("));
sakuhin.parentNode.appendChild(form);
sakuhin.parentNode.appendChild(document.createTextNode(")"));
/* -- vv ------ sakuhin links ------ vv -- */
addAfter(document.createElement("sup"), sakuhin).appendChild(createA("MB", workLookupURL("mb", "name", workName), "Search this work name in MusicBrainz"));
addAfter(document.createElement("sup"), sakuhin).appendChild(mincSearch("title", workName, "MF")).style.setProperty("text-decoration", "underline");
addAfter(document.createTextNode(" "), sakuhin);
/* -- vv ------ sakuhin code links ------ vv -- */
sakuhinCode.node = replaceChildren(createA(sakuhinCode.value, workLookupURL("minc", "code", sakuhinCode.value), "This work in MINC"), sakuhinCode.node);
/* -- vv ------ iswc links ------ vv -- */
if (iswc) {
replaceElement(createA(iswc.value, workLookupURL("mb", "iswc", iswc.value), "Search this ISWC in MusicBrainz"), iswc.node);
}
/* -- vv ------ Select music release rights, like CD, etc. ------ vv -- */
// try 複製 then any then fallback on 複製 even if red, and some works like 000-0314-0 even have none
(
document.querySelector("div.management a[href^='#tab-00-']:not(.red)")
?? document.querySelector("div.management a[href^='#tab-99-']:not(.red)")
?? document.querySelector("div.management a[href^='#tab-00-']")
)?.click();
/* -- vv ------ Open performers section ------ vv -- */
document.querySelector("section[data-role='artist'] a.btn-acd.close")?.click();
}
}
}); // quick and dirty patch
break;
case "minc":
setInterval(function() {
var workIDCells = document.querySelectorAll(
// product list page
"tbody td[data-th='JASRAC作品コード']:not(." + userjs.id + "),"
// saku detail page
+ "div#summary-area > div.management > h5 > a.internal_link[href='#jasrac'] + p > span + span:not(." + userjs.id + "),"
+ "div#jasrac-area > table > tbody > tr:nth-of-type(2) > th + td:not(." + userjs.id + ")"
);
for (var w = 0; w < workIDCells.length; w++) {
workIDCells[w].classList.add(userjs.id);
var sakuhinCode = workIDCells[w].firstChild.textContent.trim();
replaceChildren(createA(sakuhinCode, workLookupURL("jasrac", "code", sakuhinCode), "Go to this work in JASRAC"), workIDCells[w]);
}
}, 1234);
var sakuhinmei = document.querySelector("span[id$='_lbl_jas_nt_sakuhinnm']");
sakuhinCode = document.querySelector("span[id$='_jas_sakucd']");
var iswccode = document.querySelector("span[id$='_lbl_jas_nt_iswc']");
if (sakuhinmei && sakuhinCode && iswccode) {
sakuhinmei = getParent(sakuhinmei, "td");
var sakuhinmei_v = sakuhinmei.textContent;
sakuhinCode = getParent(sakuhinCode, "td");
var sakuhinCode_v = sakuhinCode.textContent.match(new RegExp(reCode)) + "";
iswccode = getParent(iswccode, "td");
var iswccode_v = iswccode.textContent.match(new RegExp(reISWC));
var jwForm = jasracSearch("title", sakuhinmei_v);
var jwSubmit = jwForm.querySelector("a[target='_self']");
jwSubmit.replaceChild(document.createTextNode("JW"), jwSubmit.firstChild);
jwSubmit.setAttribute("title", "Search this work name in JASRAC");
jwSubmit.style.setProperty("text-decoration", "underline");
insertBefore(createTag("sup", {s: {float: "right"}}), sakuhinmei.firstChild).appendChild(jwForm);
insertBefore(createTag("sup", {s: {float: "right"}}), sakuhinmei.firstChild).appendChild(createA("MB", workLookupURL("mb", "name", sakuhinmei_v), "Search this work name in MusicBrainz"));
insertBefore(createTag("sup", {s: {float: "right"}}), sakuhinCode.firstChild).appendChild(createA("JW", workLookupURL("jasrac", "code", sakuhinCode_v), "Go to this work in JASRAC"));
insertBefore(createTag("sup", {s: {float: "right"}}), sakuhinCode.firstChild).appendChild(createA("MB", workLookupURL("mb", "code", sakuhinCode_v), "Search this work code in MusicBrainz work annotation (#281 / SEARCH-434)"));
if (iswccode_v) {
iswccode_v += "";
insertBefore(createTag("sup", {s: {float: "right"}}), iswccode.firstChild).appendChild(createA("JW", workLookupURL("jasrac", "iswc", iswccode_v), "Search this ISWC in JASRAC"));
insertBefore(createTag("sup", {s: {float: "right"}}), iswccode.firstChild).appendChild(createA("MB", workLookupURL("mb", "iswc", iswccode_v.replace(/T- /, "T-")), "Search this ISWC in MusicBrainz"));
}
} else {
var sakuhinCodeT = document.querySelectorAll("a[href^='SakCdInfo.aspx?SAKUHINCD='], a[href^='SakCDInfo.aspx?SAKUHINCD='], div#ctl00_ctl00_phMain_phDBMain_PanelDetail table.tbl > tbody > tr > td:nth-child(8)");
for (let st = 0; st < sakuhinCodeT.length; st++) {
sakuhinCode = "";
let prec = sakuhinCodeT[st];
if (sakuhinCodeT[st].tagName == "A") {
sakuhinCode += sakuhinCodeT[st].getAttribute("href").match(/.{8}$/);
} else {
sakuhinCode += sakuhinCodeT[st].textContent.trim().replace(/-/, "");
prec = prec.lastChild;
}
addAfter(createA("MB", workLookupURL("mb", "code", sakuhinCode), "Search this work code in MusicBrainz work annotation (#281 / SEARCH-434)"), prec);
addAfter(createA("JW", workLookupURL("jasrac", "code", sakuhinCode), "Go to this work in JASRAC"), prec);
}
}
break;
case "work":
if (getExtLinks()) {
/* -- vv ------ JASRAC + ongakunomori sakuhin code link ------ vv -- */
// var codes = new RegExp(reAnnotCode, "ig")
var attributes = document.querySelector("h2.work-attributes + script[type='application/json']");
if (attributes && attributes.textContent) {
attributes = JSON.parse(attributes.textContent).attributes;
setInterval(function() {
// React hydrate in work attributes requires such daemon
// retrieve collapsed JASRAC codes (when there are too many work attributes)
var attributeList = document.querySelector("div#sidebar dl.work-attributes");
var codes = [];
for (var a = 0; a < attributes.length; a++) {
if (attributes[a].typeID == 3 && !document.querySelector("div#sidebar dl.work-attributes > dd.work-attribute-jasrac-id[ref='" + attributes[a].value + "']")) {
// {"id": 494106, "typeName": "JASRAC ID", "value_id": null, "value": "052-1235-9", "typeID": 3}
if (codes.indexOf(attributes[a].value.replace(/-/g, "")) > -1) {
if (confirm("Duplicate JASRAC work code " + attributes[a].value + " detected.\nDo you want to edit?")) {
self.location.href = self.location.pathname + "/edit";
}
}
codes.push(attributes[a].value.replace(/-/g, ""));
// check if this is not already displayed
var checkVisibleCodes = document.querySelectorAll("div#sidebar dl.work-attributes > dd.work-attribute-jasrac-id:not([ref='" + attributes[a].value + "'])");
var codeIsVisible = false;
for (var c = 0; c < checkVisibleCodes.length; c++) {
if (checkVisibleCodes[c].textContent.trim() == attributes[a].value) {
codeIsVisible = true;
break;
}
}
if (!codeIsVisible) {
// if this JASRAC ID is not visible yet
attributeList.insertBefore(createTag("dd", {a: {class: "work-attribute work-attribute-jasrac-id", ref: attributes[a].value}}, attributes[a].value), attributeList.firstChild);
attributeList.insertBefore(createTag("dt", {}, attributes[a].typeName + ":"), attributeList.firstChild);
}
}
}
var jasracIDs = document.querySelectorAll("div#sidebar dl.work-attributes > dd.work-attribute-jasrac-id:not(." + userjs.id + ")");
for (let i = 0; i < jasracIDs.length; i++) {
var ddcode = jasracIDs[i].textContent.trim();
replaceElement(createTag("a", {a: {href: workLookupURL("jasrac", "code", ddcode)}, s: {background: background}}, ddcode), jasracIDs[i].firstChild);
jasracIDs[i].classList.add(userjs.id);
}
}, 1000);
for (var a = 0; a < attributes.length; a++) {
switch (attributes[a].typeID) {
case 3:
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "jasrac no-favicon", ref: attributes[a].value}}, createTag("a", {a: {href: workLookupURL("jasrac", "code", attributes[a].value)}, s: {background: background}}, "JASRAC — " + attributes[a].value)));
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "minc no-favicon"}, ref: attributes[a].value}, createTag("a", {a: {href: workLookupURL("minc", "code", attributes[a].value)}, s: {background: background}}, "MINC — " + attributes[a].value)));
break;
case 33:
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "minc no-favicon"}, ref: attributes[a].value}, createTag("a", {a: {href: workLookupURL("minc", "NexTone", attributes[a].value)}, s: {background: background}}, "MINC — " + attributes[a].value)));
break;
}
}
}
/* -- vv ------ JASRAC ISWC link ------ vv -- */
var iswcs = document.querySelectorAll("div#sidebar > dl.properties > dd.iswc > a[href*='/iswc/'] code");
for (let iswc = 0; iswc < iswcs.length; iswc++) {
var iswct = iswcs[iswc].textContent;
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "jasrac no-favicon"}}, createA("JASRAC — " + iswct, workLookupURL("jasrac", "iswc", iswct.replace(/T-/, "T-+")), "Search this ISWC in JASRAC")));
}
/* -- vv ------ JASRAC name search link ------ vv -- */
var title = document.querySelector("h1 a").textContent.trim();
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "jasrac no-favicon"}}, jasracSearch("title", title)));
getExtLinks().appendChild(createTag("li", {a: {class: userjs.id + "minc no-favicon"}}, mincSearch("title", title)));
}
break;
case "work/edit":
xhrWork.edit = true;
xhrWork.mbid = self.location.pathname.match(new RegExp(RE_GUID));
xhrMachine(xhrJobs["workinfo-get"]);
// fall through
case "work/create":
h1 = document.querySelector("h1");
iname = document.getElementById("id-edit-work.name");
xhrForm.form = getParent(iname, "form");
insertBefore(createTag("p", {s: {color: "purple", border: "1px dashed #fcc", backgroundColor: "#ffc"}}, [createTag("h3", {}, userjs.name), MBS7313, " ☞ ", createA("Read more…", "https://github.com/jesus2099/konami-command/issues/14", null, "_blank")]), xhrForm.form);
/* xhrForm.form.addEventListener("submit", function(event) {
var inputs = xhrForm.form.querySelectorAll(xhrForm.originalInputs.css);
var changed = !(xhrWork.edit) || (xhrForm.originalInputs.inputs.length != inputs.length);
for (let i = 0; !changed && i < xhrForm.originalInputs.inputs.length; i++) {
if (xhrForm.originalInputs.inputs[i].value != xhrForm.originalInputs.values[i]) {
changed = true;
}
}
if (changed) {
joblist.push("work-create/edit");
}
var rels = this.querySelectorAll("div#" + userjs.id + "wcs input.name.lookup-performed").length;
if (rels > 0) {
xhrJobs["batch-relationship-create"].info = rels + " relationship" + (rels > 1 ? "s" : "");
joblist.push("batch-relationship-create");
}
if (xhrWork.code && xhrWork.edit && !xhrWork.jasracidmatch) {//je sais pas si je comprendrai toujours ça la prochaine fois
if (xhrWork.edit && typeof xhrWork.annotation == "undefined") {
joblist.push("annotation-get");
}
if (!xhrWork.edit || typeof xhrWork.annotation == "string" && !xhrWork.annotation.match(new RegExp(xhrWork.code))) {
joblist.push("annotation-add");
}
}
var aliases = xhrForm.form.querySelectorAll("table#" + userjs.id + "alta > tfoot > tr > td > input." + userjs.id + "addit[type='checkbox']");
xhrWork.newAliases = [];
for (let a = 0; a < aliases.length; a++) {
if (aliases[a].checked) {
var tr = getParent(aliases[a], "tr");
var n = tr.querySelector("input[name='edit-alias.name']");
var sn = tr.querySelector("input[name='edit-alias.sort_name']");
var t = tr.querySelector("*[name='edit-alias.type_id']");
var p = tr.querySelector("input[name='edit-alias.primary_for_locale']");
var l = tr.querySelector("input[name='edit-alias.locale']");
if (
n && typeof n.value == "string" && n.value.length > 0
&& sn && typeof sn.value == "string"
&& t && typeof t.value == "string"
&& p && typeof p.checked == "boolean"
&& l && typeof l.value == "string"
) {
xhrWork.newAliases.push({
"edit-alias.name": n.value,
"edit-alias.sort_name": sn.value.length>0 ? sn.value : n.value,
"edit-alias.type_id": t.value,
"edit-alias.primary_for_locale": p.checked ? "1" : "0",
"edit-alias.locale": l.value,
});
joblist.push("alias-add");
}
}
}
if (joblist.length > 1 || joblist.length == 1 && joblist[0] != "work-create/edit") {
stop(event);
scrollTo(0, 0);
disable(this, true);
xhrMachine();
}
}, false); */
xhrForm.submit = xhrForm.form.querySelector("div.row button.submit.positive[type='submit']");
xhrForm.originalInputs = {inputs: [], values: [], css: "form > div > fieldset:not(." + userjs.id + ") input:not([type='button']), form > div > fieldset:not(." + userjs.id + ") select"};
xhrForm.originalInputs.inputs = xhrForm.form.querySelectorAll(xhrForm.originalInputs.css);
for (let i = 0; i < xhrForm.originalInputs.inputs.length; i++) {
xhrForm.originalInputs.values.push(xhrForm.originalInputs.inputs[i].value);
}
var icomment = document.getElementById("id-edit-work.comment");
var stypeid = document.getElementById("id-edit-work.type_id");
// TODO: restore language button feature (search slangid) https://github.com/jesus2099/konami-command/issues/321
var slangid = document.querySelector("select[name='edit-work.languages.0']");
var teditnote = document.getElementById("id-edit-work.edit_note");
if (document.referrer.match(/jasrac\.or\.jp/) && (sakuhin = teditnote.value.match(new RegExp("^(.+) \\(work code '''(" + reCode + ")'''"))) !== null) {
xhrWork.code = sakuhin[2];
// workSortName(teditnote.value);
// workCredits(teditnote.value);
}
iname.addEventListener("focus", function(event){ this.style.setProperty("background", ""); }, false);
icomment.addEventListener("focus", function(event){ this.style.setProperty("background", ""); }, false);
stypeid.addEventListener("focus", function(event){ this.style.setProperty("background", ""); }, false);
stypeid.style.setProperty("width", "260px");
var buttons = stypeid.parentNode.appendChild(createTag("span", {a: {class: "buttons"}}, [createTypeButton(vocal), createTypeButton(instrumental)]));
stypeid.style.setProperty("width", (parseInt(self.getComputedStyle(stypeid).getPropertyValue("width"), 10) - parseInt(self.getComputedStyle(buttons).getPropertyValue("width"), 10)) + "px");
// buttons = slangid.parentNode.appendChild(createTag("span", {a: {class: "buttons"}}, [createLangButton("日", 198), createLangButton("EN", 120)]));
// slangid.style.setProperty("width", (parseInt(self.getComputedStyle(slangid).getPropertyValue("width"), 10) - parseInt(self.getComputedStyle(buttons).getPropertyValue("width"), 10)) + "px");
teditnote.parentNode.appendChild(document.createElement("br"));
var tjasrac = document.querySelector("div.workheader p.subheader") || document.querySelector("h1");
tjasrac = tjasrac.appendChild(createTag("textarea", {a: {placeholder: "Paste JASRAC summary here"}}));
addAfter(document.createTextNode(" ← Hover and paste JASRAC summary here for some magic :)"), tjasrac);
tjasrac.setAttribute("tabindex", "-1");
tjasrac.setAttribute("rows", "1");
tjasrac.style.setProperty("overflow", "hidden");
tjasrac.addEventListener("mouseover", function(event) {
if (document.activeElement != this) {
xhrForm.lastinput = document.activeElement;
}
this.blur();
this.focus();
}, false);
tjasrac.addEventListener("focus", function(event) {
this.setAttribute("rows", "4");
this.select();
}, false);
tjasrac.addEventListener("mouseout", function(event) {
this.setAttribute("rows", "1");
if (xhrForm.lastinput && xhrForm.lastinput.focus) {
xhrForm.lastinput.focus();
}
}, false);
tjasrac.addEventListener("keyup", function(event) {
sakuhinCode = this.value.match(new RegExp("work code '''(" + reCode + ")'''"));
if (sakuhinCode && this.value.indexOf(hasCredits) != -1) {
sakuhinCode = sakuhinCode[1];
xhrWork.code = sakuhinCode;
var sakuhin = this.value.match(/^(.+) \(work code/)[1];
if (sakuhin == iname.value) {
iname.style.setProperty("background", cOK);
} else if (iname.value.match(new RegExp(sakuhin, "i"))) {
iname.style.setProperty("background", cWARN);
} else {
iname.style.setProperty("background", cERR);
}
var workattrCSS = "form > div > fieldset > table#work-attributes";
var workattrTypeCSS = "select";
var workattrValueCSS = "input[type='text'][name$='.value']";
var workattr = xhrForm.form.querySelectorAll(workattrCSS + " > tbody > tr");
for (let wa = 0; wa < workattr.length - 1; wa++) {
var type = workattr[wa].querySelector(workattrTypeCSS);
var value = workattr[wa].querySelector(workattrValueCSS);
if (type && value && type.value == "3" && value.value == xhrWork.code) {
xhrWork.jasracidmatch = value;
break;
}
}
if (xhrWork.jasracidmatch) {
xhrWork.jasracidmatch.style.setProperty("background", cOK);
} else if (
workattr.length > 1
&& workattr[workattr.length - 2].querySelector(workattrValueCSS)
&& workattr[workattr.length - 2].querySelector(workattrValueCSS).value == ""
) {
workattr[workattr.length - 2].querySelector(workattrTypeCSS).value = "3";
workattr[workattr.length - 2].querySelector(workattrValueCSS).value = xhrWork.code;
workattr[workattr.length - 2].querySelector(workattrValueCSS).style.setProperty("background", cWARN);
} else {
xhrForm.form.querySelector(workattrCSS + " button.add-item").click();
var jasracidnew = xhrForm.form.querySelectorAll(workattrCSS + " > tbody > tr")[workattr.length - 1];
jasracidnew.querySelector(workattrTypeCSS).value = "3";
jasracidnew.querySelector(workattrValueCSS).style.setProperty("background", cWARN);
jasracidnew.querySelector(workattrValueCSS).value = xhrWork.code;
}
var iswc = this.value.match(/— ISWC '''(T-[0-9]{3}\.[0-9]{3}.[0-9]{3}-[0-9])'''/); // reISWC when MBS-4727 fixed
var insel = "form.edit-work div.form-row-text-list div.text-list-row input.value[name^='edit-work.iswcs.']";
var iiswcs = document.querySelectorAll(insel);
if (iiswcs.length > 0 && iswc) { // MBS-4727
iswc = iswc[1];
var iiswcm;
for (let im = 0; im < iiswcs.length; im++) {
if (iiswcs[im].value == iswc) {
iiswcm = iiswcs[im];
break;
}
}
if (iiswcm) {
iiswcm.style.setProperty("background", cOK);
} else if (iiswcs[iiswcs.length - 1].value == "") {
iiswcs[iiswcs.length - 1].value = iswc;
iiswcs[iiswcs.length - 1].style.setProperty("background", cWARN);
} else {
document.querySelector("form.edit-work div.form-row-text-list div.form-row-add button.add-item").click();
var iswcn = document.querySelectorAll(insel)[iiswcs.length];
iswcn.style.setProperty("background", cWARN);
iswcn.value = iswc;
}
}
setType(this.value.indexOf(hasLyrics) != -1 ? vocal : instrumental);
// workSortName(this.value);
// workCredits(this.value);
teditnote.value = this.value;
this.style.setProperty("background", cOK);
this.value = xhrWork.code + " " + sakuhin;
} else {
icomment.style.setProperty("background", "");
stypeid.style.setProperty("background", "");
this.style.setProperty("background", cERR);
}
scrollTo(0, 0);
}, false);
break;
default:
return false;
}
}
function MBlinks() {
return (xhrWork.id && self.location.href.match(/^\/work\/create/) ? "MB add work edit: " + MBS + "/search/edits?combinator=and&conditions.0.field=work&conditions.0.operator=%3D&conditions.0.name=" + (iname.value ? encodeURIComponent(iname.value) : "TA+GUEULE") + "&conditions.0.args.0=" + xhrWork.id[1] + "&conditions.1.field=type&conditions.1.operator=%3D&conditions.1.args=41\n" : "") + "MB work edit history: " + MBS + "/work/" + xhrWork.mbid + "/edits";
}
function workSortName(txt) {
var sortname = txt.match(/(.+) \(''yomikata''\)/);
var searchint = txt.match(/(.+) \(latin\)/);
var alrows = [];
var aldone = [];
if (sortname) {
alrows.push({name: iname.value, "sort-name": sortname[1], type: "1", locale: "ja", primary: "1"});
aldone.push(iname.value);
aldone.push(sortname[1]);
}
if (searchint) {
searchint = swapTHE(searchint[1], true);
alrows.push({name: searchint, "sort-name": searchint, type: "2"});
aldone.push(searchint);
}
var aliases = txt.substring(txt.indexOf("ALIASES/SUBTITLES/SEARCHES/TRANSLATIONS")).split("\n");
for (let al = 1; al < aliases.length && aliases[al].match(/^.*◇.*◇.*$/); al++) {
var alias = fixSTR(aliases[al]).split("◇");
if (alias[0].length > 0 && !alias[1].match(/^[--]?$/)) {
alrows.push({name: alias[0], "sort-name": alias[1], type: "1", locale: "ja"});
if (alias[2].length > 0) {
let swapped = swapTHE(alias[2], true);
alrows.push({name: swapped, "sort-name": swapped, type: "2"});
aldone.push(swapped);
}
} else {
for (let a = 0; a < 3; a++) {
let swapped = swapTHE(alias[a], true);
if (!alias[a].match(/^[--]?$/) && aldone.indexOf(swapped) == -1) {
alrows.push({name: swapped, "sort-name": swapTHE(alias[a], false)});
aldone.push(swapped);
}
}
}
}
if (alrows.length > 0) {
aliasTable(alrows, true);
}
}
function workCredits(txt) {
var wcs = document.getElementById(userjs.id + "wcs");
if (!wcs) {
wcs = addAfter(createTag("fieldset", {a: {class: userjs.id}}, [createTag("legend", {}, "Relationships"), createTag("p", {}, [createTag("b", {}, "JASRAC sometimes has wrong credits"), " so, please double-check with your booklet then only lookup for the correct relationship(s) you want to create.", document.createElement("br"), "If you change your mind and want to un-lookup one of them, just select and clear the text field.", document.createElement("br"), "Only green fields will queue relationship edits."]), createTag("div", {a: {id: userjs.id + "wcs"}})]), xhrForm.form.querySelector("form > div > fieldset")).querySelector("div#" + userjs.id + "wcs");
}
removeChildren(wcs);
workCredit("artist", {
"作詞": {nomatch: /^権利者 /, english: "lyrics", "ar.link_type_id": "165"},
"訳詞": {nomatch: /^権利者 /, english: "translate lyrics", "ar.link_type_id": "165", "ar.attrs.translated": "1"}, // TODO: obsolete, cf. da6c5d8a-ce13-474d-9375-61feb29039a5
"補詞": {nomatch: /^権利者 /, english: "additional lyrics", "ar.link_type_id": "165", "ar.attrs.additional": "1"},
"作曲": {nomatch: /^権利者 /, english: "compose", "ar.link_type_id": "168"},
"作曲作詞": [{english: "generic write", "ar.link_type_id": "167"}, {english: "compose", "ar.link_type_id": "168"}, {english: "lyrics", "ar.link_type_id": "165"}],
"不明": [{english: "generic write", "ar.link_type_id": "167"}, {english: "compose", "ar.link_type_id": "168"}, {english: "lyrics", "ar.link_type_id": "165"}]
}, txt, wcs);
workCredit("label", {
"作詞": {match: /^権利者 (.+)$/, english: "publish", "ar.link_type_id": "208"},
"訳詞": {match: /^権利者 (.+)$/, english: "publish", "ar.link_type_id": "208"},
"補詞": {match: /^権利者 (.+)$/, english: "publish", "ar.link_type_id": "208"},
"作曲": {match: /^権利者 ㈱?(.+)$/, english: "publish", "ar.link_type_id": "208"},
"出版者": {english: "publish", "ar.link_type_id": "208"},
"サブ出版": {english: "sub-publish", "ar.link_type_id": "208"}
}, txt, wcs);
}
function workCredit(enttype, credtypes, source, pTarget) {
var i = pTarget.querySelectorAll("a[title^='reset'][ref]");
i = i.length > 0 ? parseInt(i[i.length - 1].getAttribute("ref"), 10) + 1 : 0;
for (let credtype in credtypes) if (Object.prototype.hasOwnProperty.call(credtypes, credtype)) {
var ctype = credtypes[credtype].english ? [credtypes[credtype]] : credtypes[credtype];
var cont = pTarget;
for (let c = 0; c < ctype.length; c++) {
var credit, credits = new RegExp("^" + credtype + ":([^\u00a0]+)(?:\u00a0(.+))?$", "igm");
while ((credit = credits.exec(source)) !== null) {
if (cont.tagName != "FIELDSET" && ctype.length > 1) {
cont = cont.appendChild(createTag("fieldset", {a: {class: userjs.id}}, [createTag("legend", {}, "choose either")]));
}
credit = credit[1].trim();
if (credtypes[credtype].nomatch && credit.match(credtypes[credtype].nomatch)) {
continue;
}
if (credtypes[credtype].match) {
if ((credit = credit.match(credtypes[credtype].match)) !== null) {
credit = credit[1];
} else {
continue;
}
}
var ilookupid = userjs.id + "ilookup" + i;
var target = cont.appendChild(createTag("div", {a: {class: "row", title: credit}}));
target.appendChild(createTag("label", {a: {for: ilookupid}}, ctype[c].english + ":"));
target.appendChild(createTag("a", {a: {title: "reset\n" + credit, ref: i}, s: {cursor: "pointer"}, e: {click: function(event) {
MBlookups[this.getAttribute("ref")].clear(true);
}}}, "× "));
var jQac = jQuery(target.appendChild(createTag("span", {a: {class: enttype + " autocomplete" + (ctype.length == 1 || c > 0 ? "" : " " + userjs.id + "manu"), ref: enttype}}, [
createTag("img", {a: {src: "/static/images/icons/search.png", class: "search", alt: "search"}}),
createTag("input", {a: {type: "text", class: "name", id: ilookupid, ref: credit}, s: {width: "150px"}}),
createTag("input", {a: {type: "hidden", class: "id"}}),
createTag("input", {a: {type: "hidden", class: "gid"}}),
])));
MBlookups.push(MB.Control.EntityAutocomplete({inputs: jQac}));
MBlookups[MBlookups.length - 1].indexedSearch = false;
target.querySelector("input.name").value = credit;
jQac.bind("lookup-performed", function(event) {
var remember = xhrForm.form.querySelector("fieldset.editnote label input.jesus2099remember[type='checkbox']");
if (remember && remember.checked) {
remember.click();
}
var name = this.querySelector("input.name");
var gidv = this.querySelector("input.gid").value;
var href = "/" + this.getAttribute("ref") + "/" + gidv;
var rla = this.nextSibling;
if (rla && rla.tagName == "A") {
rla.setAttribute("href", href);
replaceElement(document.createTextNode(name.value), rla.firstChild);
} else {
addAfter(createA(name.value, href, null, "_blank"), this).style.setProperty("white-space", "nowrap");
}
});
if (ctype.length == 1 || c > 0) {
jQac.bind("lookup-performed", function(event) {
var name = this.querySelector("input.name");
var gidv = this.querySelector("input.gid").value;
var others = document.querySelectorAll("div#" + userjs.id + "wcs span.autocomplete");
for (let ot = 0; ot < others.length; ot++) {
if (
!others[ot].classList.contains(userjs.id + "manu")
&& others[ot].querySelector("input.name").getAttribute("ref") == name.getAttribute("ref")
&& !others[ot].querySelector("input.name").classList.contains("lookup-performed")
) {
MBlookups[ot].options.select(document.createEvent("HTMLEvents"), {item: {name: name.value, id: this.querySelector("input.id").value, gid: gidv}});
}
}
});
}
jQac.bind("cleared", function(event) {
var acname = this.querySelector("input.name");
acname.value = acname.getAttribute("ref");
if (this.nextSibling.tagName == "A") {
removeElement(this.nextSibling);
}
});
for (let wap in ctype[c]) if (wap != "english" && Object.prototype.hasOwnProperty.call(ctype[c], wap)) {
target.appendChild(createTag("input", {a: {type: "hidden", name: wap, value: ctype[c][wap]}}));
}
target.appendChild(document.createTextNode(" " + credtype));
target.appendChild(document.createElement("br"));
i++;
}
}
}
}
function getWorkCredits(credtypes, source, url) {
var newParams = "", r = url.lastIndexOf("&rels.");
if (r > -1) {
r = url.substr(r).match(/&rels\.(\d+)\./);
} else {
r = 0;
}
if (r) {
r = parseInt(r[1], 10) + 1;
}
for (let credtype in credtypes) if (Object.prototype.hasOwnProperty.call(credtypes, credtype)) {
var ctype = credtypes[credtype].type ? [credtypes[credtype]] : credtypes[credtype];
for (let c = 0; c < ctype.length; c++) {
var credit, credits = new RegExp("^" + credtype + ":([^\u00a0]+)(?:\u00a0(.+))?$", "igm");
while ((credit = credits.exec(source)) !== null) {
credit = credit[1].trim();
if (credtypes[credtype].nomatch && credit.match(credtypes[credtype].nomatch)) {
continue;
}
if (credtypes[credtype].match) {
if ((credit = credit.match(credtypes[credtype].match)) !== null) {
credit = credit[1];
} else {
continue;
}
}
newParams += "&rels." + r + ".target=" + encodeURIComponent(fullwidthToHalfwidth(credit)) + "&rels." + r + ".direction=backward";
for (let wap in ctype[c]) if (!wap.match(/match$/) && Object.prototype.hasOwnProperty.call(ctype[c], wap)) {
newParams += "&rels." + r + "." + wap + "=" + ctype[c][wap];
}
r++;
}
}
}
return newParams;
}
function disable(w, dis) {
var inputs = w.querySelectorAll("input, select, textarea, button");
var len = inputs.length;
if ((len) && len > 0) {
for (let i = 0; i < len; i++) {
if (dis) {
inputs[i].setAttribute("disabled", "disabled");
} else {
inputs[i].removeAttribute("disabled");
}
}
return true;
} else {
return false;
}
}
function getExtLinks() {
let el = document.querySelector("div#sidebar > ul.external_links");
let sb, lu, lis;
if (el) {
lis = el.getElementsByTagName("li");
if (lis.length == 1 && lis[0].textContent.match(/has no url relationships/i)) {
removeElement(lis[0]);
}
} else if (!el && (sb = document.querySelector("div#sidebar"))) {
lu = sb.querySelector("div#sidebar > p.lastupdate");
if (lu) {
lu = lu.previousSibling;
} else {
lu = sb.lastChild;
}
el = addAfter(createTag("ul", {a: {class: "external_links"}}), lu);
addAfter(createTag("h2", {}, "External links"), lu);
}
return el;
}
function jasracSearch(type, query) {
var formJASRAC = createTag("form", {a: {action: "https://www2.jasrac.or.jp/eJwid/main?trxID=A00401-3#result", method: "post", "accept-charset": "Shift_JIS"}, s: {display: "inline", background: background}});
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "IN_DEFAULT_WORKS_KOUHO_MAX", value: "100"}}));
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "IN_DEFAULT_WORKS_KOUHO_SEQ", value: "1"}}));
switch (type) {
case "title":
if (!maybeJapanese(query)) {
query = removeLeadingArticle(query).toLowerCase();
}
query = removeAccents(query);
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "IN_WORKS_TITLE_NAME1", value: query}}));
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "IN_WORKS_TITLE_CONDITION", value: "1"}}));
break;
}
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "IN_DEFAULT_SEARCH_WORKS_NAIGAI", value: "0"}}));
formJASRAC.appendChild(createTag("input", {a: {type: "hidden", name: "RESULT_CURRENT_PAGE", value: "1"}}));
formJASRAC.appendChild(createCoolSubmit("JASRAC — " + query)).setAttribute("title", formJASRAC.getAttribute("action") + "…");
return formJASRAC;
}
// form charset trick to allow query from MS932 JASRAC site (and any other sites) to utf-8 MINC site
function mincSearch(type, query, label) {
var formMINC = createTag("form", {a: {action: "https://www.minc.or.jp/music/list/", method: "get", "accept-charset": "utf-8"}, s: {display: "inline", background: background}});
switch (type) {
case "title":
if (!maybeJapanese(query)) {
query = removeLeadingArticle(query);
}
query = halfwidthToFullwidth(query.toUpperCase());
formMINC.appendChild(createTag("input", {a: {type: "hidden", name: "tr", value: query}}));
formMINC.appendChild(createTag("input", {a: {type: "hidden", name: "type", value: "search-form-title"}}));
formMINC.appendChild(createTag("input", {a: {type: "hidden", name: "match", value: "1"}}));
break;
}
formMINC.appendChild(createCoolSubmit(label ? label : "MINC — " + query)).setAttribute("title", formMINC.getAttribute("action") + "…");