Skip to content

Instantly share code, notes, and snippets.

@diego-mi
Last active August 8, 2022 22:20
Show Gist options
  • Save diego-mi/4920682919fbdd461c4c415cc54d5ac7 to your computer and use it in GitHub Desktop.
Save diego-mi/4920682919fbdd461c4c415cc54d5ac7 to your computer and use it in GitHub Desktop.
TurtRacing - Auto Buy
// ==UserScript==
// @name TurtRacing - Auto Buy
// @namespace https://gist.github.com/diego-mi
// @version 0.3
// @description TurtRacing - Auto Buy
// @author DiegoMi
// @match https://play.turtleracing.io
// @grant none
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
// ESCOLHA UM DA LISTA E COLOQUE O NOME NA VARIAVEL eggToBuy
const youngPoke = 3;
const eggNormal = 4;
const eggNormalYoung = 5;
const eggSSJ3 = 6;
const eggGokuYoung = 10;
const eggKakaTurtle = 12;
const eggMetaTurtle = 13;
const eggVegeTurtle = 14;
// ESCOLHA UM DA LISTA E COLOQUE O NOME NA VARIAVEL eggToBuy
//
//
//
//
// VARIAVEL QUE INFORMA QUAL OVO/TURTLE COMPRAR
const eggToBuy = eggVegeTurtle;
// VARIAVEL QUE INFORMA QUAL OVO/TURTLE COMPRAR
//
//
//
//
//
//
//
//
//
// VARIAVEL QUE INFORMA >>>QUANTOS<<< COMPRAR
const eggsCountToBuy = 5;
// VARIAVEL QUE INFORMA >>>QUANTOS<<< COMPRAR
//
//
//
//
//
const eggSelector = `#myBox2 > div.container > div:nth-child(${eggToBuy})`;
const okConfirmationModal = `#myBox2 > div.modalcontainer > div > div > div.buttons > a:nth-child(2)`;
const buyConfirmed = `#myBox2 > div.modalcontainer > div > div > div.button2 > a`;
/**
* HELPERS
*/
async function WaitForElement(selector) {
while (document.querySelector(selector) === null) {
await new Promise( resolve => requestAnimationFrame(resolve) )
}
await new Promise(resolve => setTimeout(resolve, 100));
return document.querySelector(selector);
}
async function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
const clickEggToBuy = () => {
document.querySelector(eggSelector).click();
}
const waitForModalConfirmationToBuy = async () => {
await WaitForElement(okConfirmationModal)
}
const doBuyInModal = () => {
document.querySelector(okConfirmationModal).click();
}
const waitForModalBuyConfirmed = async () => {
await WaitForElement(buyConfirmed);
}
const confirmedBuy = async () => {
document.querySelector(buyConfirmed).click();
}
/**
* INICIALIZACAO
*/
async function Init() {
await WaitForElement(eggSelector);
console.log('init buy');
for(var index = 0; index < eggsCountToBuy; index++) {
clickEggToBuy();
await waitForModalConfirmationToBuy();
doBuyInModal();
await waitForModalBuyConfirmed();
confirmedBuy()
await delay(1000);
}
}
Init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment