Skip to content

Commit 6ea7923

Browse files
committed
Format all files with latest Prettier
1 parent 0c59d8d commit 6ea7923

File tree

6 files changed

+318
-222
lines changed

6 files changed

+318
-222
lines changed

CDJournal to MusicBrainz/cdjournal-to-musicbrainz.user.js

Lines changed: 110 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -10,95 +10,129 @@
1010
// @grant none
1111
// ==/UserScript==
1212

13-
1413
(() => {
15-
'use strict';
16-
17-
// Utilities.
14+
"use strict";
1815

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.
3317

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+
);
3444

35-
// Get values.
45+
// Get values.
3646

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];
5267

68+
// Add submit link.
5369

54-
// Add submit link.
70+
const checkType = (raw) =>
71+
raw === "アルバム"
72+
? "album"
73+
: raw === "ミニアルバム"
74+
? "ep"
75+
: raw === "シングル"
76+
? "single"
77+
: "";
5578

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);
60107

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));
80118

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+
});
89124

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+
`
97130
#musicbrainz-submit a {
98131
cursor: pointer;
99132
font-size: 1.2em;
100133
font-weight: bold;
101134
}
102-
`));
103-
104-
})()
135+
`,
136+
),
137+
);
138+
})();

IMDB reprioritize/imdb-reprioritize.user.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@
88
// @grant none
99
// ==/UserScript==
1010

11-
1211
// Utils.
1312

14-
const onLoad = cb => /interactive|complete/.test(document.readyState) ? setTimeout(cb, 0) : document.addEventListener('DOMContentLoaded', cb);
13+
const onLoad = (cb) =>
14+
/interactive|complete/.test(document.readyState)
15+
? setTimeout(cb, 0)
16+
: document.addEventListener("DOMContentLoaded", cb);
1517
const sel = document.querySelector.bind(document);
1618

17-
1819
// Modify stuff.
1920

2021
onLoad(() => {
22+
if (window.top !== window.self) return; // Prevent loading on iframes.
2123

22-
if (window.top !== window.self) return; // Prevent loading on iframes.
23-
24-
const details = sel('#titleDetails');
25-
const storyline = sel('#titleStoryLine');
26-
const mainBottom = sel('#main_bottom')
27-
28-
mainBottom.prepend(storyline);
29-
mainBottom.prepend(details);
24+
const details = sel("#titleDetails");
25+
const storyline = sel("#titleStoryLine");
26+
const mainBottom = sel("#main_bottom");
3027

28+
mainBottom.prepend(storyline);
29+
mainBottom.prepend(details);
3130
});
32-

Pocket direct links/pocket-direct-links.user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ onLoad(() => {
3232
Array.from(document.querySelectorAll("article")).forEach(fixOne);
3333
};
3434

35-
const fixOne = (el) => {
35+
const fixOne = (el) => {
3636
const url = getUrl(el);
3737
if (!el.getAttribute(attrFixedFlag)) {
3838
const links = el.querySelectorAll(".content .title a, .cardWrap a");

Taiwan ISRC to MusicBrainz/taiwan-isrc-to-musicbrainz.user.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// ==/UserScript==
1111

1212
(() => {
13-
"use strict";
14-
1513
// Utilities.
1614

1715
const sel = document.querySelector.bind(document);
@@ -24,11 +22,11 @@
2422
const el = document.createElement(tag);
2523
if (attrs)
2624
Object.keys(attrs).forEach((attr) =>
27-
el.setAttribute(attr.toString(), attrs[attr] ?? "")
25+
el.setAttribute(attr.toString(), attrs[attr] ?? ""),
2826
);
2927
children
3028
.map((obj) =>
31-
typeof obj === "string" ? document.createTextNode(obj) : obj
29+
typeof obj === "string" ? document.createTextNode(obj) : obj,
3230
)
3331
.forEach((node) => el.appendChild(node));
3432
return el;
@@ -64,7 +62,7 @@
6462
class: "btn btn-outline-secondary pull-right",
6563
id: "musicbrainz-button",
6664
},
67-
"Add to MusicBrainz"
65+
"Add to MusicBrainz",
6866
);
6967

7068
const form: HTMLFormElement = dom("form", {
@@ -91,8 +89,8 @@
9189
`
9290
#musicbrainz-button {
9391
float: right
94-
}`
95-
)
92+
}`,
93+
),
9694
);
9795

9896
const table = sel(".table");
@@ -134,7 +132,7 @@
134132
else if (//.test(label)) r.date = value.split(".");
135133
return r;
136134
},
137-
{}
135+
{},
138136
);
139137

140138
values.tracks = Array.from(songsTable.querySelectorAll("tr") ?? []).map(
@@ -157,7 +155,7 @@
157155
? `${hours * 60 + minutes}:${paddedSeconds}`
158156
: "0:00",
159157
};
160-
}
158+
},
161159
);
162160

163161
console.log({ values });

0 commit comments

Comments
 (0)