This commit is contained in:
nelle 2024-09-03 16:58:14 -06:00
parent 997a7cdc47
commit 5adcad0685
4 changed files with 173 additions and 26 deletions

View file

@ -1,3 +1,6 @@
// i deeply apologize for the horrors within...
const ntfyEndpoint = "https://ntfy.ouroboros.group/beep"
const ntfyMessage = document.getElementById("ntfy-message");
const ntfyTitle = document.getElementById("ntfy-title");
const ntfyAttach = document.getElementById("ntfy-attach");
@ -13,10 +16,33 @@ const titleBoxLabel = document.getElementById("titleBoxLabel");
const attachmentBoxLabel = document.getElementById("attachBoxLabel");
const clickBoxLabel = document.getElementById("clickBoxLabel");
const msgPFX = "message: "
const optionsEnabled = sessionStorage.getItem("optionsEnabled");
const titleEnabled = sessionStorage.getItem("optionsEnabled");
const attachmentEnabled = sessionStorage.getItem("optionsEnabled");
const clickEnabled = sessionStorage.getItem("optionsEnabled");
const msgPFX = "message: ";
function checkBoxes() {
if (optionsEnabled) {
optionsCheck.checked = true;
toggleOptions();
}
if (titleEnabled) {
titleCheck.checked = true;
toggleTitle();
}
if (attachmentEnabled) {
attachmentCheck.checked = true;
toggleAttach();
}
if (clickEnabled) {
clickCheck.checked = true;
toggleClick();
}
}
// Random placeholder
function getPlaceholder() {
placeholderSelector = Math.floor(Math.random() * 8) + 1;
switch (placeholderSelector) {
@ -39,12 +65,10 @@ function getPlaceholder() {
ntfyMessage.placeholder = `${msgPFX}the organization is after you.`;
break;
case 7:
ntfyMessage.placeholder =
`${msgPFX}you wouldnt happen to know where an IBN5100 is, would you?`;
ntfyMessage.placeholder = `${msgPFX}you wouldnt happen to know where an IBN5100 is, would you?`;
break;
case 8:
ntfyMessage.placeholder =
`${msgPFX}if you had to choose, between: bacon, unlimited bacon, but no games. or. games. unlimited games, but no games. which would you pick?`;
ntfyMessage.placeholder = `${msgPFX}if you had to choose, between: bacon, unlimited bacon, but no games. or. games. unlimited games, but no games. which would you pick?`;
break;
case 9:
ntfyMessage.placeholder = `${msgPFX}time travel?`;
@ -54,10 +78,20 @@ function getPlaceholder() {
}
}
// send function
function send(message, title, attachment, click) {
// send functions
// only message
function sendNone(message) {
const r = new XMLHttpRequest();
r.open("POST", "https://ntfy.ouroboros.group/beep", true);
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.send(message);
}
// send all
function sendAll(title, message, attachment, click) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Title", title);
r.setRequestHeader("Attach", attachment);
@ -65,12 +99,117 @@ function send(message, title, attachment, click) {
r.send(message);
}
// send title only
function sendTitle(title, message) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Title", title);
r.send(message);
}
// send attachment only
function sendAttach(message, attachment) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Attach", attachment);
r.send(message);
}
// send click only
function sendClick(message, click) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Click", click);
r.send(message);
}
// send Title & Attachment
function sendTitleAttach(title, message, attachment) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Title", title);
r.setRequestHeader("Attach", attachment);
r.send(message);
}
// send Title & Click
function sendTitleClick(title, message, click) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Title", title);
r.setRequestHeader("Click", click);
r.send(message);
}
// send Attach & Click
function sendAttachClick(message, attachment, click) {
const r = new XMLHttpRequest();
r.open("POST", ntfyEndpoint, true);
r.setRequestHeader("Content-Type", "text/plain");
r.setRequestHeader("Attach", attachment);
r.setRequestHeader("Click", click);
r.send(message);
}
// send notification
function sendNotification() {
send(ntfyTitle.value, ntfyMessage.value, ntfyAttach.value, ntfyClickAction.value);
ntfyTitle.value = "";
ntfyAttach.value = "";
ntfyClickAction.value = "";
// title only
if (titleEnabled && !attachmentEnabled && !clickEnabled) {
sendTitle(ntfyTitle.value, ntfyMessage.value);
ntfyTitle.value = "";
ntfyMessage.value = "";
}
// attachment only
if (!titleEnabled && attachmentEnabled && !clickEnabled) {
sendAttach(ntfyMessage.value, ntfyAttach.value);
ntfyMessage.value = "";
ntfyAttach.value = "";
}
// click only
if (!titleEnabled && !attachmentEnabled && clickEnabled) {
sendClick(ntfyMessage.value, ntfyClickAction.value);
ntfyMessage.value = "";
ntfyClickAction.value = "";
}
// title & attachment
if (titleEnabled && attachmentEnabled && !clickEnabled) {
sendTitleAttach(ntfyTitle.value, ntfyMessage.value, ntfyAttach.value);
ntfyTitle.value = "";
ntfyMessage.value = "";
ntfyAttach.value = "";
}
// title & click
if (titleEnabled && !attachmentEnabled && clickEnabled) {
sendTitleClick(ntfyTitle.value, ntfyMessage.value, ntfyClickAction.value);
ntfyTitle.value = "";
ntfyMessage.value = "";
ntfyClickAction.value = "";
}
// attachment & click
if (!titleEnabled && attachmentEnabled && clickEnabled) {
sendAttachClick(ntfyMessage.value, ntfyAttach.value, ntfyClickAction.value);
ntfyAttach.value = "";
ntfyMessage.value = "";
ntfyClickAction.value = "";
}
// all three
if (titleEnabled && attachmentEnabled && clickEnabled) {
sendAll(ntfyTitle.value, ntfyMessage.value, ntfyAttach.value, ntfyClickAction.value);
ntfyTitle.value = "";
ntfyMessage.value = "";
ntfyAttach.value = "";
ntfyClickAction.value = "";
}
// none
else {
sendNone(ntfyMessage.value);
ntfyMessage.value = "";
}
}
// on send button click
@ -92,6 +231,7 @@ async function ntfyClick() {
function toggleOptions() {
if (optionsCheck.checked) {
sessionStorage.setItem("optionsEnabled", 1);
titleBoxLabel.style.display = "initial";
attachmentBoxLabel.style.display = "initial";
clickBoxLabel.style.display = "initial";
@ -100,6 +240,7 @@ function toggleOptions() {
clickCheck.style.display = "initial";
}
if (!optionsCheck.checked) {
sessionStorage.removeItem("optionsEnabled");
titleBoxLabel.style.display = "none";
attachmentBoxLabel.style.display = "none";
clickBoxLabel.style.display = "none";
@ -111,27 +252,33 @@ function toggleOptions() {
function toggleTitle() {
if (titleCheck.checked) {
ntfyTitle.style.display = "initial"
sessionStorage.setItem("titleEnabled", 1);
ntfyTitle.style.display = "initial";
}
if (!titleCheck.checked) {
ntfyTitle.style.display = "none"
sessionStorage.removeItem("titleEnabled");
ntfyTitle.style.display = "none";
}
}
function toggleAttach() {
if (attachmentCheck.checked) {
ntfyAttach.style.display = "initial"
sessionStorage.setItem("attachmentEnabled", 1);
ntfyAttach.style.display = "initial";
}
if (!attachmentCheck.checked) {
ntfyAttach.style.display = "none"
sessionStorage.removeItem("attachmentEnabled");
ntfyAttach.style.display = "none";
}
}
function toggleClick() {
if (clickCheck.checked) {
ntfyClickAction.style.display = "initial"
sessionStorage.setItem("clickEnabled", 1);
ntfyClickAction.style.display = "initial";
}
if (!clickCheck.checked) {
ntfyClickAction.style.display = "none"
sessionStorage.removeItem("clickEnabled");
ntfyClickAction.style.display = "none";
}
}
}

View file

@ -1,4 +1,4 @@
function getSGAStates() {
function getSGAState() {
if (sessionStorage.getItem("sgaEnabled")) {
enableSGA();
}

View file

@ -10,10 +10,10 @@
<br>
<!-- TEXT AREAS -->
<div>
<textarea id="ntfy-title" placeholder="title" rows=1 style="resize: none; display: none;"></textarea>
<textarea id="ntfy-message" placeholder="message" rows=2></textarea>
<textarea id="ntfy-attach" placeholder="attachment link" rows=1 style="resize: none;display: none;"></textarea>
<textarea id="ntfy-click" placeholder="click link" rows=1 style="resize: none; display: none;"></textarea>
<textarea id="ntfy-title" placeholder="title: Title" rows=1 style="resize: none; display: none;"></textarea>
<textarea id="ntfy-message" placeholder="message: hello!" rows=2></textarea>
<textarea id="ntfy-attach" placeholder="attachment: https://http.cat/images/100.jpg" rows=1 style="resize: none;display: none;"></textarea>
<textarea id="ntfy-click" placeholder="click: https://www.youtube.com/watch?v=dQw4w9WgXcQ" rows=1 style="resize: none; display: none;"></textarea>
</div>
<button
class="custom-btn btn-1"

View file

@ -16,7 +16,7 @@ const { title } = Astro.props;
<head>
<Head title={title} />
</head>
<body onload="getSGAState(), redirect(), getPlaceholder()" id="body">
<body onload="checkBoxes(), getSGAState(), redirect(), getPlaceholder()" id="body">
<Header />
<section class="content center">
<h1 class="title">{title}</h1>