-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
141 lines (105 loc) · 3.91 KB
/
util.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
const { Builder, By, Key, until } = require('selenium-webdriver')
const fs = require('fs')
const deepai = require('deepai')
deepai.setApiKey('never_mind');
async function compareImages() {
let res = await deepai.callStandardApi('image-similarity', {
image1: fs.createReadStream("img/captcha.jpeg"),
image2: fs.createReadStream("img/Naruto.jpeg"),
})
if(res.output.distance == 0) return 0
res = await deepai.callStandardApi('image-similarity', {
image1: fs.createReadStream("img/captcha.jpeg"),
image2: fs.createReadStream("img/Sakura.jpeg"),
})
if(res.output.distance == 0) return 1
res = await deepai.callStandardApi('image-similarity', {
image1: fs.createReadStream("img/captcha.jpeg"),
image2: fs.createReadStream("img/Sasuke.jpeg"),
})
if(res.output.distance == 0) return 2
res = await deepai.callStandardApi('image-similarity', {
image1: fs.createReadStream("img/captcha.jpeg"),
image2: fs.createReadStream("img/Kakashi.jpeg"),
})
if(res.output.distance == 0) return 3
}
async function solveCaptcha() {
let driver = this.driver
let captcha = await driver.findElement(By.id('img_captcha'))
let image64 = await captcha.takeScreenshot()
fs.writeFileSync('img/captcha.jpeg', image64, 'base64');
let givenImage = await compareImages()
if(givenImage == 0) await driver.findElement(By.id('teste_resp1')).click()
else if(givenImage == 1) await driver.findElement(By.id('teste_resp2')).click()
else if(givenImage == 2) await driver.findElement(By.id('teste_resp3')).click()
else if(givenImage == 3) await driver.findElement(By.id('teste_resp4')).click()
}
async function getReward(from) {
let driver = this.driver
if(from == 'CaçadaPorTempo') {
try {
let span = await driver.findElement(By.id('receber_m'))
await span.findElement(By.tagName('img')).click()
} catch(e) {
getReward(from)
}
}
else {
try {
let div = await driver.findElement(By.id('relogio_contador'))
await div.click()
} catch(e) {
getReward(from)
}
}
}
async function getRemainingSeconds() {
let driver = this.driver
try {
let time = await driver.findElement(By.id('relogio_contador')).getText()
if(time == 'Caçada concluída!' || time == 'Atualizar!') {
return 0
}
let min = parseInt(time.split(':')[1])
let sec = parseInt(time.split(':')[2])
return ( min * 60 ) + sec
} catch(e) {
return 0
}
}
async function playerWasAttacked() {
let driver = this.driver
let elementsFound = await driver.findElements(
By.xpath("//*[contains(text(), 'Tempo restante de penalidade:')]"))
return elementsFound.length > 0 ? true : false
}
async function isClockOnDOM() {
let driver = this.driver
let elementsFound = await driver.findElements(
By.xpath("//*[contains(text(), 'Tempo restante de caçada:')]"))
return elementsFound.length > 0 ? true : false
}
async function openLoginScreen() {
let driver = this.driver
await driver.get('http://www.narutoplayers.com.br')
let select = await driver.findElement(By.id('servidor'))
let options = await select.findElements(By.tagName('option'))
await options[1].click()
// await driver.findElement(By.id('usuario')).sendKeys('fossatialex', Key.RETURN)
// await driver.findElement(By.id('senha')).sendKeys('this_one_will_not_work', Key.RETURN)
await driver.findElement(By.id('usuario')).sendKeys('alexfossati', Key.RETURN)
await driver.findElement(By.id('senha')).sendKeys('this_neither', Key.RETURN)
await driver.wait(until.urlIs('http://www.narutoplayers.com.br/?p=status'))
}
function init(driver) {
this.driver = driver
}
exports.compareImages = compareImages
exports.solveCaptcha = solveCaptcha
exports.getReward = getReward
exports.getRemainingSeconds = getRemainingSeconds
exports.playerWasAttacked = playerWasAttacked
exports.isClockOnDOM = isClockOnDOM
exports.openLoginScreen = openLoginScreen
exports.init = init