nelle-observer/astro/public/scripts/ntfy.js

73 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-08-18 19:50:35 -06:00
const ntfyInput = document.getElementById("ntfy-input");
const ntfyButton = document.getElementById("ntfy-send");
2024-09-01 21:27:52 -06:00
// Random placeholder
function getPlaceholder() {
2024-09-01 21:27:58 -06:00
placeholderSelector = Math.floor(Math.random() * 8) + 1;
switch (placeholderSelector) {
2024-09-01 21:27:52 -06:00
case 1:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "hi nelle! (。><。)";
break;
2024-09-01 21:27:52 -06:00
case 2:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "(╹◡╹)凸";
break;
2024-09-01 21:27:52 -06:00
case 3:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "Confession of sin: I dont like SciAdv";
break;
2024-09-01 21:27:52 -06:00
case 4:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "Knock Knock...";
break;
2024-09-01 21:27:52 -06:00
case 5:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "El. Psy. Kongroo.";
break;
2024-09-01 21:27:52 -06:00
case 6:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "the organization is after you.";
break;
2024-09-01 21:27:52 -06:00
case 7:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder =
"you wouldnt happen to know where an IBN5100 is, would you?";
break;
2024-09-01 21:27:52 -06:00
case 8:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder =
"if you had to choose, between: bacon, unlimited bacon, but no games. or. games. unlimited games, but no games. which would you pick?";
break;
2024-09-01 21:27:52 -06:00
case 9:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "time travel?";
break;
2024-09-01 21:27:52 -06:00
default:
2024-09-01 21:27:58 -06:00
ntfyInput.placeholder = "type some words and hit send";
2024-09-01 21:27:52 -06:00
}
}
// send function
2024-08-12 01:26:18 -06:00
function send(message) {
2024-08-18 01:37:10 -06:00
const r = new XMLHttpRequest();
2024-08-12 01:26:18 -06:00
r.open("POST", "https://ntfy.ouroboros.group/beep", true);
r.setRequestHeader("Content-Type", "text/plain");
r.send(message);
}
2024-08-18 19:50:35 -06:00
2024-08-12 01:26:18 -06:00
// send notification
function sendNotification() {
send(ntfyInput.value);
ntfyInput.value = "";
}
2024-08-18 19:50:35 -06:00
2024-09-01 21:27:52 -06:00
// on send button click
2024-08-18 19:50:35 -06:00
async function ntfyClick() {
2024-09-01 20:50:03 -06:00
if (!ntfyInput.value.replace(/\s/g, "").length) {
2024-08-18 20:08:42 -06:00
ntfyButton.innerHTML = "<span>ಠ﹏ಠ</span>";
2024-08-20 19:18:23 -06:00
setTimeout(() => {
2024-08-18 20:08:42 -06:00
ntfyButton.innerHTML = "<span>Send</span>";
2024-08-18 19:50:35 -06:00
return;
2024-08-20 19:18:23 -06:00
}, 1000);
2024-09-01 20:50:03 -06:00
} else {
2024-08-18 20:08:42 -06:00
ntfyButton.innerHTML = "<span>Sent! ( ꈍᴗꈍ)</span>";
2024-08-18 19:50:35 -06:00
sendNotification();
2024-08-20 19:18:23 -06:00
setTimeout(() => {
2024-08-18 20:08:42 -06:00
ntfyButton.innerHTML = "<span>Send</span>";
2024-08-20 19:18:23 -06:00
}, 1000);
2024-08-18 19:50:35 -06:00
}
}