-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
113 lines (96 loc) · 2.9 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
const { text } = require("./shiroko.json").parse;
function getStudent() {
const studentName = (() => {
const { groups: { en, jp }, } =
(/<th>Full Name<\/th><td>(?<en>[\w\p{L}\s]*)(?:<br \/>|\s*)\((?<jp>[\w\p{L}\s]*)\)<\/td>/gisu.exec(
text
));
return { en, jp };
})();
const {
groups: { studentRarity },
} = /class=\"character-rarity\" data-value=\"(?<studentRarity>\d)/gim.exec(text);
const {
groups: { studentProfileImg },
} = /data-title=\"Profile\s?Image[\"><a-z\s=\-:\/\.]*src=\"\/\/(?<studentProfileImg>[a-zA-Z\.\/0-9-_]*)/gim.exec(
text
);
const {
groups: { studentSchool, studentGroup, studentRole },
} = /(?:<th class=\"character-school character-header\">.*?<td title=\")(?<studentSchool>[^,]*?)(?:,\s*)(?<studentGroup>[^\"]*)(?:\">)(?:.*?<td>.*?<\/p>\s*)(?<studentRole>.*?)(?:<\/td>)/gis.exec(
text
);
const {
groups: { studentDamageType },
} = /(?:<tr><th>Damage Type<\/th>\s*<td.*?>)(?<studentDamageType>[^<]*)(?:<\/td>)/gis.exec(
text
);
const {
groups: { studentArmorType },
} = /(?:<tr><th>Armor Type<\/th>\s*<td.*?>)(?<studentArmorType>[^<]*)(?:<\/td>)/gis.exec(
text
);
const {
groups: { studentCombatClass },
} = /(?:<tr><th>Combat Class<\/th>\s*<td.*?>)(?<studentCombatClass>[^<]*)(?:<\/td>)/gis.exec(
text
);
const studentAffinities = (() => {
let [urban, field, indoors] = [... text.matchAll(/(\w+)(?: grade affinity)/gis)].map(a => a[1]);
return { urban: urban, field: field, indoors: indoors };
})();
/* TO-DO:
* - Change to map
* - Add weapon name
* - Add weapon image
*/
const {
groups: { studentWeaponType },
} = /(?:"weapon-text".*?figcaption>)(?<studentWeaponType>.*?)(?:<\/figcaption>)/gimus.exec(
text
);
const studentUsesCover = /<span title="Uses cover">/imus.test(text);
const studentEquipment = [
... [... text.matchAll(/<td class="equipment equipment-\d" data-value="(.*?)">/gimus)]
.map(equipment => equipment[1])
];
/* Partially implemented.
* Missing:
* - Error handling -- for students without unique gear
* - Equipment stats (heavy use of HTML markup and styling...)
*/
/*
const studentUniqueGear = (() => {
const {
groups: { gearName, icon, descriptionEn, descriptionJp },
} = /"geartable-summary".*?<img.*?src="(?<icon>.*?)".*?"gear-name-main".*?>(?<gearName>.*?)<\/span>.*?"gear-description".*?"English".*?p.*?>(?<descriptionEn>.*?)<\/p>.*?"Japanese".*?p.*?>(?<descriptionJp>.*?)<\/p>/gimus.exec(
text
);
return {
name: gearName,
icon: `https:${icon}`,
description: {
en: descriptionEn,
jp: descriptionJp,
},
};
})();
*/
return {
studentName,
studentRarity,
studentProfileImg: `https://${studentProfileImg}`,
studentSchool,
studentGroup,
studentRole,
studentDamageType,
studentArmorType,
studentCombatClass,
studentAffinities,
studentWeaponType,
studentUsesCover,
studentEquipment,
/* studentUniqueGear, */
};
}
console.log(getStudent());