-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcroquignoleur.js
84 lines (65 loc) · 2.08 KB
/
croquignoleur.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
import fetch from "node-fetch";
const https = require("https");
const BASE_URL = "https://croquignoleur.fr/";
const httpsAgent = new https.Agent({
rejectUnauthorized: false,
});
const getBoxList = async (query = "") => {
const content = await fetch(
"https://croquignoleur.fr/index?page=flyff-boite",
{
agent: httpsAgent,
}
);
const html = await content.text();
const regexBox = new RegExp("<option value='(.*?)'>", "gm");
let match = regexBox.exec(html);
let results = [];
while (match != null) {
if (match[1].toLowerCase().includes(query.toLowerCase())) {
match[1] = match[1].replace(/'/g, "'");
results.push(match[1]);
}
match = regexBox.exec(html);
}
return results.map(name => ({
name,
url: getBoxLink(name),
}));
};
const getBoxLink = name => {
const slugifiedName = encodeURI(name);
return `https://croquignoleur.fr/index?page=flyff-boite&boite=${slugifiedName}`;
};
const getBoxContent = async name => {
const content = await fetch(getBoxLink(name), {
agent: httpsAgent,
});
const html = await content.text();
const regexBox = new RegExp(
"<div class='ligne_objet_boite'>.*?<img src='(.*?)'.*?<div class='name'>(.*?)<\/div>.*?<div class='description'>(.*?)<\/div>.*?<div class='obtention'>(<em>(.*?)<\/em>|<b>(.*?)%<\/b>.*?)*?<\/div>",
"gm"
);
let match = regexBox.exec(html);
let results = [];
while (match != null) {
let title = match[2];
let link = null;
const regexLink = new RegExp("<a href='(.*?)'>(.*?)</a>", "gm");
let matchLink = regexLink.exec(title);
if (matchLink) {
link = encodeURI(BASE_URL + matchLink[1]);
title = matchLink[2];
}
results.push({
img: BASE_URL + match[1],
title: title.replace(/<[^>]*>?/gm, ''),
description: match[3] == "0" || !match[3].length ? "*Aucune description*" : match[3].replace(/<[^>]*>?/gm, ''),
link: link,
probability: match[6] ? parseFloat(match[6]) : null,
});
match = regexBox.exec(html);
}
return results;
};
export { getBoxContent, getBoxList, getBoxLink };