-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodewars-leaderboard.js
More file actions
40 lines (36 loc) · 1 KB
/
Copy pathcodewars-leaderboard.js
File metadata and controls
40 lines (36 loc) · 1 KB
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
/*Codewars Leaderboard
https://www.codewars.com/kata/5a57d101cadebf03d40000b9
*/
const https = require("https");
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const getLeaderboardHonor = async () => {
const url = "https://www.codewars.com/users/leaderboard";
const res = await getData(url);
return res.map((item) => {
return parseInt(item.split(",").join(""));
});
};
const getData = (url) => {
return new Promise((resolve) => {
https.get(url, (res) => {
let response = "";
const kata = [];
let dom;
res.on("data", (data) => {
response += data.toString();
});
res.on("end", (data) => {
dom = new JSDOM(response);
const elements = dom.window.document.querySelectorAll("tr");
elements.forEach((element) => {
const innerHTML = element.lastChild.innerHTML;
if (innerHTML !== "Honor") {
kata.push(element.lastChild.innerHTML);
}
});
resolve(kata);
});
});
});
};