10
10
// @grant none
11
11
// ==/UserScript==
12
12
13
-
14
13
( ( ) => {
15
- 'use strict' ;
16
-
17
- // Utilities.
14
+ "use strict" ;
18
15
19
- const sel = document . querySelector . bind ( document ) ;
20
- const selAll = document . querySelectorAll . bind ( document ) ;
21
- const selIn = ( el , selector ) => el . querySelector ( selector ) ;
22
- const get = prop => obj => obj [ prop ] ;
23
- const esc = encodeURIComponent ;
24
- const dom = ( tag , attrs , ...children ) => {
25
- const el = document . createElement ( tag ) ;
26
- if ( attrs ) Object . keys ( attrs ) . forEach ( attr => el . setAttribute ( attr , attrs [ attr ] ) ) ;
27
- children . map ( obj => typeof obj === 'string' ? document . createTextNode ( obj ) : obj )
28
- . forEach ( node => el . appendChild ( node ) ) ;
29
- return el ;
30
- } ;
31
- const counter = ( ) => { let i = 0 ; return ( ) => i ++ } ;
32
- const flatten = list => list . reduce ( ( r , item ) => Array . isArray ( item ) ? r . concat ( flatten ( item ) ) : r . concat ( [ item ] ) , [ ] ) ;
16
+ // Utilities.
33
17
18
+ const sel = document . querySelector . bind ( document ) ;
19
+ const selAll = document . querySelectorAll . bind ( document ) ;
20
+ const selIn = ( el , selector ) => el . querySelector ( selector ) ;
21
+ const get = ( prop ) => ( obj ) => obj [ prop ] ;
22
+ const esc = encodeURIComponent ;
23
+ const dom = ( tag , attrs , ...children ) => {
24
+ const el = document . createElement ( tag ) ;
25
+ if ( attrs )
26
+ Object . keys ( attrs ) . forEach ( ( attr ) => el . setAttribute ( attr , attrs [ attr ] ) ) ;
27
+ children
28
+ . map ( ( obj ) =>
29
+ typeof obj === "string" ? document . createTextNode ( obj ) : obj ,
30
+ )
31
+ . forEach ( ( node ) => el . appendChild ( node ) ) ;
32
+ return el ;
33
+ } ;
34
+ const counter = ( ) => {
35
+ let i = 0 ;
36
+ return ( ) => i ++ ;
37
+ } ;
38
+ const flatten = ( list ) =>
39
+ list . reduce (
40
+ ( r , item ) =>
41
+ Array . isArray ( item ) ? r . concat ( flatten ( item ) ) : r . concat ( [ item ] ) ,
42
+ [ ] ,
43
+ ) ;
34
44
35
- // Get values.
45
+ // Get values.
36
46
37
- const values =
38
- Array . from ( selAll ( '#discdata_right_body .discdata li' ) )
39
- . reduce ( ( r , el ) => {
40
- const text = el . textContent ;
41
- if ( / ^ ア ー テ ィ ス ト / . test ( text ) ) r . artist = selIn ( el , 'div' ) . textContent ;
42
- else if ( / ^ 原 題 / . test ( text ) ) r . title = selIn ( el , 'div' ) . textContent ;
43
- else if ( / ^ 形 態 / . test ( text ) ) r . type = selIn ( el , 'div' ) . textContent . split ( ' /' ) [ 0 ] ;
44
- else if ( / ^ レ ー ベ ル / . test ( text ) ) r . label = selIn ( el , 'div' ) . textContent ;
45
- else if ( / ^ 規 格 品 番 / . test ( text ) ) r . cat = selIn ( el , 'div' ) . textContent ;
46
- else if ( / ^ 発 売 日 / . test ( text ) ) r . date = selIn ( el , 'div' ) . textContent . split ( '/' ) ;
47
- return r ;
48
- } , { } ) ;
49
- values . tracks = Array . from ( selAll ( '.songlist .song .song_title' ) )
50
- . map ( get ( 'textContent' ) ) ;
51
- if ( ! ( 'title' in values ) ) values . title = sel ( '#center_body h1' ) . textContent . match ( / \/ ( .+ ) $ / ) [ 1 ] ;
47
+ const values = Array . from ( selAll ( "#discdata_right_body .discdata li" ) ) . reduce (
48
+ ( r , el ) => {
49
+ const text = el . textContent ;
50
+ if ( / ^ ア ー テ ィ ス ト / . test ( text ) ) r . artist = selIn ( el , "div" ) . textContent ;
51
+ else if ( / ^ 原 題 / . test ( text ) ) r . title = selIn ( el , "div" ) . textContent ;
52
+ else if ( / ^ 形 態 / . test ( text ) )
53
+ r . type = selIn ( el , "div" ) . textContent . split ( " /" ) [ 0 ] ;
54
+ else if ( / ^ レ ー ベ ル / . test ( text ) ) r . label = selIn ( el , "div" ) . textContent ;
55
+ else if ( / ^ 規 格 品 番 / . test ( text ) ) r . cat = selIn ( el , "div" ) . textContent ;
56
+ else if ( / ^ 発 売 日 / . test ( text ) )
57
+ r . date = selIn ( el , "div" ) . textContent . split ( "/" ) ;
58
+ return r ;
59
+ } ,
60
+ { } ,
61
+ ) ;
62
+ values . tracks = Array . from ( selAll ( ".songlist .song .song_title" ) ) . map (
63
+ get ( "textContent" ) ,
64
+ ) ;
65
+ if ( ! ( "title" in values ) )
66
+ values . title = sel ( "#center_body h1" ) . textContent . match ( / \/ ( .+ ) $ / ) [ 1 ] ;
52
67
68
+ // Add submit link.
53
69
54
- // Add submit link.
70
+ const checkType = ( raw ) =>
71
+ raw === "アルバム"
72
+ ? "album"
73
+ : raw === "ミニアルバム"
74
+ ? "ep"
75
+ : raw === "シングル"
76
+ ? "single"
77
+ : "" ;
55
78
56
- const checkType = raw => raw === 'アルバム' ? 'album'
57
- : raw === 'ミニアルバム' ? 'ep'
58
- : raw === 'シングル' ? 'single'
59
- : '' ;
79
+ const link = dom ( "a" , null , "MusicBrainz に投稿" ) ;
80
+ const input = ( name , value ) =>
81
+ dom ( "input" , { name : name , value : value , type : "text" } ) ;
82
+ const form = dom (
83
+ "form" ,
84
+ {
85
+ name : "musicbrainz-submit" ,
86
+ action : "https://musicbrainz.org/release/add" ,
87
+ method : "post" ,
88
+ "accept-charset" : "utf-8" ,
89
+ style : "display: none" ,
90
+ } ,
91
+ input ( "name" , values . title ) ,
92
+ input ( "artist_credit.names.0.name" , values . artist ) ,
93
+ input ( "type" , checkType ( values . type ) ) ,
94
+ input ( "labels.0.name" , values . label ) ,
95
+ input ( "labels.0.catalog_number" , values . cat ) ,
96
+ input ( "events.0.date.year" , values . date [ 0 ] ) ,
97
+ input ( "events.0.date.month" , values . date [ 1 ] ) ,
98
+ input ( "events.0.date.day" , values . date [ 2 ] ) ,
99
+ input ( "events.0.country" , "JP" ) ,
100
+ input ( "language" , "jpn" ) ,
101
+ input ( "script" , "Jpan" ) ,
102
+ input ( "status" , "official" ) ,
103
+ input ( "mediums.0.format" , "cd" ) ,
104
+ input ( "edit_note" , "From CDJournal: " + window . location . href ) ,
105
+ ) ;
106
+ const container = dom ( "div" , { id : "musicbrainz-submit" } , link , form ) ;
60
107
61
- const link = dom ( 'a' , null , 'MusicBrainz に投稿' ) ;
62
- const input = ( name , value ) => dom ( 'input' , { name : name , value : value , type : 'text' } ) ;
63
- const form = dom ( 'form' , { name : 'musicbrainz-submit' , action : 'https://musicbrainz.org/release/add' , method : 'post' , 'accept-charset' : 'utf-8' , style : 'display: none' } ,
64
- input ( 'name' , values . title ) ,
65
- input ( 'artist_credit.names.0.name' , values . artist ) ,
66
- input ( 'type' , checkType ( values . type ) ) ,
67
- input ( 'labels.0.name' , values . label ) ,
68
- input ( 'labels.0.catalog_number' , values . cat ) ,
69
- input ( 'events.0.date.year' , values . date [ 0 ] ) ,
70
- input ( 'events.0.date.month' , values . date [ 1 ] ) ,
71
- input ( 'events.0.date.day' , values . date [ 2 ] ) ,
72
- input ( 'events.0.country' , 'JP' ) ,
73
- input ( 'language' , 'jpn' ) ,
74
- input ( 'script' , 'Jpan' ) ,
75
- input ( 'status' , 'official' ) ,
76
- input ( 'mediums.0.format' , 'cd' ) ,
77
- input ( 'edit_note' , 'From CDJournal: ' + window . location . href )
78
- ) ;
79
- const container = dom ( 'div' , { id : 'musicbrainz-submit' } , link , form ) ;
108
+ const trackCount = counter ( ) ;
109
+ flatten (
110
+ values . tracks . map ( ( title ) => {
111
+ const i = trackCount ( ) ;
112
+ return [
113
+ input ( `mediums.0.track.${ i } .name` , title ) ,
114
+ input ( `mediums.0.track.${ i } .number` , i + 1 ) ,
115
+ ] ;
116
+ } ) ,
117
+ ) . map ( ( el ) => form . appendChild ( el ) ) ;
80
118
81
- const trackCount = counter ( ) ;
82
- flatten ( values . tracks
83
- . map ( title => {
84
- const i = trackCount ( ) ;
85
- return [ input ( `mediums.0.track.${ i } .name` , title ) ,
86
- input ( `mediums.0.track.${ i } .number` , i + 1 ) ] ;
87
- } ) )
88
- . map ( el => form . appendChild ( el ) ) ;
119
+ sel ( "#artist_sub" ) . appendChild ( container ) ;
120
+ link . addEventListener ( "click" , ( e ) => {
121
+ form . submit ( ) ;
122
+ e . preventDefault ( ) ;
123
+ } ) ;
89
124
90
- sel ( '#artist_sub' ) . appendChild ( container ) ;
91
- link . addEventListener ( 'click' , e => {
92
- form . submit ( ) ;
93
- e . preventDefault ( ) ;
94
- } ) ;
95
-
96
- sel ( 'head' ) . appendChild ( dom ( 'style' , null , `
125
+ sel ( "head" ) . appendChild (
126
+ dom (
127
+ "style" ,
128
+ null ,
129
+ `
97
130
#musicbrainz-submit a {
98
131
cursor: pointer;
99
132
font-size: 1.2em;
100
133
font-weight: bold;
101
134
}
102
- ` ) ) ;
103
-
104
- } ) ( )
135
+ ` ,
136
+ ) ,
137
+ ) ;
138
+ } ) ( ) ;
0 commit comments