-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
160 lines (127 loc) · 3.58 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const { Downloader } = require('./src/downloader')
const puppeteer = require('puppeteer')
const prompts = require('prompts')
const fs = require('fs')
/**
* This is really just hacked together
*/
(async () => {
const dir = 'output'
const downloader = new Downloader()
let systems = await downloader.load()
let choices = [
{
title: 'ALL',
value: 'ALL',
}
]
for (const systemKey in systems) {
choices.push({
title: systemKey,
value: systemKey,
})
}
choices = choices.sort((a, b) => {
return a.title.localeCompare(b.title)
})
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir)
}
const response = await prompts([
{
type: 'multiselect',
name: 'systems',
message: 'Systems to screenshot.',
choices: choices,
},
{
type: 'select',
name: 'filetype',
message: 'Screenshot filetype',
choices: [
{ title: 'JPEG', value: 'jpg' },
{ title: 'PNG', value: 'png', selected: true },
],
},
])
if (typeof response.systems !== 'undefined' && !response.systems.includes('ALL')) {
let filteredSystems = []
for (const systemKey in systems) {
if (response.systems.includes(systemKey)) {
filteredSystems[systemKey] = systems[systemKey]
}
}
systems = filteredSystems
}
const browser = await puppeteer.launch({
headless: false,
})
const page = await browser.newPage()
await page.setViewport({
width: 1920,
height: 1080
})
for (let systemCode in systems) {
let patchedCode = systemCode
if (patchedCode === 'NUL') {
patchedCode = '_' + patchedCode
}
patchedCode = patchedCode.replace('\'', '')
if (!fs.existsSync('./' + dir + '/' + patchedCode)) {
fs.mkdirSync('./' + dir + '/' + patchedCode)
}
let exists = false
for (const code in systems[systemCode]) {
console.log('Accesing ' + systems[systemCode][code])
let filename = systems[systemCode][code] + '.' + response.filetype
if (filename.substr(0, 3) === 'NUL') {
filename = '_' + filename
}
filename = filename.replace('\'', '')
let path = './' + dir + '/' + patchedCode + '/' + filename
await fs.stat(path, (err, stats) => {
if (err && err.code === 'ENOENT') {
exists = false
return
}
exists = stats.isFile()
})
if (exists) {
console.log(systems[systemCode][code] + ' already downloaded.')
continue
}
await page.goto('https://robertsspaceindustries.com/starmap?location=' + systems[systemCode][code] + '&system=' + systemCode)
await page.waitForSelector('.launch', {
visible: true,
})
await page.click('.launch')
await page.waitForSelector('.sm-acknowledge', {
visible: true,
})
await page.waitForSelector('label[for="sm-dont-show-acknowledgment"]', {
visible: true,
})
await page.click('.sm-acknowledge')
page.$('#sm-header-region').then(value => {
value.evaluate((node) => {
node.style.display = 'none'
})
})
page.$('#sm-controls-region').then(value => {
value.evaluate((node) => {
node.style.display = 'none'
})
})
await page.waitForSelector('.sm-continue', {
visible: true,
})
await page.waitForSelector('label[for="sm-dont-show-info"]', {
visible: true,
})
await page.click('.sm-continue')
await page.waitForTimeout(3900)
await page.screenshot({ path: path })
}
}
await browser.close()
})()