diff --git a/pageUpdater.js b/pageUpdater.js index 1aad535..7134e06 100644 --- a/pageUpdater.js +++ b/pageUpdater.js @@ -117,7 +117,7 @@ function converter(html, query) { module.exports = { getActivities: function () { - return activityToHTML.activitiesToHTML(lanyardData, cachedImages) + return minify.minify(activityToHTML.activitiesToHTML(lanyardData, cachedImages)) }, middleWare: function (req, res, next) { @@ -218,7 +218,7 @@ function socketeer() { console.log("Connection Closed. Attempting Reconnect in 30 seconds.") setTimeout(() => { socketeer() - }, 3000); + }, 30000); }) function ping(dur) { diff --git a/static/index.html b/static/index.html index f22950e..ed6822b 100644 --- a/static/index.html +++ b/static/index.html @@ -46,7 +46,7 @@ + Everyone has spun Violet 2 times!


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.

diff --git a/static/main.js b/static/main.js index 179bdae..01718f0 100644 --- a/static/main.js +++ b/static/main.js @@ -2,6 +2,8 @@ var catsOnMars = new Audio("/snds/cats on mars.mp3") var whipLash = new Audio("/snds/johnny-test-whip-crack.mp3") catsOnMars.loop = true +var sock + var spins = 1 var globalSpins = 0 @@ -15,10 +17,13 @@ function spinLoop() { if (!catsOnMars.paused) { 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; + document.querySelector(".localSpins").innerHTML = Math.ceil(spins - 1); } spins += 0.5 + if (Math.round(spins) == spins && sock && sock.OPEN) { + sock.send(`{"op": 4}`) + console.log("Spin Sent!") + } spinLoop() } }, 1000); @@ -51,7 +56,7 @@ window.onload = function () { whipLash.currentTime = 0 whipLash.play() - + pfp.style.animationName = "unset" pfp.style.scale = "1" } @@ -62,15 +67,48 @@ window.onload = function () { var lastPong = Date.now() function socketeer() { - var sock = new WebSocket('wss://api.violets-purgatory.dev') - - sock.onmessage = (event) => { - console.log(event.data) - } + sock = new WebSocket('wss://api.violets-purgatory.dev') 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) + } }) } \ No newline at end of file