Skip to content

Instantly share code, notes, and snippets.

@jericjan
Last active August 5, 2023 10:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jericjan/cd86d5766b7bc869714c9002fd0d778f to your computer and use it in GitHub Desktop.
Save jericjan/cd86d5766b7bc869714c9002fd0d778f to your computer and use it in GitHub Desktop.
honkaihub.com - print crystals between 2 dates
const fromDate = new Date("2023-08-05T00:00:00Z");
const toDate = new Date("2023-10-31T00:00:00Z");
function incrementDay(date) {
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate() + 1;
const newDate = new Date(Date.UTC(year, month, day));
return newDate;
}
function isSameDate(date1, date2) {
return date1.getTime() == date2.getTime();
}
let currDate = fromDate;
reqBody = {
From: "2023-08-05T00:00:00",
To: "2023-08-10T00:00:00",
BalanceCrystals: 20357,
BalanceExpansionCards: 1,
BalanceFocusedCards: 1,
BalanceElfCards: 0,
BalanceSpCards: 0,
BalanceDormCards: 0,
Level: 88,
AbyssTier: "ex_agony2",
ElysianRealmDiff: "abstinence",
BpLevel: 61,
BpThisVersion: 0,
BpFutureVersions: 0,
SignInDays: 4,
MonthlyCardDays: 0,
MonthlyCardDaysBonus: 0,
CompletedAbyssMissions: true,
CustomRewards: [],
};
function makeRequests() {
return new Promise((res, rej) => {
const datesList = [];
const promises = [];
console.log("Making requests");
while (!isSameDate(currDate, toDate)) {
currDate = incrementDay(currDate);
const yoinkedDate = currDate;
reqBody.To = currDate.toISOString();
promises.push(
fetch("https://api.honkaihub.com/calc", {
headers: {
"content-type": "application/json",
},
body: JSON.stringify(reqBody),
method: "POST",
})
.then((e) => e.json())
.then((resp) => {
let calcXtals = resp.total.grandTotal;
return [yoinkedDate.toISOString(), calcXtals];
})
);
}
Promise.all(promises).then((results) => {
res(results);
});
});
}
makeRequests().then((results) => {
console.log("Printing results");
let textResults = "";
for (const [date, xtals] of results) {
textResults += `${date} - ${xtals}\n`;
}
const blob = new Blob([textResults], { type: "text/plain" });
const blobUrl = URL.createObjectURL(blob);
window.open(blobUrl);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment