2024-09-03 16:58:14 -06:00
// i deeply apologize for the horrors within...
2024-09-21 04:15:07 -06:00
const ntfyEndpoint = "https://nelle.observer/api/ntfy" ;
2024-09-21 04:48:50 -06:00
//const ntfyEndpoint = "http://0.0.0.0:7879/api/ntfy";
2024-09-03 16:58:14 -06:00
2024-09-11 05:42:18 -06:00
// text fields and buttons
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-11 05:42:18 -06:00
// options checkboxes
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-11 05:42:18 -06:00
// labels
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-11 05:42:18 -06:00
// Options storage variables
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-11 05:42:18 -06:00
// Prefixs for placeholders
2024-09-05 02:12:49 -06:00
const titlePFX = "title: " ;
2024-09-03 16:58:14 -06:00
const msgPFX = "message: " ;
2024-09-05 02:12:49 -06:00
const attachPFX = "attachment: " ;
const clickPFX = "click-action: " ;
2024-09-03 16:58:14 -06:00
2024-09-11 05:42:18 -06:00
// Ctrl + Enter to send
2024-09-11 05:36:12 -06:00
document . addEventListener ( "keydown" , ( event ) => {
2024-09-21 04:15:07 -06:00
if ( event . ctrlKey && event . key === "Enter" ) {
2024-09-11 05:37:52 -06:00
ntfyClick ( )
2024-09-11 05:36:12 -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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } hey there ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } fuck you ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } confession of sin ` ;
ntfyMessage . placeholder = ` ${ msgPFX } 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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } a funny joke ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } yes, its me ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } SDXc^73hce1!3& ` ;
ntfyMessage . placeholder = ` ${ msgPFX } we're watching you. ` ;
2024-09-01 21:27:58 -06:00
break ;
2024-09-01 21:27:52 -06:00
case 7 :
2024-09-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } haiiii :3 ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } an important question ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } query ` ;
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-05 02:12:49 -06:00
ntfyTitle . placeholder = ` ${ titlePFX } title the message for some reason? ` ;
ntfyMessage . placeholder = ` ${ msgPFX } type some words and hit send. ` ;
ntfyAttach . placeholder = ` ${ attachPFX } https://http.cat/images/100.jpg ` ;
2024-09-05 18:06:46 -06:00
ntfyClickAction . placeholder = ` ${ clickPFX } https://www.youtube.com/watch?v=dQw4w9WgXcQ ` ;
2024-09-01 21:27:52 -06:00
}
}
2024-09-05 18:06:46 -06:00
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 ( ) ;
}
}
function toggleOptions ( ) {
if ( optionsCheck . checked ) {
sessionStorage . setItem ( "optionsEnabled" , 1 ) ;
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 ) {
sessionStorage . removeItem ( "optionsEnabled" ) ;
titleBoxLabel . style . display = "none" ;
attachmentBoxLabel . style . display = "none" ;
clickBoxLabel . style . display = "none" ;
titleCheck . style . display = "none" ;
attachmentCheck . style . display = "none" ;
clickCheck . style . display = "none" ;
}
}
function toggleTitle ( ) {
if ( titleCheck . checked ) {
sessionStorage . setItem ( "titleEnabled" , 1 ) ;
ntfyTitle . style . display = "initial" ;
}
if ( ! titleCheck . checked ) {
sessionStorage . removeItem ( "titleEnabled" ) ;
ntfyTitle . style . display = "none" ;
}
}
function toggleAttach ( ) {
if ( attachmentCheck . checked ) {
sessionStorage . setItem ( "attachmentEnabled" , 1 ) ;
ntfyAttach . style . display = "initial" ;
}
if ( ! attachmentCheck . checked ) {
sessionStorage . removeItem ( "attachmentEnabled" ) ;
ntfyAttach . style . display = "none" ;
}
}
function toggleClick ( ) {
if ( clickCheck . checked ) {
sessionStorage . setItem ( "clickEnabled" , 1 ) ;
ntfyClickAction . style . display = "initial" ;
}
if ( ! clickCheck . checked ) {
sessionStorage . removeItem ( "clickEnabled" ) ;
ntfyClickAction . style . display = "none" ;
}
}
// on send button click
async function ntfyClick ( ) {
if ( ! ntfyMessage . value . replace ( /\s/g , "" ) . length ) {
ntfyButton . innerHTML = "<span>ಠ﹏ಠ</span>" ;
setTimeout ( ( ) => {
ntfyButton . innerHTML = "<span>Send</span>" ;
return ;
} , 1000 ) ;
} else {
ntfyButton . innerHTML = "<span>Sent! ( ꈍᴗꈍ)</span>" ;
sendNotification ( ) ;
setTimeout ( ( ) => {
ntfyButton . innerHTML = "<span>Send</span>" ;
} , 1000 ) ;
}
}
2024-09-03 16:58:14 -06:00
// send all
2024-09-05 18:23:55 -06:00
function sendAll ( endpoint , title , message , attachment , click ) {
2024-09-21 04:15:07 -06:00
const xhr = new XMLHttpRequest ( ) ;
const formData = new FormData ( ) ;
formData . append ( "Title" , title ) ;
formData . append ( "Message" , message ) ;
formData . append ( "Attach" , attachment ) ;
formData . append ( "Click" , click ) ;
// Submit the data via fetch()
fetch ( endpoint , {
method : "POST" ,
body : formData ,
} ) ;
2024-09-03 16:58:14 -06:00
}
2024-08-12 01:26:18 -06:00
// send notification
2024-09-03 15:33:41 -06:00
function sendNotification ( ) {
2024-09-05 18:06:46 -06:00
sendAll (
2024-09-05 18:23:55 -06:00
ntfyEndpoint ,
2024-09-05 18:06:46 -06:00
ntfyTitle . value ,
ntfyMessage . value ,
ntfyAttach . value ,
ntfyClickAction . value
) ;
2024-09-03 16:58:14 -06:00
ntfyTitle . value = "" ;
ntfyMessage . value = "" ;
ntfyAttach . value = "" ;
ntfyClickAction . value = "" ;
2024-08-12 01:26:18 -06:00
}