Violets-Purgatory/static/main.js

264 lines
6.6 KiB
JavaScript
Raw Normal View History

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)"
}
}
2024-06-07 22:02:19 -05:00
const spinSpeed = 30
2024-06-19 12:29:59 -05:00
var spinFactor = 3
var date = new Date()
var teto = false
if (date.getDay() == 2) {
teto = true
}
2024-06-07 22:02:19 -05:00
var pfp
2024-06-19 12:29:59 -05:00
var music
if (teto) {
music = new Audio("/snds/Triple Baka.ogg")
} else {
music = new Audio("/snds/Lotus Waters.ogg")
}
2024-06-03 01:01:48 -05:00
music.loop = true
2024-06-20 23:34:24 -05:00
music.preservesPitch = false
2024-04-18 23:50:10 -05:00
2024-04-20 16:46:12 -05:00
var sock
2024-06-07 22:02:19 -05:00
var spins = 0
var lastSent = 0
2024-04-20 12:56:37 -05:00
var globalSpins = 0
2024-04-19 09:31:26 -05:00
2024-06-07 22:02:19 -05:00
var spinning = false
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
function resetPFP() {
pfp.src = "https://api.violets-purgatory.dev/v1/pfp?" + new Date().getTime()
}
2024-06-07 22:02:19 -05:00
function lerp(a, b, t) {
return a * (1 - t) + b * t
}
2024-06-29 17:34:54 -05:00
function gameTimeFormatter(seconds) {
seconds = Math.ceil(seconds / 1000)
var minutes = Math.ceil(seconds / 60)
var hours = Math.floor(minutes / 60)
if (seconds <= 60) {
return 'about ' + seconds + ' seconds'
} else if (minutes < 60) {
return `${minutes} Minutes`
}
return `${hours} hours and ${minutes % 60} minutes`
}
function timeFormatter(seconds) {
seconds = Math.ceil(seconds / 1000)
var minutes = Math.floor(seconds / 60)
if (seconds % 60 < 10) {
return `${minutes}:0${seconds % 60}`
} else {
return `${minutes}:${seconds % 60}`
}
}
function loop() {
2024-04-20 12:24:46 -05:00
spinWaiting = true
2024-04-19 09:31:26 -05:00
setTimeout(() => {
2024-04-20 12:24:46 -05:00
spinWaiting = false
2024-06-07 22:02:19 -05:00
if (spinning) {
2024-06-20 23:34:24 -05:00
// music.volume = 0.5
2024-06-19 12:29:59 -05:00
if (music.currentTime > 6.5 && teto) {
spinFactor = 0.25
} else {
spinFactor = 3
}
2024-06-20 23:34:24 -05:00
if (!teto) {
music.playbackRate = lerp(music.playbackRate, 1, 1/spinSpeed)
music.volume = lerp(music.volume, 0.5, 1/spinSpeed)
2024-04-20 12:56:37 -05:00
}
2024-06-19 12:29:59 -05:00
spins += 1/spinSpeed / spinFactor
2024-06-07 22:02:19 -05:00
if (Math.floor(spins) != lastSent && sock && sock.OPEN) {
2024-06-29 16:13:49 -05:00
console.log("RAH")
$(".globalSpins").text(globalSpins + 1)
2024-06-07 22:02:19 -05:00
lastSent = Math.floor(spins)
2024-06-03 01:01:48 -05:00
// resetPFP()
2024-04-20 16:46:12 -05:00
sock.send(`{"op": 4}`)
2024-06-20 23:34:24 -05:00
if (spins > 1) {
2024-06-25 18:35:58 -05:00
$(".spinnyCount").css("display", "block")
$(".localSpins").html(lastSent);
2024-06-20 23:34:24 -05:00
}
2024-04-20 16:46:12 -05:00
}
2024-06-07 22:02:19 -05:00
} else {
2024-06-20 23:34:24 -05:00
if (!teto) {
music.playbackRate = lerp(music.playbackRate, 0.5, 1/spinSpeed)
music.volume = lerp(music.volume, -0, 3/spinSpeed)
} else {
music.pause()
music.currentTime = 1.5
}
2024-06-11 23:20:57 -05:00
spins = lerp(spins, Math.round(spins), 1 / spinSpeed * 3)
2024-04-20 12:24:46 -05:00
}
2024-06-25 18:35:58 -05:00
$(".pfp").css("rotate", (spins * 360) + "deg")
2024-06-29 17:34:54 -05:00
$(".durationBarFormatter").each((_, item) => {
item = $(item)
item.text(`${timeFormatter((Date.now() - item.attr("data-start")))}/${timeFormatter((item.attr("data-end") - item.attr("data-start")))}`)
})
$(".timeEstimate").each((_, item) => {
item = $(item)
item.text(gameTimeFormatter(Date.now() - item.attr("data-start")))
})
2024-06-29 18:36:27 -05:00
$(".endEstimate").each((_, item) => {
item = $(item)
item.text(timeFormatter((item.attr("data-end") - Date.now())))
})
2024-06-29 17:34:54 -05:00
loop()
2024-06-07 22:02:19 -05:00
}, 1/spinSpeed * 1000);
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 () {
2024-06-25 19:02:29 -05:00
$("#jsEnabled").text("true")
2024-06-25 18:35:58 -05:00
pfp = $(".pfp")
2024-04-18 23:50:10 -05:00
2024-06-29 17:34:54 -05:00
loop()
2024-06-07 22:02:19 -05:00
2024-06-25 18:35:58 -05:00
pfp.on("mousedown", () => {
2024-06-07 22:02:19 -05:00
// if (!spinWaiting) {
// spinLoop();
// }
2024-06-03 01:01:48 -05:00
music.play()
2024-04-18 23:50:10 -05:00
2024-06-07 22:02:19 -05:00
spinning = true
2024-06-25 18:35:58 -05:00
pfp.css("transition", "")
2024-04-18 23:50:10 -05:00
2024-06-25 18:35:58 -05:00
pfp.css("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) {
2024-06-07 22:02:19 -05:00
// music.currentTime = 0
// music.pause()
// whipLash.currentTime = 0
// whipLash.play()
spinning = false
2024-04-18 23:50:10 -05:00
2024-06-11 23:20:57 -05:00
// pfp.style.transition = "all 3s cubic-bezier(0.39, 0.575, 0.565, 1)"
2024-04-20 16:46:12 -05:00
2024-06-25 18:35:58 -05:00
pfp.css("scale", "1")
2024-04-18 23:50:10 -05:00
}
}
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.")
2024-06-25 19:02:29 -05:00
$("#apiConnected").text("false")
2024-04-20 16:46:12 -05:00
setTimeout(() => {
socketeer()
}, 30000);
})
sock.addEventListener("message", async (data) => {
2024-04-20 16:46:12 -05:00
data = data.data
data = JSON.parse(data)
if (data.op == 4) {
2024-06-25 19:02:29 -05:00
$("#apiConnected").text("true")
2024-04-20 16:46:12 -05:00
globalSpins = data.spins
2024-04-22 07:56:44 -05:00
if (firsttimeDebounce == true) {
firsttimeDebounce = false
2024-06-25 18:35:58 -05:00
$(".globalSpins").innerHTML = globalSpins + 1;
2024-04-22 07:56:44 -05:00
} else {
2024-06-25 18:35:58 -05:00
$(".globalSpins").innerHTML = globalSpins;
2024-04-22 07:56:44 -05:00
}
2024-04-20 16:46:12 -05:00
} else if (data.op == 0) {
var lanyard = data.d
var statusInfo = discStatuses[lanyard.discord_status]
2024-06-25 18:35:58 -05:00
var lastStatus = $(".statusColor")
if (lastStatus.innerHTML != statusInfo.text) {
lastStatus.innerHTML = statusInfo.text
2024-06-25 18:35:58 -05:00
lastStatus.css("color", statusInfo.color)
2024-06-25 18:35:58 -05:00
pfp.css("borderColor", statusInfo.color)
resetPFP()
}
2024-06-08 17:04:53 -05:00
// if (lanyard.activities[0] && lanyard.activities[0].type == 4) {
// document.querySelector(".customStatus").innerHTML = `<hr><img src=""><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-06-25 18:35:58 -05:00
$("#activityHtml").html(discFetch)
} 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
})
}