-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
190 lines (166 loc) · 6.01 KB
/
index.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
const cheerio = require("cheerio");
const request = require("request");
module.exports = async function azurlane(ship) {
return new Promise((resolve, reject) => {
const source = `https://azurlane.koumakan.jp/w/index.php?search=${ship}&title=Special%3ASearch&go=Go`;
request(source, (error, response, html) => {
if (error || response.statusCode !== 200) {
reject(error);
return;
}
const $ = cheerio.load(html);
const shipSearch = $(".mw-search-results li:first-child div a");
const searchCorrection = shipSearch.attr("href");
if (searchCorrection) {
const url = `https://azurlane.koumakan.jp${searchCorrection}`;
request(url, (error, response, html) => {
if (error || response.statusCode !== 200) {
reject(error);
return;
}
search(html, resolve, url);
});
} else {
const url = `https://azurlane.koumakan.jp/w/index.php?search=${ship}`;
request(url, (error, response, html) => {
if (error || response.statusCode !== 200) {
reject(error);
return;
}
search(html, resolve, url);
});
}
});
});
};
function search(html, resolve, url) {
const $ = cheerio.load(html);
const shipbannerSearch = $(".shipgirl-banner span a img");
const banner = shipbannerSearch.attr("src") || undefined; //! banner
const shipskinSearch = $(".ship-card img");
const skin = shipskinSearch.attr("src") || undefined; //! skin
const shipfactionSearch = $(".card-logo img");
const faction = shipfactionSearch.attr("src") || undefined; //! faction
const shipcategorySearch = $(".card-class-stamp img");
const category = shipcategorySearch.attr("src") || undefined; //! category
const shipvoiceSearch = $(".card-info-tbl .sm2_button");
const voice = shipvoiceSearch.attr("href") || undefined; //! voice
const name = $(".mw-page-title-main").text().trim() || undefined; //! name
const title = $(".card-headline span[lang=en]").text().trim() || undefined; //! title
const galleryUrl = url + "/Gallery";
request(galleryUrl, (error, response, html) => {
if (error || response.statusCode !== 200) {
reject(error);
return;
}
const $gallery = cheerio.load(html);
const shipchibiSearch = $gallery(".shipskin-chibi img");
const chibi = shipchibiSearch.attr("src") || undefined; //! chibi
// TODO: ship information
const shiprarity =
$(".card-info-tbl tr:nth-child(2) td").text().trim() || undefined; //! rarity
const shipconstruction =
$(".card-info-tbl tr:nth-child(1) td").text().trim() || undefined; //! construction
const shipclass =
$(".card-info-tbl tr:nth-child(5) td").text().replace(/\n/g, "").trim() ||
undefined; //! class
const shipfaction =
$(".card-info-tbl tr:nth-child(4) td").text().trim() || undefined; //! faction
const shipcategory =
$(".card-info-tbl tr:nth-child(3) td")
.text()
.replace(/\n|→ Guided-missile Destroyer/g, "")
.trim() || undefined; //! category
const shipvoice =
$(".card-info-tbl tr:nth-child(6) td")
.text()
.replace(/Play/g, "")
.trim() || undefined; //! voice
const shipillustrator =
$(".card-info-tbl tr:nth-child(7) td").text().trim() || undefined; //! illustrator
const shipdrop = $(".drop-notes td").text().trim() || undefined; //! drop
const info = {
rarity: shiprarity,
construction: shipconstruction,
class: shipclass,
faction: shipfaction,
category: shipcategory,
voice: shipvoice,
illustrator: shipillustrator,
drop: shipdrop,
};
// TODO: tech points
const techcollection =
$(".ship-fleettech tr:nth-child(2) td:nth-child(3)").text().trim() ||
undefined; //! collection
const techmaxlimitbreak =
$(".ship-fleettech tr:nth-child(3) td:nth-child(3)").text().trim() ||
undefined; //! maxlimitbreak
const techlevel120 =
$(".ship-fleettech tr:nth-child(4) td:nth-child(3)").text().trim() ||
undefined; //! level120
const techtotal =
$(".ship-fleettech tr:nth-child(2) td:nth-child(4)").text().trim() ||
undefined; //! total
const techpoint = {
collection: techcollection,
maxlimitbreak: techmaxlimitbreak,
level120: techlevel120,
total: techtotal,
};
// TODO: limit break
const firstlimitbreak =
$(".ship-limit-break tr:nth-child(3) td").text().trim() || undefined; //! first
const secondlimitbreak =
$(".ship-limit-break tr:nth-child(4) td").text().trim() || undefined; //! second
const thirdlimitbreak =
$(".ship-limit-break tr:nth-child(5) td").text().trim() || undefined; //! third
const limitbreak = {
first: firstlimitbreak || undefined,
second: secondlimitbreak || undefined,
third: thirdlimitbreak || undefined,
};
// TODO: skills
const skills = {};
for (let i = 2; i <= 7; i++) {
const shipskilliconSearch = $(
".ship-skills tr:nth-child(" + i + ") td img"
);
const skillicon = shipskilliconSearch.attr("src") || undefined;
const skillname =
$(".ship-skills tr:nth-child(" + i + ") td b")
.text()
.trim() || undefined;
const skilldescription =
$(".ship-skills tr:nth-child(" + i + ") td:last-child")
.text()
.replace(/\(\) /g, "")
.replace(/\.mw-parser-output.*?}/g, "")
.replace(/body\..*?\s/g, "")
.replace(/body:not\(.+?\):not\(.+?\)\s*/g, "")
.replace(/ andIn-game[^;]*;/g, "")
.replace(/\s+/g, " ")
.replace(/↑[^.]*|\n/g, "")
.trim() || undefined;
skills["skill" + (i - 1)] = {
icon: skillicon,
name: skillname,
description: skilldescription,
};
}
resolve({
banner,
skin,
chibi,
faction,
category,
voice,
name,
title,
info,
techpoint,
limitbreak,
skills,
});
});
}