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

14aec430644bee10b5a2de71d663051c7f3c7a24

Cohee <18619528+Cohee1207@users.noreply.github.com>

2 files changed, +95 -96Ignore whitespace
public/scripts/authors-note.js+39 -39
@@ -389,49 +389,49 @@ export function setFloatingPrompt() {
389389}
390390
391391function onANMenuItemClick() {
392392 if (!selected_group ||&& this_chid === undefined) {
393- //show AN if it's hidden
393+ toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 });
394- if ($('#floatingPrompt').css('display') !== 'flex') {
394+ return;
395- $('#floatingPrompt').addClass('resizing');
395+ }
396- $('#floatingPrompt').css('display', 'flex');
396+
397- $('#floatingPrompt').css('opacity', 0.0);
397+ //show AN if it's hidden
398- $('#floatingPrompt').transition({
398+ if ($('#floatingPrompt').css('display') !== 'flex') {
399- opacity: 1.0,
399+ $('#floatingPrompt').addClass('resizing');
400- duration: animation_duration,
400+ $('#floatingPrompt').css('display', 'flex');
401- }, async function () {
401+ $('#floatingPrompt').css('opacity', 0.0);
402- await delay(50);
402+ $('#floatingPrompt').transition({
403- $('#floatingPrompt').removeClass('resizing');
403+ opacity: 1.0,
404- });
404+ duration: animation_duration,
405-
405+ }, async function () {
406- //auto-open the main AN inline drawer
406+ await delay(50);
407407 if ($('#ANBlockTogglefloatingPrompt').removeClass('resizing');
408- .siblings('.inline-drawer-content')
408+ });
409- .css('display') !== 'block') {
410- $('#floatingPrompt').addClass('resizing');
411- $('#ANBlockToggle').click();
412- }
413- } else {
414- //hide AN if it's already displayed
415- $('#floatingPrompt').addClass('resizing');
416- $('#floatingPrompt').transition({
417- opacity: 0.0,
418- duration: animation_duration,
419- },
420- async function () {
421- await delay(50);
422- $('#floatingPrompt').removeClass('resizing');
423- });
424- setTimeout(function () {
425- $('#floatingPrompt').hide();
426- }, animation_duration);
427409
410+ //auto-open the main AN inline drawer
411+ if ($('#ANBlockToggle')
412+ .siblings('.inline-drawer-content')
413+ .css('display') !== 'block') {
414+ $('#floatingPrompt').addClass('resizing');
415+ $('#ANBlockToggle').click();
428416 }
429- //duplicate options menu close handler from script.js
430- //because this listener takes priority
431- $('#options').stop().fadeOut(animation_duration);
432417 } else {
433- toastr.warning(t`Select a character before trying to use Author's Note`, '', { timeOut: 2000 });
418+ //hide AN if it's already displayed
419+ $('#floatingPrompt').addClass('resizing');
420+ $('#floatingPrompt').transition({
421+ opacity: 0.0,
422+ duration: animation_duration,
423+ }, async function () {
424+ await delay(50);
425+ $('#floatingPrompt').removeClass('resizing');
426+ });
427+ setTimeout(function () {
428+ $('#floatingPrompt').hide();
429+ }, animation_duration);
434430 }
431+
432+ //duplicate options menu close handler from script.js
433+ //because this listener takes priority
434+ $('#options').stop().fadeOut(animation_duration);
435435}
436436
437437async function onChatChanged() {
public/scripts/cfg-scale.js+56 -57
@@ -40,7 +40,7 @@ function setCharCfg(tempValue, setting) {
4040 name: avatarName,
4141 };
4242
4343 switch (setting) {
4444 case settingType.guidance_scale:
4545 tempCharaCfg['guidance_scale'] = Number(tempValue);
4646 break;
@@ -69,8 +69,7 @@ function setCharCfg(tempValue, setting) {
6969 if (!existingCharaCfg.useChara &&
7070 (tempAssign.guidance_scale ?? 1.00) === 1.00 &&
7171 (tempAssign.negative_prompt?.length ?? 0) === 0 &&
7272 (tempAssign.positive_prompt?.length ?? 0) === 0) {
73- {
7473 extension_settings.cfg.chara.splice(existingCharaCfgIndex, 1);
7574 }
7675 } else if (avatarName && tempValue.length > 0) {
@@ -92,7 +91,7 @@ function setCharCfg(tempValue, setting) {
9291}
9392
9493function setChatCfg(tempValue, setting) {
9594 switch (setting) {
9695 case settingType.guidance_scale:
9796 chat_metadata[metadataKeys.guidance_scale] = tempValue;
9897 break;
@@ -113,49 +112,49 @@ function setChatCfg(tempValue, setting) {
113112
114113// TODO: Only change CFG when character is selected
115114function onCfgMenuItemClick() {
116115 if (!selected_group ||&& this_chid === undefined) {
117- //show CFG config if it's hidden
116+ toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 });
118- if ($('#cfgConfig').css('display') !== 'flex') {
117+ return;
119- $('#cfgConfig').addClass('resizing');
118+ }
120- $('#cfgConfig').css('display', 'flex');
119+
121- $('#cfgConfig').css('opacity', 0.0);
120+ //show CFG config if it's hidden
122- $('#cfgConfig').transition({
121+ if ($('#cfgConfig').css('display') !== 'flex') {
123- opacity: 1.0,
122+ $('#cfgConfig').addClass('resizing');
124- duration: animation_duration,
123+ $('#cfgConfig').css('display', 'flex');
125- }, async function () {
124+ $('#cfgConfig').css('opacity', 0.0);
126- await delay(50);
125+ $('#cfgConfig').transition({
127- $('#cfgConfig').removeClass('resizing');
126+ opacity: 1.0,
128- });
127+ duration: animation_duration,
129-
128+ }, async function () {
130- //auto-open the main AN inline drawer
129+ await delay(50);
131130 if ($('#CFGBlockTogglecfgConfig').removeClass('resizing');
132- .siblings('.inline-drawer-content')
131+ });
133- .css('display') !== 'block') {
134- $('#floatingPrompt').addClass('resizing');
135- $('#CFGBlockToggle').click();
136- }
137- } else {
138- //hide AN if it's already displayed
139- $('#cfgConfig').addClass('resizing');
140- $('#cfgConfig').transition({
141- opacity: 0.0,
142- duration: animation_duration,
143- },
144- async function () {
145- await delay(50);
146- $('#cfgConfig').removeClass('resizing');
147- });
148- setTimeout(function () {
149- $('#cfgConfig').hide();
150- }, animation_duration);
151132
133+ //auto-open the main AN inline drawer
134+ if ($('#CFGBlockToggle')
135+ .siblings('.inline-drawer-content')
136+ .css('display') !== 'block') {
137+ $('#floatingPrompt').addClass('resizing');
138+ $('#CFGBlockToggle').click();
152139 }
153- //duplicate options menu close handler from script.js
154- //because this listener takes priority
155- $('#options').stop().fadeOut(animation_duration);
156140 } else {
157- toastr.warning('Select a character before trying to configure CFG', '', { timeOut: 2000 });
141+ //hide AN if it's already displayed
142+ $('#cfgConfig').addClass('resizing');
143+ $('#cfgConfig').transition({
144+ opacity: 0.0,
145+ duration: animation_duration,
146+ }, async function () {
147+ await delay(50);
148+ $('#cfgConfig').removeClass('resizing');
149+ });
150+ setTimeout(function () {
151+ $('#cfgConfig').hide();
152+ }, animation_duration);
153+
158154 }
155+ //duplicate options menu close handler from script.js
156+ //because this listener takes priority
157+ $('#options').stop().fadeOut(animation_duration);
159158}
160159
161160async function onChatChanged() {
@@ -288,7 +287,7 @@ export function initCfg() {
288287 setTimeout(function () { $('#cfgConfig').hide(); }, animation_duration);
289288 });
290289
291290 $('#chat_cfg_guidance_scale').on('input', function () {
292291 const numberValue = Number($(this).val());
293292 const success = setChatCfg(numberValue, settingType.guidance_scale);
294293 if (success) {
@@ -296,15 +295,15 @@ export function initCfg() {
296295 }
297296 });
298297
299298 $('#chat_cfg_negative_prompt').on('input', function () {
300299 setChatCfg($(this).val(), settingType.negative_prompt);
301300 });
302301
303302 $('#chat_cfg_positive_prompt').on('input', function () {
304303 setChatCfg($(this).val(), settingType.positive_prompt);
305304 });
306305
307306 $('#chara_cfg_guidance_scale').on('input', function () {
308307 const value = $(this).val();
309308 const success = setCharCfg(value, settingType.guidance_scale);
310309 if (success) {
@@ -312,34 +311,34 @@ export function initCfg() {
312311 }
313312 });
314313
315314 $('#chara_cfg_negative_prompt').on('input', function () {
316315 setCharCfg($(this).val(), settingType.negative_prompt);
317316 });
318317
319318 $('#chara_cfg_positive_prompt').on('input', function () {
320319 setCharCfg($(this).val(), settingType.positive_prompt);
321320 });
322321
323322 $('#global_cfg_guidance_scale').on('input', function () {
324323 extension_settings.cfg.global.guidance_scale = Number($(this).val());
325324 $('#global_cfg_guidance_scale_counter').val(extension_settings.cfg.global.guidance_scale.toFixed(2));
326325 saveSettingsDebounced();
327326 });
328327
329328 $('#global_cfg_negative_prompt').on('input', function () {
330329 extension_settings.cfg.global.negative_prompt = $(this).val();
331330 saveSettingsDebounced();
332331 });
333332
334333 $('#global_cfg_positive_prompt').on('input', function () {
335334 extension_settings.cfg.global.positive_prompt = $(this).val();
336335 saveSettingsDebounced();
337336 });
338337
339338 $('input[name="cfg_prompt_combine"]').on('input', function () {
340339 const values = $('#cfgConfig').find('input[name="cfg_prompt_combine"]')
341340 .filter(':checked')
342341 .map(function () { return Number($(this).val()); })
343342 .get()
344343 .filter((e) => !Number.isNaN(e)) || [];
345344
@@ -347,17 +346,17 @@ export function initCfg() {
347346 saveMetadataDebounced();
348347 });
349348
350349 $('#cfg_prompt_insertion_depth').on('input', function () {
351350 chat_metadata[metadataKeys.prompt_insertion_depth] = Number($(this).val());
352351 saveMetadataDebounced();
353352 });
354353
355354 $('#cfg_prompt_separator').on('input', function () {
356355 chat_metadata[metadataKeys.prompt_separator] = $(this).val();
357356 saveMetadataDebounced();
358357 });
359358
360359 $('#groupchat_cfg_use_chara').on('input', function () {
361360 const checked = !!$(this).prop('checked');
362361 chat_metadata[metadataKeys.groupchat_individual_chars] = checked;
363362