diff --git a/public/script.js b/public/script.js index 728a446f2..b6ed6cfd2 100644 --- a/public/script.js +++ b/public/script.js @@ -155,7 +155,7 @@ import { } from "./scripts/secrets.js"; import { EventEmitter } from './lib/eventemitter.js'; import { markdownExclusionExt } from "./scripts/showdown-exclusion.js"; -import { NOTE_MODULE_NAME, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from "./scripts/authors-note.js"; +import { NOTE_MODULE_NAME, initAuthorsNote, metadata_keys, setFloatingPrompt, shouldWIAddPrompt } from "./scripts/authors-note.js"; import { getDeviceInfo } from "./scripts/RossAscends-mods.js"; import { registerPromptManagerMigration } from "./scripts/PromptManager.js"; import { getRegexedString, regex_placement } from "./scripts/extensions/regex/engine.js"; @@ -2761,7 +2761,7 @@ async function Generate(type, { automatic_trigger, force_name2, resolve, reject, const anchorDepth = Math.abs(index - finalMesSend.length + 1); // NOTE: Depth injected here! const extensionAnchor = getExtensionPrompt(extension_prompt_types.IN_CHAT, anchorDepth); - + if (anchorDepth > 0 && extensionAnchor && extensionAnchor.length) { mesItem.extensionPrompts.push(extensionAnchor); } @@ -9023,5 +9023,6 @@ $(document).ready(function () { }); // Added here to prevent execution before script.js is loaded and get rid of quirky timeouts + initAuthorsNote(); initRossMods(); }); diff --git a/public/scripts/authors-note.js b/public/scripts/authors-note.js index 03a2d1d1c..21b477543 100644 --- a/public/scripts/authors-note.js +++ b/public/scripts/authors-note.js @@ -389,10 +389,11 @@ function onChatChanged() { $('#extension_floating_default_token_counter').text(tokenCounter3); } -// Inject extension when extensions_activating is fired +/** + * Inject author's note options and setup event listeners. + */ // Inserts the extension first since it's statically imported -jQuery(async () => { - await waitUntilCondition(() => eventSource !== undefined); +export function initAuthorsNote() { $('#extension_floating_prompt').on('input', onExtensionFloatingPromptInput); $('#extension_floating_interval').on('input', onExtensionFloatingIntervalInput); $('#extension_floating_depth').on('input', onExtensionFloatingDepthInput); @@ -419,4 +420,4 @@ jQuery(async () => { registerSlashCommand('freq', setNoteIntervalCommand, ['interval'], "(number) – sets an author's note insertion frequency", true, true); registerSlashCommand('pos', setNotePositionCommand, ['position'], "(chat or scenario) – sets an author's note position", true, true); eventSource.on(event_types.CHAT_CHANGED, onChatChanged); -}); +}