-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathsplinterlandsPage.js
75 lines (68 loc) · 3.3 KB
/
splinterlandsPage.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
async function login(page, account, password) {
try {
page.waitForSelector('#log_in_button > button').then(() => page.click('#log_in_button > button'))
await page.waitForSelector('#email')
.then(() => page.waitForTimeout(3000))
.then(() => page.focus('#email'))
.then(() => page.type('#email', account))
.then(() => page.focus('#password'))
.then(() => page.type('#password', password))
// .then(() => page.waitForSelector('#login_dialog_v2 > div > div > div.modal-body > div > div > form > div > div.col-sm-offset-1 > button', { visible: true }).then(() => page.click('#login_dialog_v2 > div > div > div.modal-body > div > div > form > div > div.col-sm-offset-1 > button')))
.then(() => page.click("#loginBtn"))
.then(() => page.waitForTimeout(5000))
.then(() => page.reload())
.then(() => page.waitForTimeout(5000))
.then(() => page.reload())
.then(() => page.waitForTimeout(3000))
.then(async () => {
await page.waitForSelector('#log_in_text', {
visible: true, timeout: 3000
})
.then(()=>{
console.log('logged in!')
})
.catch(()=>{
console.log('didnt login');
throw new Error('Didnt login');
})
})
.then(() => page.waitForTimeout(2000))
.then(() => page.reload())
} catch (e) {
throw new Error('Check that you used correctly username and posting key. (dont use email and password)');
}
}
async function checkMana(page) {
var manas = await page.evaluate(() => {
var manaCap = document.querySelectorAll('div.mana-total > span.mana-cap')[0].innerText;
var manaUsed = document.querySelectorAll('div.mana-total > span.mana-used')[0].innerText;
var manaLeft = manaCap - manaUsed
return { manaCap, manaUsed, manaLeft };
});
console.log('manaLimit', manas);
return manas;
}
async function checkMatchMana(page) {
const mana = await page.$$eval("div.mana-cap__icon", el => el.map(x => x.getAttribute("data-original-title")));
const manaValue = parseInt(mana[mana.length -1].split(':')[1], 10);
return manaValue;
}
async function checkMatchRules(page) {
const rules = await page.$$eval("div.combat__rules > div > div > img", el => el.map(x => x.getAttribute("data-original-title")));
return rules.map(x => x.split(':')[0]).join('|')
}
async function checkMatchActiveSplinters(page) {
const splinterUrls = await page.$$eval("div.active_element_list > img", el => el.map(x => x.getAttribute("src")));
return splinterUrls.map(splinter => splinterIsActive(splinter)).filter(x => x);
}
//UNUSED ?
const splinterIsActive = (splinterUrl) => {
const splinter = splinterUrl.split('/').slice(-1)[0].replace('.svg', '').replace('icon_splinter_', '');
return splinter.indexOf('inactive') === -1 ? splinter : '';
}
exports.login = login;
exports.checkMana = checkMana;
exports.checkMatchMana = checkMatchMana;
exports.checkMatchRules = checkMatchRules;
exports.checkMatchActiveSplinters = checkMatchActiveSplinters;
exports.splinterIsActive = splinterIsActive;