From 6e20b8aafa35277b4724dadc6718e1b644ab722a Mon Sep 17 00:00:00 2001 From: ChrisCoy Date: Sun, 21 Sep 2025 13:58:21 -0300 Subject: [PATCH 1/2] save clicks count to localStorage --- index.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 5e443a5..b9a8264 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,8 @@ const regularFart = new Audio("fart-83471-fixed-regular.flac"); const critFart = new Audio("fart-4-228244-fixed-crit.flac"); +const STORAGE_KEY = "@button:" + +let canPlaySound = true; const farts = [ regularFart, @@ -7,6 +10,7 @@ const farts = [ ]; function playFart(fart) { + if (!canPlaySound) return; fart.currentTime = 0; fart.playbackRate = randomPlaybackRate(); fart.preservesPitch = false; @@ -125,8 +129,24 @@ function fireEvents() { } } +function initializeButton() { + debugger + canPlaySound = false; + for (const event of eventsTable.reverse()) { + if (event.onCount > counter) { + break; + } + + event.action(); + } + + eventsTable.reverse(); + canPlaySound = true; +} + + let shaking = false; -let counter = 0; // TODO: DONT FORGET TO SET TO 0 ON RELEASE!!! +let counter = Number(localStorage.getItem(`${STORAGE_KEY}counter`)) || 0; function finishFart() { shaking = false; @@ -136,11 +156,16 @@ for (let fart of farts) { fart.onended = finishFart; } +function updatePopup() { + popupText.innerText = counter + "🍑💨"; +} + // TODO: change it to onmousedown (it stopped working after separating button and label) clickMe.onclick = () => { counter += 1; - popupText.innerText = counter + "🍑💨"; + localStorage.setItem(`${STORAGE_KEY}counter`, counter); fireEvents(); + updatePopup(); }; let prevTimestamp = 0; @@ -163,4 +188,5 @@ window.requestAnimationFrame((timestamp) => { window.requestAnimationFrame(frame); }); -fireEvents(); +initializeButton(); +updatePopup(); \ No newline at end of file From c8d7f3b5fc8504e077139fae994ded7667016b1c Mon Sep 17 00:00:00 2001 From: ChrisCoy Date: Mon, 22 Sep 2025 07:50:25 -0300 Subject: [PATCH 2/2] remove left debugger --- index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/index.js b/index.js index b9a8264..8f2ef9d 100644 --- a/index.js +++ b/index.js @@ -130,7 +130,6 @@ function fireEvents() { } function initializeButton() { - debugger canPlaySound = false; for (const event of eventsTable.reverse()) { if (event.onCount > counter) {