Skip to content

Instantly share code, notes, and snippets.

@diego-mi
Last active July 3, 2022 02:14
Show Gist options
  • Save diego-mi/fd24ae8f9fba9a2c5058fe9892f86f9c to your computer and use it in GitHub Desktop.
Save diego-mi/fd24ae8f9fba9a2c5058fe9892f86f9c to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Rabbits Revenge Farm Monitor
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://play.rabbitsrevenge.io
// @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.js
// @grant none
// ==/UserScript==
(function() {
'use strict';
let landsCardsElements = null;
let loaded = 0;
let workingDates = [];
let landFarms = [];
let dateStarted = Date.now();
let farm = 0;
const QuerySelector_StartElement = '.card-land';
async function delay(time) {
return new Promise(resolve => setTimeout(resolve, time));
}
new MutationObserver(function(mutations) {
if (document.querySelector(QuerySelector_StartElement) && loaded == 0) {
loaded = 1;
LoadProductionMonitor();
}
}).observe(document, {childList: true, subtree: true});
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);
}
function farmCount() {
landsCardsElements = document.querySelectorAll(QuerySelector_StartElement);
farm = 0;
landFarms = [];
workingDates = [];
for (let item in landsCardsElements) {
let value = 0;
try {
value = parseFloat(landsCardsElements[item].querySelector('.land-farm-rabt > span').textContent.split(' ')[0]);
landFarms.push(value);
workingDates.push(landsCardsElements[item].querySelector('.land-farm-rabt > span').title)
} catch (e) {
}
farm += value;
}
}
async function doHarvest() {
const landsCardsElementsHarvest = document.querySelectorAll(QuerySelector_StartElement);
const count = landsCardsElementsHarvest.length;
for (let index = 0; index <= count; index++) {
try {
console.log("init harvest", index);
await delay(1000);
let landsCardsElementsHarvest = document.querySelectorAll(QuerySelector_StartElement);
landsCardsElementsHarvest[index].querySelector('.land-card-btn').click();
console.log("init harvested", index);
await delay(1000);
console.log("next harvest", index);
} catch (e) {
console.log(e);
}
}
}
function getFarmAmount() {
farmCount();
return getValueFormated(farm);
}
async function LoadProductionMonitor () {
AddHtml();
await doHarvest();
intervalPlay();
//setInterval(function () {
// AddHtml();
//}, 60000);
}
function getFarmPerMinute() {
let timeDiff = Date.now() - dateStarted;
if (timeDiff < 60000) return '-';
return getValueFormated((farm / (timeDiff / 60000)));
}
function getFarmPerLand() {
return getValueFormated(farm / landsCardsElements.length);
}
function getValueFormated(value) {
return value.toLocaleString('pt-BR', {maximumFractionDigits: 2});
}
async function AddHtml() {
try {
var rowRemove = document.querySelector(".land-atributos2");
rowRemove.remove();
} catch (e) {
}
const row = document.createElement('div');
row.classList.add("row", 'land-atributos2');
const rowTitle = document.createElement('h2');
rowTitle.classList.add('3');
rowTitle.textContent = `Your Results`;
row.appendChild(rowTitle);
const div1 = document.createElement('div');
div1.classList.add('col-lg-3');
const div2 = document.createElement('div');
div2.classList.add('1');
const div3 = document.createElement('div');
div3.classList.add('1');
const div4 = document.createElement('div');
div4.classList.add('1');
const div5 = document.createElement('div');
div5.classList.add('1');
div5.appendChild(await AddText('Farm Total:', getFarmAmount()));
div5.appendChild(await AddText('Farm por minuto:', getFarmPerMinute()));
div5.appendChild(await AddText('Farm medio por land:', getFarmPerLand()));
div5.appendChild(await AddText('Lands:', landsCardsElements.length));
div4.appendChild(div5);
div3.appendChild(div4);
div2.appendChild(div3);
div1.appendChild(div2);
row.appendChild(div1);
document.querySelector('#farm > div.container').prepend(row);
}
async function AddText(title, text) {
const divContent = document.createElement('div');
divContent.classList.add('d-flex','justify-content-between');
const spanTitle = document.createElement('span');
spanTitle.innerHTML = title;
const spanText = document.createElement('span');
spanText.textContent = text ;
divContent.appendChild(spanTitle);
divContent.appendChild(spanText);
return divContent;
}
function intervalPlay() {
setTimeout(function() {
console.log("asd");
document.location.reload(true);
}, 120000);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment