1 Star 7 Fork 0

黑洞 / autoscripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.js 18.24 KB
一键复制 编辑 原始数据 按行查看 历史
黑洞 提交于 2021-12-30 03:05 . update
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
const i18n = require('i18n')
const path = require('path')
const axios = require('axios')
const prompts = require('prompts')
const puppeteer = require('puppeteer-extra')
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
const { osLocale } = require('os-locale-s-fix')
require('puppeteer-extra-plugin-stealth/evasions/chrome.app')
require('puppeteer-extra-plugin-stealth/evasions/chrome.csi')
require('puppeteer-extra-plugin-stealth/evasions/chrome.loadTimes')
require('puppeteer-extra-plugin-stealth/evasions/chrome.runtime')
require('puppeteer-extra-plugin-stealth/evasions/iframe.contentWindow')
require('puppeteer-extra-plugin-stealth/evasions/media.codecs')
require('puppeteer-extra-plugin-stealth/evasions/navigator.hardwareConcurrency')
require('puppeteer-extra-plugin-stealth/evasions/navigator.languages')
require('puppeteer-extra-plugin-stealth/evasions/navigator.permissions')
require('puppeteer-extra-plugin-stealth/evasions/navigator.plugins')
require('puppeteer-extra-plugin-stealth/evasions/navigator.vendor')
require('puppeteer-extra-plugin-stealth/evasions/navigator.webdriver')
require('puppeteer-extra-plugin-stealth/evasions/sourceurl')
require('puppeteer-extra-plugin-stealth/evasions/user-agent-override')
require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor')
require('puppeteer-extra-plugin-stealth/evasions/window.outerdimensions')
require('puppeteer-extra-plugin-stealth/evasions/defaultArgs')
const s = (ss) =>
new Promise((res, rej) => {
setTimeout(res, ss * 1000)
})
const s10 = () =>
new Promise((res, rej) => {
return setTimeout(res, 10 * 1000)
})
const s30 = () =>
new Promise((res, rej) => {
return setTimeout(res, 30 * 1000)
})
function randomNum(minNum, maxNum) {
switch (arguments.length) {
case 1:
return parseInt(Math.random() * minNum + 1, 10)
break
case 2:
return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10)
break
default:
return 0
break
}
}
Date.prototype.format = function (fmt) {
var o = {
'M+': this.getMonth() + 1,
'd+': this.getDate(),
'h+': this.getHours(),
'm+': this.getMinutes(),
's+': this.getSeconds(),
'q+': Math.floor((this.getMonth() + 3) / 3),
S: this.getMilliseconds(),
}
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length))
}
for (var k in o) {
if (new RegExp('(' + k + ')').test(fmt)) {
fmt = fmt.replace(
RegExp.$1,
RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
)
}
}
return fmt
}
const maxenergy = 0 // You can set the to 150
let serverurl = 'https://api.waxsweden.org'
// 'https://api.waxsweden.org/v1/chain/get_table_rows'
// 'https://api.wax.alohaeos.com/v1/chain/get_table_rows'
async function play(account, pos, module, salelist) {
let browser = null
const position = pos * 150
const DefaultTimeout = 90 * 1000
try {
puppeteer.use(StealthPlugin())
const params = {
headless: false,
args: [
// "--proxy-server='direct://'",
// '--proxy-bypass-list=*',
'--ignore-certificate-errors',
'--no-sandbox',
'--disable-infobars',
'--disable-setuid-sandbox',
`--window-position=${position * 2},${position}`,
'--window-size=1300,900',
],
ignoreHTTPSErrors: true,
timeout: DefaultTimeout,
userDataDir: './tmp/' + account,
}
if (process.pkg) {
if (process.platform === 'darwin') {
// for macos
const puppeteerexec = path.resolve(
path.dirname(process.execPath),
'Chromium.app/Contents/MacOS/Chromium'
)
params.executablePath = puppeteerexec
params.userDataDir = path.resolve(path.dirname(process.execPath), 'tmp', account)
} else if (
process.platform === 'win32' ||
process.env.OSTYPE === 'cygwin' ||
process.env.OSTYPE === 'msys'
) {
// for win
const puppeteerexec = path.resolve(process.cwd(), 'chrome-win', 'chrome.exe')
params.executablePath = puppeteerexec
params.userDataDir = path.resolve(path.dirname(process.execPath), 'tmp', account)
} else {
// linux
const puppeteerexec = path.resolve(path.dirname(process.execPath), 'chrome-linux/chrome')
params.executablePath = puppeteerexec
params.userDataDir = path.resolve(path.dirname(process.execPath), 'tmp', account)
}
}
browser = await puppeteer.launch(params)
const page = await browser.newPage()
await page.setDefaultTimeout(DefaultTimeout)
await page.setViewport({ width: 1280, height: 768 })
page.on('console', (consoleObj) => {
if (consoleObj.text().indexOf('inner-') === 0) {
const key = consoleObj.text().replace('inner-', '')
console.log(i18n.__(key), new Date().format(' yyyy-MM-dd hh:mm:ss'))
// } else {
// console.log(consoleObj.text())
}
})
const loginURL = 'https://play.farmersworld.io/'
await page.goto(loginURL, { waitUntil: 'networkidle0' })
await page.waitForSelector('button.login-button')
console.log(i18n.__('Login Page Load'), new Date().format(' yyyy-MM-dd hh:mm:ss'))
// select server
const serverlist = await page.$$eval('#RPC-Endpoint option', (options) =>
options.map((option) => option.text)
)
const selectcount = serverlist.length
const selectid = randomNum(0, selectcount - 2)
serverurl = serverlist[selectid + 1]
console.log('select server : ', selectid, selectcount, serverurl)
await page.waitForTimeout(2000)
page.select('#RPC-Endpoint', '' + selectid)
await page.waitForTimeout(2000)
await page.click('button.login-button')
await page.waitForTimeout(2000)
await page.click('img[alt="wax-cloud-wallet"]')
await page.waitForSelector('div.container__header--tilte')
console.log(i18n.__('Login Success'), new Date().format(' yyyy-MM-dd hh:mm:ss'))
await page.waitForTimeout(5000)
await page.click('div.game-container')
while (true) {
if (module.includes('1')) {
await selected(page, 'home-map')
if (await checkMing(page)) {
await click(page, account, 'Mine')
await click(page, account, 'Claim')
await click(page, account, 'Repair')
await energy(page, account)
} else {
process.stdout.write(
account + i18n.__('Not Mine') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
}
}
if (module.includes('2')) {
await selected(page, 'chicken-map')
if (await checkMapTitle(page)) {
await click(page, account, 'Feed', 3)
await click(page, account, 'Hatch', 3)
await energy(page, account)
} else {
await home(page)
process.stdout.write(
account + i18n.__('Not Chicken') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
}
}
if (module.includes('3')) {
await selected(page, 'crop-map')
if (await checkMapTitle(page)) {
await click(page, account, 'Water', 8)
await energy(page, account)
} else {
await home(page)
process.stdout.write(
account + i18n.__('Not Crop') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
}
}
if (module.includes('4')) {
await selected(page, 'cow-map')
if (await checkMapTitle(page)) {
await click(page, account, 'Feed', 2)
await energy(page, account)
} else {
await home(page)
process.stdout.write(
account + i18n.__('Not Cow') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
}
}
if (module.includes('5')) {
await build(page)
await energy(page, account)
}
if (module.includes('6') && salelist) {
const list = salelist.includes('-') ? salelist.split('-') : [salelist]
for (const title of list) {
await sale(page, title)
await home(page)
}
}
await s10()
}
} catch (err) {
console.log(`❌ Error: ${err}`)
} finally {
await browser.close()
}
}
async function checkMing(page) {
let empty = await page.$('.empty-container')
return !empty
}
async function checkMapTitle(page) {
let title = await page.$('.modal-map-title')
return !title
}
async function checkCPU(page, title) {
try {
let checklist = [
page.waitForSelector('.modal-stake-header'),
page.waitForSelector('.modal__button-group>.button-section'),
// page.waitForSelector('.close-modal'),
page.waitForFunction(() => {
var msg = document.querySelector('div.flash-message-content')
if (msg) {
return msg.innerText.includes('successful')
}
return false
}),
page.waitForFunction(async () => {
var msg = document.querySelector('div.flash-message-content')
if (msg) {
if (msg.innerText.includes('Repairing')) {
await new Promise((resolve, reject) => setTimeout(resolve, 3000))
return true
}
}
return false
}),
page.waitForFunction(() => {
var msg = document.querySelector('div.flash-message-content')
if (msg) {
return msg.innerText.includes('Eating')
}
return false
}),
]
let champion = await Promise.race(checklist)
await s(2)
if (champion) {
if (champion.constructor.name === 'ElementHandle') {
const stake = await champion.evaluate((node) => node.getAttribute('class'))
if ('modal-stake-header' === stake) {
const close_modal = await page.waitForSelector('.close-modal')
await close_modal.click()
} else {
champion.click()
}
}
console.log(i18n.__(title), new Date().format(' yyyy-MM-dd hh:mm:ss'))
await page.click('div.game-container')
}
await s(2)
} catch (e) {
console.log('🚫', e)
}
}
async function selected(page, title) {
await page.$$eval('div.navbar-group--tilte', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Map')) {
await elem.click()
}
}
})
await s(1)
await page.$$eval(
'.map-container-bg',
async (element, title) => {
for (const elem of element) {
if (elem.style['background-image'].includes(title)) {
await elem.click()
}
}
},
title
)
await s(2)
}
// async function wear(page, title) {
// const wearList = [
// {k: 'barley seed',v: 'crops'},
// {k: 'corn seed',v: 'crops'},
// {k: '',v: 'crops'},
// ]
// const data = {
// json: true,
// code: 'farmersworld',
// scope: 'farmersworld',
// table: 'crops',
// lower_bound: '.auyk.wam',
// upper_bound: '.auyk.wam',
// index_position: 2,
// key_type: 'i64',
// limit: '100',
// reverse: false,
// show_payer: false,
// }
// const res = await axios.post('https://wax.pink.gg/v1/chain/get_table_rows', data, {
// timeout: 90 * 1000,
// })
// // const res = await axios.post('https://api.waxsweden.org/v1/chain/get_table_rows', data)
// // const res = await axios.post('https://api.wax.alohaeos.com/v1/chain/get_table_rows', data)
// if (res.status === 200) {
// const json = res.data
// }
// }
async function sale(page, title) {
title = title.toLowerCase()
// console.log(title)
await page.$$eval('div.navbar-group--tilte', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Chest')) {
await elem.click()
}
}
})
await s(1)
let loop = true
while (loop) {
const isClick = await page.$$eval(
'div.card-container',
async (element, title) => {
for (const elem of element) {
const text = elem.innerText.toLowerCase()
if (text.includes(title)) {
let countText = text.split(title)[0]
let count = parseInt(countText)
if (count > 0) {
console.log('inner-✅售卖第' + count + '' + title)
const buts = await elem.querySelectorAll('button.button-section')
for (const but of buts) {
if (but.innerText.toLowerCase().includes('exchange')) {
but.click()
return true
}
}
}
}
}
return false
},
title
)
if (isClick) {
await checkCPU(page, title + ' Success')
}
loop = isClick
}
await s(1)
}
async function home(page) {
let isClick3 = await page.$$eval('div.navbar-group--tilte', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Home')) {
await elem.click()
return true
}
}
return false
})
await page.waitForTimeout(1000)
}
async function build(page) {
let isClick = await page.$$eval('div.navbar-group--tilte', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Map')) {
await elem.click()
return true
}
}
return false
})
await s(2)
let isClick2 = await page.$$eval('div.plain-button', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Build')) {
console.log('inner-Build Plant')
await elem.click()
return true
}
}
return false
})
if (isClick2) {
isMint = true
await s(10)
}
await s(2)
let isClick3 = await page.$$eval('div.navbar-group--tilte', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Home')) {
await elem.click()
return true
}
}
return false
})
}
//
async function energy(page, account) {
try {
isMint = false
process.stdout.write(
account + i18n.__('Energy Check') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
const data = {
json: true,
code: 'farmersworld',
scope: 'farmersworld',
table: 'accounts',
lower_bound: account,
upper_bound: account,
index_position: 1,
key_type: 'i64',
limit: '100',
}
const res = await axios.post(serverurl + '/v1/chain/get_table_rows', data, {
timeout: 90 * 1000,
})
if (res.status === 200) {
const json = res.data
let last = json['rows'][0]['max_energy'] - json['rows'][0]['energy']
let balances = json['rows'][0].balances
let FOOD = 0
for (const bal of balances) {
if (bal.includes('FOOD')) {
const temparr = bal.split(' ')
if (temparr && temparr.length > 0) {
FOOD = parseInt(temparr[0])
}
}
}
if (maxenergy) {
last = maxenergy - json['rows'][0]['energy']
}
if (last > parseInt(FOOD * 5)) {
last = parseInt(FOOD * 5)
}
if (last > 0) {
console.log(i18n.__('Energy', last), new Date().format(' yyyy-MM-dd hh:mm:ss'))
await page.click('img.resource-energy--plus[alt="plus"]')
await page.waitForTimeout(2000)
await page.type('input.modal-input', last + '')
await page.waitForTimeout(2000)
let isClick = await page.$$eval('button.button-section', async (element) => {
for (const elem of element) {
if (elem.innerText.includes('Exchange')) {
await elem.click()
return true
}
}
return false
})
if (isClick) {
await checkCPU(page, 'Energy Success')
await s(2)
}
await page.click('div.game-container')
}
}
} catch (error) {
console.log(error.toString())
}
}
async function click(page, account, title, count = 24) {
process.stdout.write(
account + i18n.__('Check') + new Date().format(' yyyy-MM-dd hh:mm:ss') + '\r'
)
for (let index = 0; index < count; index++) {
const tools = await page.$('img[alt="' + index + '"]')
if (tools) {
await page.click('img[alt="' + index + '"]')
await page.waitForTimeout(1500)
var timeout = await page.$eval('.info-time .card-container--time', (card) => card.innerText)
if (count > 9 || timeout == '00:00:00') {
let isClick = await page.$$eval(
'div.plain-button',
(elements, title) => {
for (const ele of elements) {
if (ele.innerText.includes(title) && !ele.className.includes('disabled')) {
console.log('inner-' + title)
ele.click()
return true
}
}
return false
},
title
)
if (isClick) {
await checkCPU(page, title + ' Success')
}
}
}
}
}
;(async () => {
try {
i18n.configure({
locales: ['en', 'zh'],
directory: path.join(__dirname, 'locales'),
})
const language = await osLocale()
if (language && language.length > 2) {
i18n.setLocale(language.substring(0, 2))
}
const args = process.argv.splice(2)
let account = args[0] || ''
const position = Number(args[1] || 0)
let module = args[2]
let salelist = args[3] || ''
if (!account) {
const response = await prompts({
type: 'text',
name: 'account',
message: i18n.__('Enter your wallet account:'),
validate: (value) => {
if (value.includes('.wam')) {
return true
}
if (/[a-z1-5]{12}/.test(value)) {
return true
}
return i18n.__('Invalid wallet account %s', value)
},
})
account = response.account
}
if (!module) {
const response = await prompts({
type: 'text',
name: 'module',
message: i18n.__(
'请选择你要使用的模块,可以多选? /1=挖矿mined /2=养鸡chicken /3=种地farming /4=养牛cow /5=建造:'
),
})
module = response.module
}
module = module || '12345'
while (true) {
try {
if (account) {
console.log(i18n.__('Waiting'))
await play(account, position, module, salelist)
}
} catch (error) {
console.log(i18n.__('Offline'), new Date().format(' yyyy-MM-dd hh:mm:ss'))
await s30()
}
}
} catch (error) {
console.log(error)
await s10()
}
})()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/romejiang/autoscripts.git
git@gitee.com:romejiang/autoscripts.git
romejiang
autoscripts
autoscripts
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891