Global Spinner

This commit is contained in:
bingus_violet 2024-04-20 16:46:12 -05:00
parent fb85cdf770
commit 17327706f5
3 changed files with 51 additions and 13 deletions

View file

@ -117,7 +117,7 @@ function converter(html, query) {
module.exports = { module.exports = {
getActivities: function () { getActivities: function () {
return activityToHTML.activitiesToHTML(lanyardData, cachedImages) return minify.minify(activityToHTML.activitiesToHTML(lanyardData, cachedImages))
}, },
middleWare: function (req, res, next) { middleWare: function (req, res, next) {
@ -218,7 +218,7 @@ function socketeer() {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.") console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => { setTimeout(() => {
socketeer() socketeer()
}, 3000); }, 30000);
}) })
function ping(dur) { function ping(dur) {

View file

@ -46,7 +46,7 @@
</div> </div>
</div> </div>
<p class="spinnyCount" style="display: none;">You have spun Violet <span class="localSpins">4</span> times!<br> <p class="spinnyCount" style="display: none;">You have spun Violet <span class="localSpins">4</span> times!<br>
Everyone has spun Violet <span class="globalSpins">3603250</span> times!</p> Everyone has spun Violet <span class="globalSpins">2</span> times!</p>
<hr> <hr>
<div> <div>
<p style="padding: 10px;">Hi! I'm Violet, a 15 year old web and game developer. I make server-sided dynamic websites, with no Javascript required! I'm currently making games in the Godot Engine, and my dynamic sites in NodeJS.</p> <p style="padding: 10px;">Hi! I'm Violet, a 15 year old web and game developer. I make server-sided dynamic websites, with no Javascript required! I'm currently making games in the Godot Engine, and my dynamic sites in NodeJS.</p>

View file

@ -2,6 +2,8 @@ var catsOnMars = new Audio("/snds/cats on mars.mp3")
var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3") var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3")
catsOnMars.loop = true catsOnMars.loop = true
var sock
var spins = 1 var spins = 1
var globalSpins = 0 var globalSpins = 0
@ -16,9 +18,12 @@ function spinLoop() {
if (spins > 1) { if (spins > 1) {
document.querySelector(".spinnyCount").style.display = "block" document.querySelector(".spinnyCount").style.display = "block"
document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1); document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1);
document.querySelector(".globalSpins").innerHTML = Math.ceil(spins - 1) + globalSpins;
} }
spins += 0.5 spins += 0.5
if (Math.round(spins) == spins && sock && sock.OPEN) {
sock.send(`{"op": 4}`)
console.log("Spin Sent!")
}
spinLoop() spinLoop()
} }
}, 1000); }, 1000);
@ -62,15 +67,48 @@ window.onload = function () {
var lastPong = Date.now() var lastPong = Date.now()
function socketeer() { function socketeer() {
var sock = new WebSocket('wss://api.violets-purgatory.dev') sock = new WebSocket('wss://api.violets-purgatory.dev')
sock.onmessage = (event) => {
console.log(event.data)
}
sock.addEventListener("open", () => { sock.addEventListener("open", () => {
console.log("AAAA") ping(30000)
})
sock.addEventListener("error", (error) => {
console.log(error)
})
sock.addEventListener("close", () => {
console.log("Connection Closed. Attempting Reconnect in 30 seconds.")
setTimeout(() => {
socketeer()
}, 30000);
})
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);
}
sock.addEventListener("message", async(data) => {
data = data.data
data = JSON.parse(data)
if (data.op == 4) {
globalSpins = data.spins
document.querySelector(".globalSpins").innerHTML = globalSpins;
} else if (data.op == 0) {
var discFetch = await (await fetch("/discHTML")).text()
document.querySelector("#activityHTML").innerHTML = discFetch
} else {
console.log(data)
}
}) })
} }