|
function homka() { |
|
const authorization = "Bearer " + localStorage.getItem('authToken') |
|
|
|
// localStorage.setItem('ebyshki-vorobuski', 0); |
|
const startDate = new Date |
|
|
|
function timeAgo(date) { |
|
const secondsPast = (new Date() - date) / 1000; |
|
|
|
if (secondsPast < 60) { |
|
return "меньше минуты назад"; |
|
} else if (secondsPast < 3600) { |
|
const minutes = Math.floor(secondsPast / 60); |
|
return `${minutes} минут${getPlural(minutes)} назад`; |
|
} else if (secondsPast < 86400) { |
|
const hours = Math.floor(secondsPast / 3600); |
|
return `${hours} час${getPlural(hours)} назад`; |
|
} else if (secondsPast < 2592000) { |
|
const days = Math.floor(secondsPast / 86400); |
|
return `${days} день${getPlural(days)} назад`; |
|
} else if (secondsPast < 31536000) { |
|
const months = Math.floor(secondsPast / 2592000); |
|
return `${months} месяц${getPlural(months)} назад`; |
|
} else { |
|
const years = Math.floor(secondsPast / 31536000); |
|
return `${years} год${getPlural(years)} назад`; |
|
} |
|
} |
|
|
|
function getPlural(number) { |
|
const lastDigit = number % 10; |
|
const lastTwoDigits = number % 100; |
|
if (lastDigit === 1 && lastTwoDigits !== 11) { |
|
return ""; |
|
} else if (lastDigit >= 2 && lastDigit <= 4 && (lastTwoDigits < 10 || lastTwoDigits >= 20)) { |
|
return "а"; |
|
} else { |
|
return "ов"; |
|
} |
|
} |
|
|
|
|
|
function request(count, availableTaps) { |
|
const min = 1 |
|
const max = 60 |
|
const seconds = Math.round(Math.random() * (max - min) + min) |
|
|
|
fetch('https://api.hamsterkombatgame.io/clicker/tap', { |
|
method: 'POST', |
|
mode: 'cors', |
|
headers: { |
|
// "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0", |
|
"Accept": "application/json", |
|
"Accept-Language": "ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3", |
|
"authorization": authorization, |
|
"content-type": "application/json", |
|
}, |
|
referrer: 'https://hamsterkombatgame.io/', |
|
body: JSON.stringify({ |
|
count, |
|
availableTaps, |
|
timestamp: Math.floor(Date.now() / 1000) |
|
}) |
|
|
|
}) |
|
.then(r => r.json()) |
|
.then(body => { |
|
const startBalance = localStorage.getItem('startBalance'); |
|
let currentProfit = 0; |
|
if(startBalance === null) { |
|
localStorage.setItem('startBalance', Math.round(body.clickerUser.lastPassiveEarn)); |
|
} else { |
|
currentProfit = Math.round(body.clickerUser.balanceCoins) - Math.round(startBalance) |
|
} |
|
|
|
const passiveProfit = Math.round(body.clickerUser.earnPassivePerSec); |
|
|
|
console.clear() |
|
|
|
console.info('Общая информация:') |
|
console.table({ |
|
'Ожидание (сек.)': seconds, |
|
'Баланс': Math.round(body.clickerUser.balanceCoins), |
|
'Общий баланс': Math.round(body.clickerUser.totalCoins), |
|
'Уровень': body.clickerUser.level, |
|
'Всего тапов': body.clickerUser.maxTaps, |
|
'Прошло с момента запуска скрипта': timeAgo(startDate), |
|
'Текущее время': (new Date).toLocaleString(), |
|
}) |
|
|
|
console.info('Информация о доходах:') |
|
console.table({ |
|
'Доход с тапа': body.clickerUser.earnPerTap, |
|
'Доход пасивный в секунду': passiveProfit, |
|
// 'Доход с момента запуска скрипта': currentProfit, |
|
}) |
|
|
|
setTimeout(() => { |
|
const tapRecover = body.clickerUser.tapsRecoverPerSec |
|
const availableTaps = body.clickerUser.availableTaps; |
|
let currentEnergy = availableTaps > 0 ? availableTaps : seconds * tapRecover |
|
|
|
request(currentEnergy, body.clickerUser.maxTaps - currentEnergy) |
|
}, seconds * 1000) |
|
}) |
|
.catch((error) => { |
|
console.error('Error: ', error); |
|
clearInterval(interval) |
|
}) |
|
} |
|
|
|
function getEnergy() { |
|
return document.querySelector('.user-tap-energy > p') |
|
.textContent.split(' / '); |
|
} |
|
|
|
[currentEnergy, totalEnergy] = getEnergy() |
|
request(Number(currentEnergy), totalEnergy - currentEnergy) |
|
} |