zyllian.github.io/site/root/js/pet-me.js

28 lines
759 B
JavaScript
Raw Normal View History

2024-06-25 16:31:26 -07:00
(function () {
"use strict";
const url = document.body.classList.contains("debug")
? "http://127.0.0.1:8787/api/pet"
: "https://cf.zyllian.workers.dev/api/pet";
const petCounter = document.querySelector("#pet-counter");
const count = petCounter.querySelector(".count");
const petButton = petCounter.querySelector("button");
(async function () {
const r = await (await fetch(url)).json();
count.innerText = r.count;
})();
petButton.addEventListener("click", async () => {
petButton.disabled = true;
2024-06-25 16:41:37 -07:00
petButton.outerHTML = "| thanks! <3";
2024-06-25 16:31:26 -07:00
const r = await (await fetch(url, { method: "post" })).json();
if (r.count) {
count.innerText = r.count;
}
});
petCounter.style.display = "block";
})();