From babb127aee992e4fecb03ae7fae12e80ba74ef47 Mon Sep 17 00:00:00 2001 From: valadaptive Date: Sat, 9 Dec 2023 18:41:51 -0500 Subject: [PATCH] Move NovelAI status functions over to the rest Have all the get(...)Status and event handler registrations in the same areas, rather than having the NovelAI ones far away. I want to eventually move all the API-specific stuff into separate modules, but this will make things cleaner for the time being. --- public/script.js | 68 ++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/public/script.js b/public/script.js index 3713d74e8..81bed0af0 100644 --- a/public/script.js +++ b/public/script.js @@ -968,6 +968,22 @@ async function getStatusTextgen() { return resultCheckStatus(); } +async function getStatusNovel() { + try { + const result = await loadNovelSubscriptionData(); + + if (!result) { + throw new Error('Could not load subscription data'); + } + + online_status = getNovelTier(); + } catch { + online_status = 'no_connection'; + } + + resultCheckStatus(); +} + export function startStatusLoading() { $('.api_loading').show(); $('.api_button').addClass('disabled'); @@ -6072,22 +6088,6 @@ export async function displayPastChats() { }); } -async function getStatusNovel() { - try { - const result = await loadNovelSubscriptionData(); - - if (!result) { - throw new Error('Could not load subscription data'); - } - - online_status = getNovelTier(); - } catch { - online_status = 'no_connection'; - } - - resultCheckStatus(); -} - function selectRightMenuWithAnimation(selectedMenuId) { const displayModes = { 'rm_group_chats_block': 'flex', @@ -8348,6 +8348,24 @@ jQuery(async function () { getStatusTextgen(); }); + $('#api_button_novel').on('click', async function (e) { + e.stopPropagation(); + const api_key_novel = String($('#api_key_novel').val()).trim(); + + if (api_key_novel.length) { + await writeSecret(SECRET_KEYS.NOVEL, api_key_novel); + } + + if (!secret_state[SECRET_KEYS.NOVEL]) { + console.log('No secret key saved for NovelAI'); + return; + } + + startStatusLoading(); + // Check near immediately rather than waiting for up to 90s + await getStatusNovel(); + }); + var button = $('#options_button'); var menu = $('#options'); @@ -9034,24 +9052,6 @@ jQuery(async function () { }); //Select chat - $('#api_button_novel').on('click', async function (e) { - e.stopPropagation(); - const api_key_novel = String($('#api_key_novel').val()).trim(); - - if (api_key_novel.length) { - await writeSecret(SECRET_KEYS.NOVEL, api_key_novel); - } - - if (!secret_state[SECRET_KEYS.NOVEL]) { - console.log('No secret key saved for NovelAI'); - return; - } - - startStatusLoading(); - // Check near immediately rather than waiting for up to 90s - await getStatusNovel(); - }); - //**************************CHARACTER IMPORT EXPORT*************************// $('#character_import_button').click(function () { $('#character_import_file').click();