mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add author's note to floating prompt extension
This commit is contained in:
@ -6,6 +6,8 @@ const UPDATE_INTERVAL = 1000;
|
||||
|
||||
let lastMessageNumber = null;
|
||||
let promptInsertionInterval = 0;
|
||||
let promptInsertionPosition = 0;
|
||||
let promptInsertionDepth = 0;
|
||||
|
||||
function onExtensionFloatingPromptInput() {
|
||||
saveSettings();
|
||||
@ -16,24 +18,45 @@ function onExtensionFloatingIntervalInput() {
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function onExtensionFloatingDepthInput() {
|
||||
promptInsertionDepth = Number($(this).val());
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function onExtensionFloatingPositionInput(e) {
|
||||
promptInsertionPosition = e.target.value;
|
||||
saveSettings();
|
||||
}
|
||||
|
||||
function getLocalStorageKeys() {
|
||||
const context = getContext();
|
||||
const keySuffix = context.groupId ? context.groupId : `${context.characters[context.characterId].name}_${context.chatId}`;
|
||||
return { prompt: `extensions_floating_prompt_${keySuffix}`, interval: `extensions_floating_interval_${keySuffix}` };
|
||||
return {
|
||||
prompt: `extensions_floating_prompt_${keySuffix}`,
|
||||
interval: `extensions_floating_interval_${keySuffix}`,
|
||||
depth: `extensions_floating_depth_${keySuffix}`,
|
||||
position: `extensions_floating_position_${keySuffix}`,
|
||||
};
|
||||
}
|
||||
|
||||
function loadSettings() {
|
||||
const keys = getLocalStorageKeys();
|
||||
const prompt = localStorage.getItem(keys.prompt) ?? '';
|
||||
const interval = localStorage.getItem(keys.interval) ?? 0;
|
||||
const position = localStorage.getItem(keys.position) ?? 0;
|
||||
const depth = localStorage.getItem(keys.depth) ?? 0;
|
||||
$('#extension_floating_prompt').val(prompt).trigger('input');
|
||||
$('#extension_floating_interval').val(interval).trigger('input');
|
||||
$('#extension_floating_depth').val(depth).trigger('input');
|
||||
$(`input[name="extension_floating_position"][value="${position}"]`).prop('checked', true).trigger('change');
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
const keys = getLocalStorageKeys();
|
||||
localStorage.setItem(keys.prompt, $('#extension_floating_prompt').val());
|
||||
localStorage.setItem(keys.interval, $('#extension_floating_interval').val());
|
||||
localStorage.setItem(keys.depth, $('#extension_floating_depth').val());
|
||||
localStorage.setItem(keys.position, $('input:radio[name="extension_floating_position"]:checked').val());
|
||||
}
|
||||
|
||||
async function moduleWorker() {
|
||||
@ -61,21 +84,31 @@ async function moduleWorker() {
|
||||
const messagesTillInsertion = lastMessageNumber >= promptInsertionInterval
|
||||
? (lastMessageNumber % promptInsertionInterval)
|
||||
: (promptInsertionInterval - lastMessageNumber);
|
||||
const shouldAddPrompt = messagesTillInsertion == 0;
|
||||
const shouldAddPrompt = messagesTillInsertion == 0 && (promptInsertionPosition == 0 || promptInsertionDepth > 0);
|
||||
const prompt = shouldAddPrompt ? $('#extension_floating_prompt').val() : '';
|
||||
context.setExtensionPrompt(MODULE_NAME, prompt);
|
||||
context.setExtensionPrompt(MODULE_NAME, prompt, promptInsertionPosition, promptInsertionDepth);
|
||||
$('#extension_floating_counter').text(shouldAddPrompt ? 'This' : messagesTillInsertion);
|
||||
}
|
||||
|
||||
(function() {
|
||||
function addExtensionsSettings() {
|
||||
const settingsHtml = `
|
||||
<h4>Floating Prompt</h4>
|
||||
<h4>Floating Prompt / Author's Note</h4>
|
||||
<div class="floating_prompt_settings">
|
||||
<label for="extension_floating_prompt">Append the following text to the scenario:</label>
|
||||
<label for="extension_floating_prompt">Append the following text:</label>
|
||||
<textarea id="extension_floating_prompt" class="text_pole" rows="2"></textarea>
|
||||
<label>
|
||||
<input type="radio" name="extension_floating_position" value="0" />
|
||||
After scenario
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="extension_floating_position" value="1" />
|
||||
In-chat
|
||||
</label>
|
||||
<label for="extension_floating_interval">Every N messages <b>you</b> send (set to 0 to disable):</label>
|
||||
<input id="extension_floating_interval" class="text_pole" type="number" value="0" min="0" max="999" />
|
||||
<label for="extension_floating_interval">Insertion depth (for in-chat positioning, set to 0 to disable):</label>
|
||||
<input id="extension_floating_depth" class="text_pole" type="number" value="0" min="0" max="99" />
|
||||
<span>Appending the prompt in next: <span id="extension_floating_counter">No</span> message(s)</span>
|
||||
</div>
|
||||
`;
|
||||
@ -83,6 +116,8 @@ async function moduleWorker() {
|
||||
$('#extensions_settings').append(settingsHtml);
|
||||
$('#extension_floating_prompt').on('input', onExtensionFloatingPromptInput);
|
||||
$('#extension_floating_interval').on('input', onExtensionFloatingIntervalInput);
|
||||
$('#extension_floating_depth').on('input', onExtensionFloatingDepthInput);
|
||||
$('input[name="extension_floating_position"]').on('change', onExtensionFloatingPositionInput);
|
||||
}
|
||||
|
||||
addExtensionsSettings();
|
||||
|
Reference in New Issue
Block a user