-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
33 lines (27 loc) · 1.04 KB
/
app.js
File metadata and controls
33 lines (27 loc) · 1.04 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
const fs = require('fs');
const { JSDOM } = require("jsdom");
const file = fs.readFileSync('./Hideouts.json', 'utf-8');
const { data } = JSON.parse(file.toString());
const HIDEOUT = data.map(d => {
const dom = new JSDOM(d);
const Icon = dom.window.document.querySelector('img').getAttribute('src');
const CName = dom.window.document.querySelector('a').textContent
.replace(/\[.*?\]/g, '')
.replace(/\s+/g, '');
const Name = dom.window.document.querySelector('a').getAttribute('href')
.replace('area.php?n=', '')
.replace(/\+/g, ' ')
.replace('%27', "'")
.replace('/cn/', '')
.replace('/tw/', '')
// TODO: replace other locale
return { CName, Name, Icon };
});
// https://stackoverflow.com/questions/54207701/write-json-content-in-json-format-to-a-new-file-in-node-js
const writeFile = `
{
"data": ${JSON.stringify(HIDEOUT, null, ' ').replace(/^ +/gm, '').replace(/: "(?:[^"]+|\\")*",?$/gm, ' $&')}
}
`
fs.writeFileSync('HideoutsParse.json', writeFile);
console.log('Success');