Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
50 lines (48 loc) · 1.58 KB
/
Copy pathscript.js
File metadata and controls
50 lines (48 loc) · 1.58 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
41
42
43
44
45
46
47
48
49
50
process.env.CHROME_PATH = ""; // The place of Chrome on you system (REQUIRED!)
process.env.NICKJS_PROXY = ""; // NickJS proxy
process.env.http_proxy = ""; // Env proxy
const url = 'https://fontawesome.com/cheatsheet';
const fs = require('fs');
const Nick = require("nickjs")
const nick = new Nick({
headless: false
})
;
(async () => {
const tab = await nick.newTab()
await tab.open(url)
await tab.untilVisible("main") // Make sure we have loaded the page
const iconsList = await tab.evaluate((arg, callback) => {
// Here we're in the page context. It's like being in your browser's inspector tool
var groups = {};
var sections = window.document.getElementsByClassName('cheatsheet-set');
for (const section of sections) {
const names = [];
groups[section.id] = names;
var icons = section.getElementsByClassName('icon');
for (const icon of icons) {
const name = icon.getElementsByTagName('dd')[0].innerText;
if (section.id === 'solid') {
names.push('fas fa-' + name);
} else if (section.id === 'regular') {
names.push('far fa-' + name);
} else if (section.id === 'brands') {
names.push('fab fa-' + name);
}
}
};
callback(null, groups)
})
await fs.writeFileSync('fontawesome.json', JSON.stringify(iconsList, null, 4), (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
})()
.then(() => {
console.log("Json Generated Successfully!")
nick.exit()
})
.catch((err) => {
console.log(`Something went wrong: ${err}`)
nick.exit(1)
})