2024-09-03 16:58:14 -06:00
// i deeply apologize for the horrors within...
const ntfyEndpoint = "https://ntfy.ouroboros.group/beep"
2024-09-03 03:53:02 -06:00
const ntfyMessage = document . getElementById ( "ntfy-message" ) ;
const ntfyTitle = document . getElementById ( "ntfy-title" ) ;
const ntfyAttach = document . getElementById ( "ntfy-attach" ) ;
const ntfyClickAction = document . getElementById ( "ntfy-click" ) ;
const ntfyButton = document . getElementById ( "ntfy-button" ) ;
2024-09-03 16:03:57 -06:00
const optionsCheck = document . getElementById ( "optionsCheckbox" ) ;
2024-09-03 15:33:41 -06:00
const titleCheck = document . getElementById ( "titleCheckbox" ) ;
const attachmentCheck = document . getElementById ( "attachmentCheckbox" ) ;
const clickCheck = document . getElementById ( "clickCheckbox" ) ;
2024-09-03 16:03:57 -06:00
const titleBoxLabel = document . getElementById ( "titleBoxLabel" ) ;
const attachmentBoxLabel = document . getElementById ( "attachBoxLabel" ) ;
const clickBoxLabel = document . getElementById ( "clickBoxLabel" ) ;
2024-09-03 16:58:14 -06:00
const optionsEnabled = sessionStorage . getItem ( "optionsEnabled" ) ;
const titleEnabled = sessionStorage . getItem ( "optionsEnabled" ) ;
const attachmentEnabled = sessionStorage . getItem ( "optionsEnabled" ) ;
const clickEnabled = sessionStorage . getItem ( "optionsEnabled" ) ;
2024-08-18 19:50:35 -06:00
2024-09-03 16:58:14 -06:00
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 ( ) ;
}
}
2024-09-01 21:27:52 -06:00
2024-09-03 16:58:14 -06:00
// Random placeholder
2024-09-01 21:27:52 -06:00
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-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } hi nelle! (。>﹏ <。) ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 2 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } (╹◡╹)凸 ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 3 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } Confession of sin: I dont like SciAdv ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 4 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } Knock Knock... ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 5 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } El. Psy. Kongroo. ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 6 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } the organization is after you. ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 7 :
2024-09-03 16:58:14 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } you wouldnt happen to know where an IBN5100 is, would you? ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 8 :
2024-09-03 16:58:14 -06:00
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? ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 9 :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } time travel? ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
default :
2024-09-03 03:53:02 -06:00
ntfyMessage . placeholder = ` ${ msgPFX } type some words and hit send ` ;
2024-09-01 21:27:52 -06:00
}
}
2024-09-03 16:58:14 -06:00
// send functions
// only message
function sendNone ( message ) {
const r = new XMLHttpRequest ( ) ;
r . open ( "POST" , ntfyEndpoint , true ) ;
r . setRequestHeader ( "Content-Type" , "text/plain" ) ;
r . send ( message ) ;
}
// send all
function sendAll ( title , message , attachment , click ) {
2024-08-18 01:37:10 -06:00
const r = new XMLHttpRequest ( ) ;
2024-09-03 16:58:14 -06:00
r . open ( "POST" , ntfyEndpoint , true ) ;
2024-09-03 15:33:41 -06:00
r . setRequestHeader ( "Content-Type" , "text/plain" ) ;
2024-09-03 03:53:02 -06:00
r . setRequestHeader ( "Title" , title ) ;
r . setRequestHeader ( "Attach" , attachment ) ;
2024-09-03 15:33:41 -06:00
r . setRequestHeader ( "Click" , click ) ;
2024-08-12 01:26:18 -06:00
r . send ( message ) ;
}
2024-08-18 19:50:35 -06:00
2024-09-03 16:58:14 -06:00
// 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 ) ;
}
2024-08-12 01:26:18 -06:00
// send notification
2024-09-03 15:33:41 -06:00
function sendNotification ( ) {
2024-09-03 16:58:14 -06:00
// 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 = "" ;
}
2024-08-12 01:26:18 -06:00
}
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-03 03:53:02 -06:00
if ( ! ntfyMessage . 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
}
}
2024-09-03 04:41:52 -06:00
2024-09-03 16:03:57 -06:00
function toggleOptions ( ) {
if ( optionsCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . setItem ( "optionsEnabled" , 1 ) ;
2024-09-03 16:03:57 -06:00
titleBoxLabel . style . display = "initial" ;
attachmentBoxLabel . style . display = "initial" ;
clickBoxLabel . style . display = "initial" ;
titleCheck . style . display = "initial" ;
attachmentCheck . style . display = "initial" ;
clickCheck . style . display = "initial" ;
}
if ( ! optionsCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . removeItem ( "optionsEnabled" ) ;
2024-09-03 16:03:57 -06:00
titleBoxLabel . style . display = "none" ;
attachmentBoxLabel . style . display = "none" ;
clickBoxLabel . style . display = "none" ;
titleCheck . style . display = "none" ;
attachmentCheck . style . display = "none" ;
clickCheck . style . display = "none" ;
}
}
2024-09-03 04:41:52 -06:00
function toggleTitle ( ) {
2024-09-03 15:33:41 -06:00
if ( titleCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . setItem ( "titleEnabled" , 1 ) ;
ntfyTitle . style . display = "initial" ;
2024-09-03 04:41:52 -06:00
}
2024-09-03 15:33:41 -06:00
if ( ! titleCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . removeItem ( "titleEnabled" ) ;
ntfyTitle . style . display = "none" ;
2024-09-03 04:41:52 -06:00
}
}
function toggleAttach ( ) {
2024-09-03 15:33:41 -06:00
if ( attachmentCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . setItem ( "attachmentEnabled" , 1 ) ;
ntfyAttach . style . display = "initial" ;
2024-09-03 04:41:52 -06:00
}
2024-09-03 15:33:41 -06:00
if ( ! attachmentCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . removeItem ( "attachmentEnabled" ) ;
ntfyAttach . style . display = "none" ;
2024-09-03 04:41:52 -06:00
}
}
function toggleClick ( ) {
2024-09-03 15:33:41 -06:00
if ( clickCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . setItem ( "clickEnabled" , 1 ) ;
ntfyClickAction . style . display = "initial" ;
2024-09-03 04:41:52 -06:00
}
2024-09-03 15:33:41 -06:00
if ( ! clickCheck . checked ) {
2024-09-03 16:58:14 -06:00
sessionStorage . removeItem ( "clickEnabled" ) ;
ntfyClickAction . style . display = "none" ;
2024-09-03 04:41:52 -06:00
}
2024-09-03 16:58:14 -06:00
}