-
Notifications
You must be signed in to change notification settings - Fork 3
/
activate.js
102 lines (78 loc) · 2.5 KB
/
activate.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
const puppeteer = require('puppeteer')
const fs = require('fs')
;(async () => {
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
})
const page = await browser.newPage()
const downloadPath = process.cwd()
const client = await page.target().createCDPSession()
await client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: downloadPath
})
const navigationPromise = page.waitForNavigation({
waitUntil: 'domcontentloaded'
})
await page.goto('https://license.unity3d.com/manual')
await Promise.all([
await navigationPromise,
await page.waitForSelector('#new_conversations_create_session_form #conversations_create_session_form_password')
])
const email = `${process.argv[2]}`
await page.type('input[type=email]', email)
const password = `${process.argv[3]}`
await page.type('input[type=password]', password)
await page.click('input[name="commit"]')
await navigationPromise
const confirmNumber = `${process.argv[5]}`
if (
confirmNumber.value != null &&
confirmNumber.value != undefined &&
confirmNumber.value.length > 0
) {
await page.waitFor(1000)
await page.type('input[class="verify_code"]', confirmNumber)
await page.click('input[type=submit]')
await navigationPromise
}
const licenseFile = 'input[name="licenseFile"]'
await page.waitFor(10000)
const input = await page.$(licenseFile)
const alfPath = `${process.argv[4]}`
await input.uploadFile(alfPath)
await page.click('input[name="commit"]')
await navigationPromise
const selectedTypePersonal = 'input[id="type_personal"][value="personal"]'
await page.waitForSelector(selectedTypePersonal)
await page.evaluate(
s => document.querySelector(s).click(),
selectedTypePersonal
)
const selectedPersonalCapacity = 'input[id="option3"][name="personal_capacity"]'
await page.evaluate(
s => document.querySelector(s).click(),
selectedPersonalCapacity
)
await page.click('input[class="btn mb10"]')
await Promise.all([
await navigationPromise,
await page.waitFor(1000)
])
await page.click('input[name="commit"]')
let _ = await (async () => {
let ulf
do {
for (const file of fs.readdirSync(downloadPath)) {
ulf |= file.endsWith('.ulf')
}
await sleep(1000)
} while (!ulf)
})()
function sleep(milliSeconds) {
return new Promise((resolve, reject) => {
setTimeout(resolve, milliSeconds)
})
}
await browser.close()
})()