Skip to content

Commit

Permalink
๐Ÿšธ Improved number formatting + ๐Ÿ› Variable bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kieranperk authored Dec 7, 2023
1 parent eb0a4ba commit 1c957b7
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let currentNumber = localStorage.getItem("number") || 1;
let scrollsPerScroll = localStorage.getItem("sps") || 1;
let scrollsPerScrollLevel = localStorage.getItem("spsl") || 1; // index in upgades array
let autoScrollerSPS = localStorage.getItem("assps") || 0;
let autoScrollerLevel = localStorage.getItem("asl") || 1;
let autoScrollerLevel = localStorage.getItem("asl") || 0;
let darkMode = localStorage.getItem("darkMode") || "true";

// Scrolling
Expand All @@ -19,7 +19,7 @@ function updateNumberOnScroll(event) {
}
}
const numberContainer = document.getElementById("number");
numberContainer.innerText = currentNumber;
numberContainer.innerText = currentNumber.toLocaleString();
numberContainer.className = "numberscrolling";
setTimeout(() => {
numberContainer.className = "number";
Expand Down Expand Up @@ -175,7 +175,7 @@ function resetCounter() {
clearInterval(autoscrollerInterval);

const numberContainer = document.getElementById("number");
numberContainer.innerText = currentNumber;
numberContainer.innerText = currentNumber.toLocaleString();

localStorage.setItem("number", currentNumber);
localStorage.setItem("sps", 1);
Expand All @@ -195,17 +195,11 @@ function resetCounter() {
// Helpers

function numberStringShortener(number) {
if (number > 999 && number < 1000000) {
number /= 1000
number = +number.toFixed(1)
return `${number}k`
} else if (number > 999999 && number < 1000000000) {
number /= 1000000
number = +number.toFixed(1)
return `${number}m`
} else {
return `${number}x`
}
return number.toLocaleString('en-US', {
maximumFractionDigits: 2,
notation: 'compact',
compactDisplay: 'short'
});
}

// Event Listeners
Expand All @@ -222,7 +216,7 @@ window.addEventListener("load", function () {
darkMode = localStorage.getItem("darkMode") === "true";
// Load number
const numberContainer = document.getElementById("number");
numberContainer.innerText = currentNumber;
numberContainer.innerText = currentNumber.toLocaleString();
// Load dark mode
const bodyElement = document.body;
bodyElement.classList.toggle("dark-theme", darkMode);
Expand Down

0 comments on commit 1c957b7

Please sign in to comment.