Various improvements

This commit is contained in:
2024-05-14 17:44:57 +02:00
parent 49d874ad6d
commit b24f87e883
15 changed files with 1885 additions and 91 deletions

20
painter-js/src/counter.js Normal file
View File

@@ -0,0 +1,20 @@
import { pixelCooldown } from "./constants.js";
const countdownDiv = document.getElementById("countdown");
export const updateCountdown = () => {
setInterval(() => {
const lastPixelTime = parseInt(
localStorage.getItem("lastPixelTime") || "0"
);
const now = Date.now();
const timeLeft = Math.max(0, pixelCooldown - (now - lastPixelTime));
if (timeLeft > 0) {
countdownDiv.textContent = `You can place a pixel in ${Math.ceil(
timeLeft / 1000
)} seconds`;
} else {
countdownDiv.textContent = "You can place a pixel now";
}
}, 1000);
};