mirror of
https://github.com/maxswa/osrs-json-hiscores.git
synced 2025-10-15 10:19:04 +00:00
Fix getRSNFormat
This commit is contained in:
1336
__tests__/attackTopPage.html
vendored
1336
__tests__/attackTopPage.html
vendored
File diff suppressed because it is too large
Load Diff
1400
__tests__/b0atyNamePage.html
vendored
1400
__tests__/b0atyNamePage.html
vendored
File diff suppressed because it is too large
Load Diff
1337
__tests__/lynxTitanNamePage.html
vendored
1337
__tests__/lynxTitanNamePage.html
vendored
File diff suppressed because it is too large
Load Diff
@@ -50,12 +50,11 @@ export async function getRSNFormat(rsn: string): Promise<string> {
|
|||||||
try {
|
try {
|
||||||
const response = await httpGet(url);
|
const response = await httpGet(url);
|
||||||
const dom = new JSDOM(response.data);
|
const dom = new JSDOM(response.data);
|
||||||
const spans = dom.window.document.querySelectorAll(
|
const anchor = dom.window.document.querySelector(
|
||||||
'span[style="color:#AA0022;"]'
|
'.personal-hiscores__row.personal-hiscores__row--type-highlight a'
|
||||||
);
|
);
|
||||||
if (spans.length >= 2) {
|
if (anchor) {
|
||||||
const nameSpan = spans[1];
|
return rsnFromElement(anchor);
|
||||||
return rsnFromElement(nameSpan);
|
|
||||||
}
|
}
|
||||||
throw Error('Player not found');
|
throw Error('Player not found');
|
||||||
} catch {
|
} catch {
|
||||||
@@ -75,7 +74,10 @@ export function parseStats(csv: string): Stats {
|
|||||||
.filter((entry) => !!entry)
|
.filter((entry) => !!entry)
|
||||||
.map((stat) => stat.split(','));
|
.map((stat) => stat.split(','));
|
||||||
|
|
||||||
if (splitCSV.length !== SKILLS.length + BH_MODES.length + CLUES.length + BOSSES.length + 5) {
|
if (
|
||||||
|
splitCSV.length !==
|
||||||
|
SKILLS.length + BH_MODES.length + CLUES.length + BOSSES.length + 5
|
||||||
|
) {
|
||||||
throw Error(INVALID_FORMAT_ERROR);
|
throw Error(INVALID_FORMAT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +107,12 @@ export function parseStats(csv: string): Stats {
|
|||||||
const [leaguePoints] = activityObjects.splice(0, 1);
|
const [leaguePoints] = activityObjects.splice(0, 1);
|
||||||
const bhObjects = activityObjects.splice(0, BH_MODES.length);
|
const bhObjects = activityObjects.splice(0, BH_MODES.length);
|
||||||
const clueObjects = activityObjects.splice(0, CLUES.length);
|
const clueObjects = activityObjects.splice(0, CLUES.length);
|
||||||
const [lastManStanding, pvpArena, soulWarsZeal, riftsClosed] = activityObjects.splice(0, 4);
|
const [
|
||||||
|
lastManStanding,
|
||||||
|
pvpArena,
|
||||||
|
soulWarsZeal,
|
||||||
|
riftsClosed
|
||||||
|
] = activityObjects.splice(0, 4);
|
||||||
const bossObjects = activityObjects.splice(0, BOSSES.length);
|
const bossObjects = activityObjects.splice(0, BOSSES.length);
|
||||||
|
|
||||||
const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => {
|
const skills: Skills = skillObjects.reduce<Skills>((prev, curr, index) => {
|
||||||
|
Reference in New Issue
Block a user