Fix A/N and CFG menus on first in the list

This commit is contained in:
Cohee 2025-02-28 10:26:03 +02:00
parent 76cb34fd06
commit 14aec43064
2 changed files with 99 additions and 100 deletions

View File

@ -389,49 +389,49 @@ export function setFloatingPrompt() {
} }
function onANMenuItemClick() { function onANMenuItemClick() {
if (selected_group || this_chid) { if (!selected_group && this_chid === undefined) {
//show AN if it's hidden
if ($('#floatingPrompt').css('display') !== 'flex') {
$('#floatingPrompt').addClass('resizing');
$('#floatingPrompt').css('display', 'flex');
$('#floatingPrompt').css('opacity', 0.0);
$('#floatingPrompt').transition({
opacity: 1.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#floatingPrompt').removeClass('resizing');
});
//auto-open the main AN inline drawer
if ($('#ANBlockToggle')
.siblings('.inline-drawer-content')
.css('display') !== 'block') {
$('#floatingPrompt').addClass('resizing');
$('#ANBlockToggle').click();
}
} else {
//hide AN if it's already displayed
$('#floatingPrompt').addClass('resizing');
$('#floatingPrompt').transition({
opacity: 0.0,
duration: animation_duration,
},
async function () {
await delay(50);
$('#floatingPrompt').removeClass('resizing');
});
setTimeout(function () {
$('#floatingPrompt').hide();
}, animation_duration);
}
//duplicate options menu close handler from script.js
//because this listener takes priority
$('#options').stop().fadeOut(animation_duration);
} else {
toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 }); toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 });
return;
} }
//show AN if it's hidden
if ($('#floatingPrompt').css('display') !== 'flex') {
$('#floatingPrompt').addClass('resizing');
$('#floatingPrompt').css('display', 'flex');
$('#floatingPrompt').css('opacity', 0.0);
$('#floatingPrompt').transition({
opacity: 1.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#floatingPrompt').removeClass('resizing');
});
//auto-open the main AN inline drawer
if ($('#ANBlockToggle')
.siblings('.inline-drawer-content')
.css('display') !== 'block') {
$('#floatingPrompt').addClass('resizing');
$('#ANBlockToggle').click();
}
} else {
//hide AN if it's already displayed
$('#floatingPrompt').addClass('resizing');
$('#floatingPrompt').transition({
opacity: 0.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#floatingPrompt').removeClass('resizing');
});
setTimeout(function () {
$('#floatingPrompt').hide();
}, animation_duration);
}
//duplicate options menu close handler from script.js
//because this listener takes priority
$('#options').stop().fadeOut(animation_duration);
} }
async function onChatChanged() { async function onChatChanged() {

View File

@ -40,7 +40,7 @@ function setCharCfg(tempValue, setting) {
name: avatarName, name: avatarName,
}; };
switch(setting) { switch (setting) {
case settingType.guidance_scale: case settingType.guidance_scale:
tempCharaCfg['guidance_scale'] = Number(tempValue); tempCharaCfg['guidance_scale'] = Number(tempValue);
break; break;
@ -69,8 +69,7 @@ function setCharCfg(tempValue, setting) {
if (!existingCharaCfg.useChara && if (!existingCharaCfg.useChara &&
(tempAssign.guidance_scale ?? 1.00) === 1.00 && (tempAssign.guidance_scale ?? 1.00) === 1.00 &&
(tempAssign.negative_prompt?.length ?? 0) === 0 && (tempAssign.negative_prompt?.length ?? 0) === 0 &&
(tempAssign.positive_prompt?.length ?? 0) === 0) (tempAssign.positive_prompt?.length ?? 0) === 0) {
{
extension_settings.cfg.chara.splice(existingCharaCfgIndex, 1); extension_settings.cfg.chara.splice(existingCharaCfgIndex, 1);
} }
} else if (avatarName && tempValue.length > 0) { } else if (avatarName && tempValue.length > 0) {
@ -92,7 +91,7 @@ function setCharCfg(tempValue, setting) {
} }
function setChatCfg(tempValue, setting) { function setChatCfg(tempValue, setting) {
switch(setting) { switch (setting) {
case settingType.guidance_scale: case settingType.guidance_scale:
chat_metadata[metadataKeys.guidance_scale] = tempValue; chat_metadata[metadataKeys.guidance_scale] = tempValue;
break; break;
@ -113,49 +112,49 @@ function setChatCfg(tempValue, setting) {
// TODO: Only change CFG when character is selected // TODO: Only change CFG when character is selected
function onCfgMenuItemClick() { function onCfgMenuItemClick() {
if (selected_group || this_chid) { if (!selected_group && this_chid === undefined) {
//show CFG config if it's hidden
if ($('#cfgConfig').css('display') !== 'flex') {
$('#cfgConfig').addClass('resizing');
$('#cfgConfig').css('display', 'flex');
$('#cfgConfig').css('opacity', 0.0);
$('#cfgConfig').transition({
opacity: 1.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#cfgConfig').removeClass('resizing');
});
//auto-open the main AN inline drawer
if ($('#CFGBlockToggle')
.siblings('.inline-drawer-content')
.css('display') !== 'block') {
$('#floatingPrompt').addClass('resizing');
$('#CFGBlockToggle').click();
}
} else {
//hide AN if it's already displayed
$('#cfgConfig').addClass('resizing');
$('#cfgConfig').transition({
opacity: 0.0,
duration: animation_duration,
},
async function () {
await delay(50);
$('#cfgConfig').removeClass('resizing');
});
setTimeout(function () {
$('#cfgConfig').hide();
}, animation_duration);
}
//duplicate options menu close handler from script.js
//because this listener takes priority
$('#options').stop().fadeOut(animation_duration);
} else {
toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 }); toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 });
return;
} }
//show CFG config if it's hidden
if ($('#cfgConfig').css('display') !== 'flex') {
$('#cfgConfig').addClass('resizing');
$('#cfgConfig').css('display', 'flex');
$('#cfgConfig').css('opacity', 0.0);
$('#cfgConfig').transition({
opacity: 1.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#cfgConfig').removeClass('resizing');
});
//auto-open the main AN inline drawer
if ($('#CFGBlockToggle')
.siblings('.inline-drawer-content')
.css('display') !== 'block') {
$('#floatingPrompt').addClass('resizing');
$('#CFGBlockToggle').click();
}
} else {
//hide AN if it's already displayed
$('#cfgConfig').addClass('resizing');
$('#cfgConfig').transition({
opacity: 0.0,
duration: animation_duration,
}, async function () {
await delay(50);
$('#cfgConfig').removeClass('resizing');
});
setTimeout(function () {
$('#cfgConfig').hide();
}, animation_duration);
}
//duplicate options menu close handler from script.js
//because this listener takes priority
$('#options').stop().fadeOut(animation_duration);
} }
async function onChatChanged() { async function onChatChanged() {
@ -288,7 +287,7 @@ export function initCfg() {
setTimeout(function () { $('#cfgConfig').hide(); }, animation_duration); setTimeout(function () { $('#cfgConfig').hide(); }, animation_duration);
}); });
$('#chat_cfg_guidance_scale').on('input', function() { $('#chat_cfg_guidance_scale').on('input', function () {
const numberValue = Number($(this).val()); const numberValue = Number($(this).val());
const success = setChatCfg(numberValue, settingType.guidance_scale); const success = setChatCfg(numberValue, settingType.guidance_scale);
if (success) { if (success) {
@ -296,15 +295,15 @@ export function initCfg() {
} }
}); });
$('#chat_cfg_negative_prompt').on('input', function() { $('#chat_cfg_negative_prompt').on('input', function () {
setChatCfg($(this).val(), settingType.negative_prompt); setChatCfg($(this).val(), settingType.negative_prompt);
}); });
$('#chat_cfg_positive_prompt').on('input', function() { $('#chat_cfg_positive_prompt').on('input', function () {
setChatCfg($(this).val(), settingType.positive_prompt); setChatCfg($(this).val(), settingType.positive_prompt);
}); });
$('#chara_cfg_guidance_scale').on('input', function() { $('#chara_cfg_guidance_scale').on('input', function () {
const value = $(this).val(); const value = $(this).val();
const success = setCharCfg(value, settingType.guidance_scale); const success = setCharCfg(value, settingType.guidance_scale);
if (success) { if (success) {
@ -312,34 +311,34 @@ export function initCfg() {
} }
}); });
$('#chara_cfg_negative_prompt').on('input', function() { $('#chara_cfg_negative_prompt').on('input', function () {
setCharCfg($(this).val(), settingType.negative_prompt); setCharCfg($(this).val(), settingType.negative_prompt);
}); });
$('#chara_cfg_positive_prompt').on('input', function() { $('#chara_cfg_positive_prompt').on('input', function () {
setCharCfg($(this).val(), settingType.positive_prompt); setCharCfg($(this).val(), settingType.positive_prompt);
}); });
$('#global_cfg_guidance_scale').on('input', function() { $('#global_cfg_guidance_scale').on('input', function () {
extension_settings.cfg.global.guidance_scale = Number($(this).val()); extension_settings.cfg.global.guidance_scale = Number($(this).val());
$('#global_cfg_guidance_scale_counter').val(extension_settings.cfg.global.guidance_scale.toFixed(2)); $('#global_cfg_guidance_scale_counter').val(extension_settings.cfg.global.guidance_scale.toFixed(2));
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('#global_cfg_negative_prompt').on('input', function() { $('#global_cfg_negative_prompt').on('input', function () {
extension_settings.cfg.global.negative_prompt = $(this).val(); extension_settings.cfg.global.negative_prompt = $(this).val();
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('#global_cfg_positive_prompt').on('input', function() { $('#global_cfg_positive_prompt').on('input', function () {
extension_settings.cfg.global.positive_prompt = $(this).val(); extension_settings.cfg.global.positive_prompt = $(this).val();
saveSettingsDebounced(); saveSettingsDebounced();
}); });
$('input[name="cfg_prompt_combine"]').on('input', function() { $('input[name="cfg_prompt_combine"]').on('input', function () {
const values = $('#cfgConfig').find('input[name="cfg_prompt_combine"]') const values = $('#cfgConfig').find('input[name="cfg_prompt_combine"]')
.filter(':checked') .filter(':checked')
.map(function() { return Number($(this).val()); }) .map(function () { return Number($(this).val()); })
.get() .get()
.filter((e) => !Number.isNaN(e)) || []; .filter((e) => !Number.isNaN(e)) || [];
@ -347,17 +346,17 @@ export function initCfg() {
saveMetadataDebounced(); saveMetadataDebounced();
}); });
$('#cfg_prompt_insertion_depth').on('input', function() { $('#cfg_prompt_insertion_depth').on('input', function () {
chat_metadata[metadataKeys.prompt_insertion_depth] = Number($(this).val()); chat_metadata[metadataKeys.prompt_insertion_depth] = Number($(this).val());
saveMetadataDebounced(); saveMetadataDebounced();
}); });
$('#cfg_prompt_separator').on('input', function() { $('#cfg_prompt_separator').on('input', function () {
chat_metadata[metadataKeys.prompt_separator] = $(this).val(); chat_metadata[metadataKeys.prompt_separator] = $(this).val();
saveMetadataDebounced(); saveMetadataDebounced();
}); });
$('#groupchat_cfg_use_chara').on('input', function() { $('#groupchat_cfg_use_chara').on('input', function () {
const checked = !!$(this).prop('checked'); const checked = !!$(this).prop('checked');
chat_metadata[metadataKeys.groupchat_individual_chars] = checked; chat_metadata[metadataKeys.groupchat_individual_chars] = checked;