api.violets-purgatory.dev/static/main.js

107 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-04-18 23:50:10 -05:00
var catsOnMars = new Audio("/snds/cats on mars.mp3")
var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3")
catsOnMars.loop = true
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-20 12:24:46 -05:00
var spinWaiting = false
2024-04-19 09:31:26 -05:00
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
var pfp = document.querySelector(".pfp")
if (!catsOnMars.paused) {
2024-04-20 12:56:37 -05:00
if (spins > 1) {
document.querySelector(".spinnyCount").style.display = "block"
document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1);
document.querySelector(".globalSpins").innerHTML = Math.ceil(spins - 1) + globalSpins;
}
2024-04-20 12:24:46 -05:00
spins += 0.5
spinLoop()
}
2024-04-19 09:31:26 -05:00
}, 1000);
}
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
var pfp = document.querySelector(".pfp")
pfp.addEventListener("mousedown", () => {
2024-04-20 12:24:46 -05:00
if (!spinWaiting) {
spinLoop();
}
2024-04-18 23:50:10 -05:00
catsOnMars.play()
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 = () => {
if (catsOnMars.currentTime != 0) {
catsOnMars.currentTime = 0
catsOnMars.pause()
whipLash.currentTime = 0
whipLash.play()
pfp.style.animationName = "unset"
pfp.style.scale = "1"
}
}
2024-04-13 00:08:16 -05:00
}
2024-04-20 13:03:54 -05:00
var lastPong = Date.now()
2024-04-13 00:08:16 -05:00
function socketeer() {
2024-04-20 13:03:54 -05:00
var sock = new WebSocket('wss://beta.violets-purgatory.dev')
2024-04-13 00:08:16 -05:00
2024-04-20 13:03:54 -05:00
sock.onerror = (error) => {
2024-04-13 00:08:16 -05:00
console.log(error)
}
2024-04-20 13:03:54 -05:00
sock.onclose = () => {
2024-04-13 00:08:16 -05:00
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 3000);
}
function ping(dur) {
2024-04-20 13:03:54 -05:00
sock.send(JSON.stringify({
2024-04-13 00:08:16 -05:00
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
2024-04-20 13:03:54 -05:00
sock.close()
2024-04-13 00:08:16 -05:00
console.log("Max duration since last pong exceeded- Closing socket.")
}
}, dur);
}
2024-04-20 13:03:54 -05:00
sock.addEventListener("message", async (res) => {
2024-04-13 00:08:16 -05:00
var data = JSON.parse(res.data)
if (data.op == 1) {
console.log("Connected to Discord Websocket!")
ping(30000)
lastPong = Date.now()
} else if (data.op == 3) {
lastPong = Date.now()
}
var discStatusHTML = await (await fetch("/discHTML")).text();
2024-04-18 23:50:10 -05:00
2024-04-13 00:08:16 -05:00
var activityDiv = document.querySelector("#activityHTML")
activityDiv.innerHTML = discStatusHTML
})
}
socketeer()