Init author's note via function call instead of onready

This commit is contained in:
Cohee 2023-08-25 16:46:54 +03:00
parent e34e51226f
commit d68151f7e2
2 changed files with 8 additions and 6 deletions

View File

@ -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();
});

View File

@ -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'], "<span class='monospace'>(number)</span> sets an author's note insertion frequency", true, true);
registerSlashCommand('pos', setNotePositionCommand, ['position'], "(<span class='monospace'>chat</span> or <span class='monospace'>scenario</span>) sets an author's note position", true, true);
eventSource.on(event_types.CHAT_CHANGED, onChatChanged);
});
}