forked from DanielHe4rt/bbbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
112 lines (101 loc) · 3.2 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
if (process.argv.length < 4) {
console.log("Como usar: node index.js usuario@usuario.com senha");
return false;
}
const puppeteer = require("puppeteer");
const configs = require("./config");
const fs = require("fs");
let voteCounter = 0;
const { installMouseHelper } = require("./mouseHelper");
const {
refreshCaptcha,
clickXPath,
scrollToTop,
resolveImages,
revote,
removeSponsor
} = require("./helper");
(async () => {
const browser = await puppeteer.launch({
headless: false,
defaultViewport: null,
args: ["--window-size=200,1000"]
});
const page = await browser.newPage();
await installMouseHelper(page);
await page.goto(configs.links.globoLoginUrl, {
waitUntil: "networkidle2"
});
if (process.argv[4] === "login") {
await page.waitForNavigation();
}
await page.type("#login", process.argv[2]);
await page.type("#password", process.argv[3]);
await page.click("[class='button ng-scope']");
await page.waitForNavigation();
await page.goto(configs.links.paredaoUrl, {
waitUntil: "networkidle2"
});
await removeSponsor(page);
await page.waitForXPath(configs.xpaths.user).then(async () => {
await clickXPath(page, configs.xpaths.user);
});
await page.waitForXPath(configs.xpaths.buttonCaptcha).then(async () => {
await clickXPath(page, configs.xpaths.buttonCaptcha);
});
await page.waitForXPath(configs.xpaths.imgCaptcha).then(async () => {
let handler = await page.$x(configs.xpaths.imgCaptcha);
setTimeout(() => {
handler[0].focus();
}, 1000);
});
// Aqui começa a palhaçada dos hooks
page.on("response", async response => {
let calcPosition;
let hookUrl = response.url();
let request = response.request();
let status = response.status();
if (
hookUrl.startsWith(configs.links.challengeAccepted) &&
parseInt(response.status()) === 200 &&
request.method() === "POST"
) {
voteCounter++;
console.log("Votos computados: " + voteCounter);
await revote(page);
}
if (
hookUrl.startsWith(configs.links.challengeAccepted) &&
parseInt(response.status()) >= 403 &&
request.method() === "POST"
) {
console.log("Voto não computado =/");
await page.waitForXPath(configs.xpaths.buttonCaptcha).then(async () => {
await clickXPath(page, configs.xpaths.buttonCaptcha);
});
}
if (hookUrl.startsWith(configs.links.challengeUrl)) {
let res = await response.json();
let { symbol, image } = res.data;
if (symbol === "mochila") {
fs.writeFileSync("alo.png", image, "base64");
calcPosition = await resolveImages();
await setTimeout(async () => {
if (!calcPosition) {
await refreshCaptcha(page, configs.xpaths.buttonCaptcha);
return false;
}
let finalPosition = 100 + calcPosition[0] + 30 * 1.5;
calcPosition = false;
await scrollToTop(page);
await page.mouse.move(finalPosition, 555);
setTimeout(async () => {
await page.mouse.click(finalPosition, 550);
}, 1000);
}, 2300);
} else {
await refreshCaptcha(page, configs.xpaths.buttonCaptcha);
}
}
});
})();