advanced ntfy!

This commit is contained in:
nelle 2024-08-18 19:50:35 -06:00
parent 91a55ceca9
commit 64c88f00e5
2 changed files with 31 additions and 4 deletions

View file

@ -1,3 +1,6 @@
const ntfyInput = document.getElementById("ntfy-input");
const ntfyButton = document.getElementById("ntfy-send");
// both // both
function send(message) { function send(message) {
const r = new XMLHttpRequest(); const r = new XMLHttpRequest();
@ -5,10 +8,33 @@ function send(message) {
r.setRequestHeader("Content-Type", "text/plain"); r.setRequestHeader("Content-Type", "text/plain");
r.send(message); r.send(message);
} }
// send notification // send notification
const ntfyInput = document.getElementById("ntfy-input");
function sendNotification() { function sendNotification() {
if (ntfyInput.value.length <= 0) return;
send(ntfyInput.value); send(ntfyInput.value);
ntfyInput.value = ""; ntfyInput.value = "";
} }
async function ntfyClick() {
if (ntfyInput.value.length >= 0) {
ntfyButton.innerHTML = "ಠ﹏ಠ";
setTimeout(()=> {
ntfyButton.innerHTML = "Send";
return;
}, 1000);
}
if (ntfyInput.value === ' ') {
ntfyButton.innerHTML = "ಠ﹏ಠ";
setTimeout(()=> {
ntfyButton.innerHTML = "Send";
return;
}, 1000);
}
if (ntfyInput.value.length >= 1 && ntfyInput.value !== " ") {
ntfyButton.innerHTML = "Sent! ( ꈍᴗꈍ)";
sendNotification();
setTimeout(()=> {
ntfyButton.innerHTML = "Send";
}, 1000);
}
}

View file

@ -56,8 +56,9 @@ import Layout from "../layouts/Layout.astro";
<br style="margin-bottom: 10px;"> <br style="margin-bottom: 10px;">
<textarea id="ntfy-input" placeholder="Hi nelle~!"></textarea><button <textarea id="ntfy-input" placeholder="Hi nelle~!"></textarea><button
class="ntfy-send nob4 custom-btn btn-1" class="ntfy-send nob4 custom-btn btn-1"
onclick="sendNotification()" onclick="ntfyClick()"
style="margin-left:10px;">Send</button style="margin-left:10px;"
id="ntfy-send">Send</button
> >
</div> </div>
</div> </div>