2024-05-26 15:32:26 -05:00
|
|
|
const discStatuses = {
|
|
|
|
"online": {
|
|
|
|
"text": "Online",
|
|
|
|
"color": "rgb(100, 255, 100)"
|
|
|
|
},
|
|
|
|
"dnd": {
|
|
|
|
"text": "DND",
|
|
|
|
"color": "rgb(255, 100, 100)"
|
|
|
|
},
|
|
|
|
"idle": {
|
|
|
|
"text": "Idle",
|
|
|
|
"color": "rgb(255, 255, 75)"
|
|
|
|
},
|
|
|
|
"offline": {
|
|
|
|
"text": "",
|
|
|
|
"color": "rgb(175, 175, 200)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var pfp
|
|
|
|
|
2024-06-03 01:01:48 -05:00
|
|
|
var music = new Audio("/snds/Lotus Waters.ogg")
|
2024-04-18 23:50:10 -05:00
|
|
|
var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3")
|
2024-06-03 01:01:48 -05:00
|
|
|
music.loop = true
|
|
|
|
music.volume = 0.45
|
2024-04-28 12:30:40 -05:00
|
|
|
whipLash.volume = 0.25
|
2024-04-18 23:50:10 -05:00
|
|
|
|
2024-04-20 16:46:12 -05:00
|
|
|
var sock
|
|
|
|
|
2024-04-19 09:31:26 -05:00
|
|
|
var spins = 1
|
2024-04-20 12:56:37 -05:00
|
|
|
var globalSpins = 0
|
2024-04-19 09:31:26 -05:00
|
|
|
|
2024-04-22 07:56:44 -05:00
|
|
|
var firsttimeDebounce = true
|
|
|
|
|
2024-04-20 12:24:46 -05:00
|
|
|
var spinWaiting = false
|
2024-04-19 09:31:26 -05:00
|
|
|
|
2024-05-26 15:32:26 -05:00
|
|
|
function resetPFP() {
|
|
|
|
pfp.src = "https://api.violets-purgatory.dev/v1/pfp?" + new Date().getTime()
|
|
|
|
}
|
|
|
|
|
2024-04-20 12:24:46 -05:00
|
|
|
function spinLoop() {
|
|
|
|
spinWaiting = true
|
2024-04-19 09:31:26 -05:00
|
|
|
setTimeout(() => {
|
2024-04-20 12:24:46 -05:00
|
|
|
spinWaiting = false
|
2024-06-03 01:01:48 -05:00
|
|
|
if (!music.paused) {
|
2024-04-20 12:56:37 -05:00
|
|
|
if (spins > 1) {
|
|
|
|
document.querySelector(".spinnyCount").style.display = "block"
|
2024-04-20 16:46:12 -05:00
|
|
|
document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1);
|
2024-04-20 12:56:37 -05:00
|
|
|
}
|
2024-04-20 12:24:46 -05:00
|
|
|
spins += 0.5
|
2024-04-20 16:46:12 -05:00
|
|
|
if (Math.round(spins) == spins && sock && sock.OPEN) {
|
2024-06-03 01:01:48 -05:00
|
|
|
// resetPFP()
|
2024-04-20 16:46:12 -05:00
|
|
|
sock.send(`{"op": 4}`)
|
|
|
|
console.log("Spin Sent!")
|
|
|
|
}
|
2024-04-20 12:24:46 -05:00
|
|
|
spinLoop()
|
|
|
|
}
|
2024-06-03 01:01:48 -05:00
|
|
|
}, 1500);
|
2024-04-19 09:31:26 -05:00
|
|
|
}
|
|
|
|
|
2024-04-13 00:08:16 -05:00
|
|
|
window.onbeforeunload = function () {
|
|
|
|
window.scrollTo(0, 0);
|
2024-04-12 23:37:21 -05:00
|
|
|
}
|
|
|
|
|
2024-04-13 00:08:16 -05:00
|
|
|
window.onload = function () {
|
|
|
|
window.scrollTo(0, 0);
|
2024-04-18 23:50:10 -05:00
|
|
|
|
2024-05-26 15:32:26 -05:00
|
|
|
pfp = document.querySelector(".pfp")
|
2024-04-18 23:50:10 -05:00
|
|
|
|
|
|
|
pfp.addEventListener("mousedown", () => {
|
2024-04-20 12:24:46 -05:00
|
|
|
if (!spinWaiting) {
|
|
|
|
spinLoop();
|
|
|
|
}
|
2024-06-03 01:01:48 -05:00
|
|
|
music.play()
|
2024-04-18 23:50:10 -05:00
|
|
|
|
|
|
|
pfp.style.animationName = "spinny"
|
|
|
|
|
2024-04-20 12:56:37 -05:00
|
|
|
pfp.style.scale = "1.1"
|
2024-04-18 23:50:10 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
document.body.onmouseup = () => {
|
2024-06-03 01:01:48 -05:00
|
|
|
if (music.currentTime != 0) {
|
|
|
|
music.currentTime = 0
|
|
|
|
music.pause()
|
2024-04-18 23:50:10 -05:00
|
|
|
|
|
|
|
whipLash.currentTime = 0
|
|
|
|
whipLash.play()
|
2024-04-20 16:46:12 -05:00
|
|
|
|
2024-04-18 23:50:10 -05:00
|
|
|
pfp.style.animationName = "unset"
|
|
|
|
pfp.style.scale = "1"
|
|
|
|
}
|
|
|
|
}
|
2024-04-20 15:39:25 -05:00
|
|
|
socketeer()
|
2024-04-13 00:08:16 -05:00
|
|
|
}
|
|
|
|
|
2024-04-20 13:03:54 -05:00
|
|
|
var lastPong = Date.now()
|
|
|
|
|
2024-04-20 17:00:58 -05:00
|
|
|
function ping(dur) {
|
|
|
|
sock.send(JSON.stringify({
|
|
|
|
op: 3
|
|
|
|
}))
|
|
|
|
setTimeout(() => {
|
|
|
|
ping(dur)
|
|
|
|
if (Date.now() - lastPong > 120000) {
|
|
|
|
sock.close()
|
|
|
|
console.log("Max duration since last pong exceeded- Closing socket.")
|
|
|
|
}
|
|
|
|
}, dur);
|
|
|
|
}
|
|
|
|
|
2024-04-13 00:08:16 -05:00
|
|
|
function socketeer() {
|
2024-04-20 16:46:12 -05:00
|
|
|
sock = new WebSocket('wss://api.violets-purgatory.dev')
|
2024-04-13 00:08:16 -05:00
|
|
|
|
2024-04-20 16:46:12 -05:00
|
|
|
sock.addEventListener("open", () => {
|
|
|
|
ping(30000)
|
|
|
|
})
|
|
|
|
|
|
|
|
sock.addEventListener("error", (error) => {
|
|
|
|
console.log(error)
|
|
|
|
})
|
|
|
|
|
|
|
|
sock.addEventListener("close", () => {
|
|
|
|
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
|
|
|
|
setTimeout(() => {
|
|
|
|
socketeer()
|
|
|
|
}, 30000);
|
|
|
|
})
|
|
|
|
|
2024-05-26 15:32:26 -05:00
|
|
|
sock.addEventListener("message", async (data) => {
|
2024-04-20 16:46:12 -05:00
|
|
|
data = data.data
|
|
|
|
data = JSON.parse(data)
|
|
|
|
if (data.op == 4) {
|
|
|
|
globalSpins = data.spins
|
2024-04-22 07:56:44 -05:00
|
|
|
if (firsttimeDebounce == true) {
|
|
|
|
firsttimeDebounce = false
|
|
|
|
document.querySelector(".globalSpins").innerHTML = globalSpins + 1;
|
|
|
|
} else {
|
|
|
|
document.querySelector(".globalSpins").innerHTML = globalSpins;
|
|
|
|
}
|
2024-04-20 16:46:12 -05:00
|
|
|
} else if (data.op == 0) {
|
2024-05-26 15:32:26 -05:00
|
|
|
var lanyard = data.d
|
|
|
|
var statusInfo = discStatuses[lanyard.discord_status]
|
|
|
|
var lastStatus = document.querySelector(".statusColor")
|
|
|
|
|
|
|
|
if (lastStatus.innerHTML != statusInfo.text) {
|
|
|
|
lastStatus.innerHTML = statusInfo.text
|
|
|
|
lastStatus.style.color = statusInfo.color
|
|
|
|
|
|
|
|
pfp.style.borderColor = lastStatus.style.color
|
|
|
|
|
|
|
|
resetPFP()
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lanyard.activities[0] && lanyard.activities[0].type == 4) {
|
|
|
|
document.querySelector(".customStatus").innerHTML = `<hr><p>${lanyard.activities[0].state}</p>`
|
|
|
|
} else {
|
|
|
|
document.querySelector(".customStatus").innerHTML = ""
|
|
|
|
}
|
|
|
|
|
2024-04-20 16:46:12 -05:00
|
|
|
var discFetch = await (await fetch("/discHTML")).text()
|
2024-04-22 09:46:29 -05:00
|
|
|
document.querySelector("#activityHtml").innerHTML = discFetch
|
2024-05-20 10:45:24 -05:00
|
|
|
} else if (data.op == 3) {
|
2024-04-20 17:00:58 -05:00
|
|
|
lastPong = Date.now()
|
2024-04-20 16:46:12 -05:00
|
|
|
} else {
|
|
|
|
console.log(data)
|
|
|
|
}
|
2024-04-20 15:39:25 -05:00
|
|
|
})
|
|
|
|
}
|