This repository has been archived by the owner on Aug 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
144 lines (121 loc) · 4.36 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
const config = require('config');
const puppeteer = require('puppeteer-extra');
const RecaptchaPlugin = require('puppeteer-extra-plugin-recaptcha')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(
RecaptchaPlugin({
provider: {
id: '2captcha',
token: 'f804e7fb453a6117f3df546b9aaa054d' // REPLACE THIS WITH YOUR OWN 2CAPTCHA API KEY ⚡
},
visualFeedback: true // colorize reCAPTCHAs (violet = detected, green = solved)
}),
StealthPlugin()
)
const sites = config.get('sites');
const singleMode = config.get('singleMode');
const playerName = config.get('playerName');
const reCaptchaExtensionPath = require('path').join(__dirname, 'extensions/reCaptch-solver');
var extensionBackgroundPage;
const chromeSettings = {
executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
headless: false,
args: [
`--disable-extensions-except=${reCaptchaExtensionPath}`,
`--load-extension=${reCaptchaExtensionPath}`
// '--user-data-dir=C:\\users\\Loai Arkam\\AppData\\Local\\Chrome'
// `--proxy-server= http://159.203.44.118:8080`
]
};
(async () => {
const browser = await puppeteer.launch(chromeSettings)
const targets = await browser.targets();
const extensionBackgroundTarget = targets.find(target => target.type() === 'background_page');
extensionBackgroundPage = await extensionBackgroundTarget.page();
extensionBackgroundPage.evaluate(settings => {
setOptions(settings);
}, config.get('captcha'))
for (let index = 2; index < sites.length; index++) {
singleMode ? await vote(browser, sites[index]) : vote(browser, sites[index]);
}
})();
async function vote(browser, site) {
return new Promise(function (resolve, reject) {
var page;
newPage(browser, site)
.then(result => page = result)
.then(_ => sleep(500))
.then(_ => inputName(page, site))
.then(_ => sleep(500))
.then(_ => selectOptions(page, site))
.then(_ => sleep(500))
.then(_ => solveCaptcha(page))
.then(_ => sleep(500))
//.then(_ => resolve(page))
.catch(error => console.log(error))
})
}
async function newPage(browser, site) {
var page;
return new Promise(function (resolve, reject) {
browser.newPage()
.then(result => {
page = result;
return Promise.all([
page.waitForNavigation({ timeout: 120000 }),
page.waitForSelector(site.inputSelector, { timeout: 120000 }),
page.goto(site.url, { timeout: 120000 }),
])
})
.then(_ => resolve(page))
.catch(error => reject(error))
})
}
async function inputName(page, site) {
var inputField;
return new Promise(function (resolve, reject) {
page.$(site.inputSelector)
.then(result => inputField = result)
.then(_ => inputField.click())
.then(_ => sleep(500))
.then(_ => site.clearText ? clearText(inputField, page) : inputField)
.then(_ => inputField.type(playerName, { delay: 200 }))
.then(_ => resolve(page))
.catch(error => reject(error))
})
}
async function selectOptions(page, site) {
var selectInput;
return new Promise(function (resolve, reject) {
if (site.select) {
page.$(site.select)
.then(result => selectInput = result)
.then(_ => selectInput.click())
.then(resolve())
.catch(error => reject(error))
}
else {
resolve()
}
})
}
async function solveCaptcha(page) {
console.log("solving")
}
function sleep(duration, value) {
value = value || true;
//console.log("sleeping")
return new Promise(function (resolve, reject) {
setTimeout(() => resolve(value), duration);
})
}
async function clearText(element, page) {
return new Promise(function (resolve, reject) {
page.keyboard.down('Shift')
.then(_ => page.keyboard.press('KeyA'))
.then(_ => page.keyboard.up('Shift'))
.then(_ => page.keyboard.press('Backspace'))
.then(_ => resolve(element))
.catch(error => reject(error))
})
}