Use named function to submit ntfy message

This commit is contained in:
pancakes 2024-12-03 20:24:03 +10:00
parent 697dfdab18
commit 6e6db6d109
No known key found for this signature in database
GPG key ID: ED53D426432B861B

View file

@ -5,7 +5,24 @@
const pages = getPages();
function updateCharCount(_) {
function sendNtfyMessage() {
const message = document.getElementById("ntfy-message").value;
if (message.length < 15)
return alert(
`Message must be 15 to 128 characters. Current length is ${message.length}`,
);
fetch("https://ntfy.meow.company/pancakes", {
method: "POST",
body: message,
headers: {
Title: "pancakes.gay",
Priority: "min",
Tags: "black_cat",
},
});
}
function updateNtfyCharCount(_) {
const message = document.getElementById("ntfy-message").value;
const el = document.getElementById("ntfy-char-count");
@ -354,7 +371,7 @@
</p>
<input
on:input={updateCharCount}
on:input={updateNtfyCharCount}
type="text"
id="ntfy-message"
name="ntfy-message"
@ -366,27 +383,7 @@
128
</label>
<br />
<button
on:click={() => {
const message = document.getElementById("ntfy-message").value;
if (message.length < 15)
return alert(
`Message must be 15 to 128 characters. Current length is ${message.length}`,
);
fetch("https://ntfy.meow.company/pancakes", {
method: "POST",
body: message,
headers: {
Title: "pancakes.gay",
Priority: "min",
Tags: "black_cat",
},
});
}}
style="margin-top: 1rem;"
>
Send
</button>
<button on:click={sendNtfyMessage} style="margin-top: 1rem;"> Send </button>
</main>
<style>