limepot-xyz/public/scripts/ntfy.js
2024-07-06 16:45:47 -06:00

50 lines
No EOL
1.9 KiB
JavaScript

// both
function send(message) {
let r = new XMLHttpRequest()
r.open("POST", "https://ntfy.ouroboros.group/beep", true)
r.setRequestHeader("Content-Type", "text/plain")
r.send(message)
}
// send notification
let ntfyInput = document.getElementById("ntfy-input")
function sendNotification() {
if (ntfyInput.value.length <= 0) return
send(ntfyInput.value)
ntfyInput.value = ""
}
ntfyInput.addEventListener("keyup", e => e.keyCode == 13 && send())
// send praise
let praiseSentence = document.getElementById("pp-sentence"),
praiseA = document.getElementById("pp-a"),
praiseAdj = document.getElementById("pp-adj"),
praiseNoun = document.getElementById("pp-noun"),
praiseAfter = document.getElementById("pp-after")
resetPraise()
praiseAdj.addEventListener("change", updatePraiseA)
praiseSentence.addEventListener("change", () => {
if (praiseSentence.selectedOptions[0].hasAttribute("data-suffix")) praiseAfter.innerText = praiseSentence.selectedOptions[0].attributes["data-suffix"].value
else praiseAfter.innerText = ""
updatePraiseA()
})
function sendPraise() {
if (praiseAdj.value == "0" || praiseNoun.value == "0") return
text = praiseSentence.selectedOptions[0].innerText
if (text) text += " " + praiseA.innerText + " "
text += praiseAdj.selectedOptions[0].innerText + " " + praiseNoun.selectedOptions[0].innerText
if (praiseAfter.innerText) text += praiseSentence.selectedOptions[0].attributes["data-suffix"].value
send(text)
resetPraise()
}
// praise helpers
function resetPraise() {
praiseSentence.value = "0"
praiseA.innerText = ""
praiseAdj.value = "0"
praiseNoun.value = "0"
praiseAfter.innerText = ""
}
function updatePraiseA() {
if (praiseSentence.value == "0") praiseA.innerText = ""
else if (praiseAdj.selectedOptions[0].hasAttribute("data-mod")) praiseA.innerText = "an"
else praiseA.innerText = "a"
}