From 4ecf2b9f2dfae200cd2d9f49d2caf63ebb074b3d Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:32:36 +0300 Subject: [PATCH] Fix stats init error --- public/script.js | 3 ++- public/scripts/stats.js | 29 +++++++++-------------------- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/public/script.js b/public/script.js index a97e2d286..fb752a042 100644 --- a/public/script.js +++ b/public/script.js @@ -1,5 +1,5 @@ import { humanizedDateTime, favsToHotswap, getMessageTimeStamp, dragElement, isMobile, initRossMods, } from "./scripts/RossAscends-mods.js"; -import { userStatsHandler, statMesProcess } from './scripts/stats.js'; +import { userStatsHandler, statMesProcess, initStats } from './scripts/stats.js'; import { generateKoboldWithStreaming, kai_settings, @@ -723,6 +723,7 @@ async function firstLoadInit() { initAuthorsNote(); initPersonas(); initRossMods(); + initStats(); } function checkOnlineStatus() { diff --git a/public/scripts/stats.js b/public/scripts/stats.js index 63829248d..e62b6e883 100644 --- a/public/scripts/stats.js +++ b/public/scripts/stats.js @@ -194,10 +194,10 @@ async function getStats() { /** * Asynchronously recreates the stats file from chat files. - * + * * Sends a POST request to the "/recreatestats" endpoint. If the request fails, * it displays an error notification and throws an error. - * + * * @throws {Error} If the request to recreate stats is unsuccessful. */ async function recreateStats() { @@ -330,23 +330,12 @@ async function statMesProcess(line, type, characters, this_chid, oldMesssage) { updateStats(); } -jQuery(() => { - function init() { - $(".rm_stats_button").on('click', function () { - characterStatsHandler(characters, this_chid); - }); - // Wait for debug functions to load, then add the refresh stats function - registerDebugFunction('refreshStats', 'Refresh Stat File', 'Recreates the stats file based on existing chat files', recreateStats); - } - - // Check every 100ms if registerDebugFunction is defined (this is bad lmao) - const interval = setInterval(() => { - if (typeof registerDebugFunction !== 'undefined') { - clearInterval(interval); // Clear the interval once the function is found - init(); // Initialize your code - } - }, 100); -}); - +export function initStats() { + $(".rm_stats_button").on('click', function () { + characterStatsHandler(characters, this_chid); + }); + // Wait for debug functions to load, then add the refresh stats function + registerDebugFunction('refreshStats', 'Refresh Stat File', 'Recreates the stats file based on existing chat files', recreateStats); +} export { userStatsHandler, characterStatsHandler, getStats, statMesProcess, charStats };