index.html (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>clicker</title>
<link rel="stylesheet" href="./assets/main.css" />
</head>
<body>
<main>
<header>
<h1>click</h1>
<p class="sub">make my phone go ""Clic k "" .!</p>
</header>
<form id="click-form">
<div class="field">
<label for="message">leave a message!</label>
<input
id="message"
type="text"
placeholder="or don't that's okay idc i wont care"
autocomplete="off"
/>
</div>
<button type="submit" id="btn" class="btn">
<span class="btn-label">send click!</span>
<span class="btn-state" aria-hidden="true">sending <i></i></span>
</button>
</form>
<div id="status" class="status-box" role="status" aria-live="polite"></div>
</main>
<script>
const form = document.getElementById("click-form");
const input = document.getElementById("message");
const btn = document.getElementById("btn");
const statusEl = document.getElementById("status");
let statusTimeout;
form.addEventListener("submit", async (e) => {
e.preventDefault();
btn.disabled = true;
btn.classList.add("is-sending");
window.clearTimeout(statusTimeout);
statusEl.className = "status-box";
statusEl.textContent = "";
const message = input.value.trim() || undefined;
try {
const res = await fetch("/api/click", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message }),
});
const result = await res.json();
if (result.error) {
statusEl.className = "status-box error";
statusEl.textContent = `couldn't click :c ${result.error.error.toLowerCase()}`;
} else {
statusEl.className = "status-box success pop";
statusEl.textContent = "click sent!";
input.value = "";
btn.classList.remove("is-sending");
btn.classList.add("is-sent");
window.setTimeout(() => btn.classList.remove("is-sent"), 900);
}
statusTimeout = window.setTimeout(() => {
statusEl.className = "status-box dismissing";
window.setTimeout(() => {
statusEl.className = "status-box";
statusEl.textContent = "";
}, 180);
}, 3000);
} catch (err) {
statusEl.className = "status-box error";
statusEl.textContent =
"couldn't click, try again?";
statusTimeout = window.setTimeout(() => {
statusEl.className = "status-box dismissing";
window.setTimeout(() => {
statusEl.className = "status-box";
statusEl.textContent = "";
}, 180);
}, 3000);
} finally {
btn.disabled = false;
btn.classList.remove("is-sending");
}
});
</script>
</body>
</html>
|