Created
November 23, 2019 20:04
-
-
Save ngld/5d64b5247c5619b55ed3eb8c381c193d to your computer and use it in GitHub Desktop.
GP ETA test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf8"> | |
<title>Simple GP Tracker</title> | |
</head> | |
<body> | |
<div id="display"></div> | |
</body> | |
<script type="text/javascript" src="https://quisquous.github.io/cactbot/resources/common.js"></script> | |
<script type="text/javascript"> | |
let alerted = true; | |
let lastTen = []; | |
let lastGP = null; | |
let lastTime = null; | |
let gpRegen = 0; | |
let sound = new Audio('https://quisquous.github.io/cactbot/resources/sounds/BigWigs/Alert.ogg'); | |
let display = document.getElementById('display'); | |
addOverlayListener('onPlayerChangedEvent', (e) => { | |
if (lastGP !== null && lastTime !== null) { | |
lastTen.push((e.detail.currentGP - lastGP) / (Date.now() - lastTime)); | |
if (lastTen.length > 10) lastTen.shift(); | |
} | |
lastGP = e.detail.currentGP; | |
lastTime = Date.now(); | |
if (e.detail.currentGP < e.detail.maxGP) { | |
alerted = false; | |
} else if(!alerted) { | |
sound.play(); | |
alerted = true; | |
} | |
let eta = ''; | |
if (gpRegen > 0) { | |
let etaTime = (e.detail.maxGP - lastGP) / gpRegen / 1000; | |
let etaMinutes = Math.floor(etaTime / 60) + ''; | |
let etaSeconds = Math.floor(etaTime % 60) + ''; | |
if (etaMinutes.length < 2) etaMinutes = '0' + etaMinutes; | |
if (etaSeconds.length < 2) etaSeconds = '0' + etaSeconds; | |
eta = `ETA: ${etaMinutes}:${etaSeconds}`; | |
} | |
display.innerText = `${lastGP} / ${e.detail.maxGP} ${eta}`; | |
}); | |
setInterval(() => { | |
let gpSum = 0; | |
for (let part of lastTen) gpSum += part; | |
gpRegen = gpSum / lastTen.length; | |
}, 1000); | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment