From b63e46a441b66e79021c55cdfb5a095aa5b4e2b7 Mon Sep 17 00:00:00 2001 From: BatteRaquette581 <84451047+BatteRaquette581@users.noreply.github.com> Date: Fri, 8 Mar 2024 22:22:56 +0100 Subject: [PATCH] Create tps_counter.js --- mods/tps_counter.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 mods/tps_counter.js diff --git a/mods/tps_counter.js b/mods/tps_counter.js new file mode 100644 index 00000000..06764915 --- /dev/null +++ b/mods/tps_counter.js @@ -0,0 +1,44 @@ +/* +MIT License + +Copyright (c) 2024 BatteRaquette58 (a.k.a BatteRaquette581) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +const old_tick = tick + +let tps_counter = document.createElement("span") +tps_counter.id = "stat-tps-counter" +tps_counter.classList = ["stat",] +const total_wrapper = document.getElementById("totalWrapper") +const first_child = total_wrapper.childNodes[0] +total_wrapper.insertBefore(tps_counter, first_child) +total_wrapper.insertBefore(document.createElement("br"), first_child) + +tick = () => { + const t1 = Date.now() + old_tick() + const t2 = Date.now() + let time_elapsed = t2 - t1 + tps_counter.innerText = Math.min(tps, 1 / (time_elapsed / 1000)) +} + +window.clearInterval(tickInterval) +tickInterval = window.setInterval(tick, 1000 / tps)