fixed friendly button

This commit is contained in:
ari melody 2024-04-07 00:29:51 +01:00
parent f7f6254016
commit 1fcb473c5f
Signed by: ari
GPG key ID: CF99829C92678188

View file

@ -40,7 +40,9 @@
</p> </p>
<button id="friendly-button">friendly button</button> <button id="friendly-button">friendly button</button>
<script> <script>
function hook_button() {
const button = document.getElementById("friendly-button"); const button = document.getElementById("friendly-button");
if (!button) return;
let clicks = 0; let clicks = 0;
let saved_clicks = window.localStorage.getItem("friendly-button-clicks"); let saved_clicks = window.localStorage.getItem("friendly-button-clicks");
if (saved_clicks) { if (saved_clicks) {
@ -51,6 +53,9 @@
button.innerText = `clicked ${++clicks} times!`; button.innerText = `clicked ${++clicks} times!`;
window.localStorage.setItem("friendly-button-clicks", clicks); window.localStorage.setItem("friendly-button-clicks", clicks);
}); });
}
document.addEventListener("ready", hook_button);
document.addEventListener("htmx:load", hook_button);
</script> </script>
</main> </main>
<footer> <footer>