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

99 lines
2.4 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
function notif(text) {
document.body.innerHTML = "apple"
}
function secondLoop() {
2024-04-19 11:14:09 -05:00
var pfp = document.querySelector(".pfp")
2024-04-19 09:31:26 -05:00
if (!catsOnMars.paused) {
spins += 0.5
2024-04-19 11:14:09 -05:00
document.querySelector(".spinnyCount").innerHTML = `You have spun Violet ${Math.floor(spins)} times!` + pfp.style.animationDuration
2024-04-19 09:31:26 -05:00
}
setTimeout(() => {
secondLoop()
}, 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-19 09:31:26 -05:00
secondLoop()
2024-04-18 23:50:10 -05:00
var pfp = document.querySelector(".pfp")
pfp.addEventListener("mousedown", () => {
catsOnMars.play()
pfp.style.animationName = "spinny"
pfp.style.scale = "1.2"
})
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
}
function socketeer() {
var lanyard = new WebSocket('wss://api.violets-purgatory.dev')
lanyard.onerror = (error) => {
console.log(error)
}
lanyard.onclose = () => {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 3000);
}
function ping(dur) {
lanyard.send(JSON.stringify({
op: 3
}))
setTimeout(() => {
ping(dur)
if (Date.now() - lastPong > 120000) {
lanyard.close()
console.log("Max duration since last pong exceeded- Closing socket.")
}
}, dur);
}
lanyard.addEventListener("message", async (res) => {
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()