Refactor banned strings kill switch functions into a single toggle function

c87e203b4a6840cf4a0e448dd6108e9f6597e735

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

1 files changed, +13 -18Ignore whitespace
public/scripts/textgen-settings.js+13 -18
@@ -458,22 +458,18 @@ function getCustomTokenBans() {
458458 };
459459}
460460
461-async function enableBannedStringsKillSwitch() {
461+/**
462- $('#send_banned_tokens_textgenerationwebui').prop('checked', true);
462+ * Sets the banned strings kill switch toggle.
463- $('#send_banned_tokens_label').find('.menu_button').addClass('toggleEnabled').prop('title', t`Banned tokens/strings are being sent in the request.`);
463+ * @param {boolean} isEnabled Kill switch state
464- settings.send_banned_tokens = true;
464+ * @param {string} title Label title
465- saveSettingsDebounced();
465+ */
466- return '';
466+function toggleBannedStringsKillSwitch(isEnabled, title) {
467-}
467+ $('#send_banned_tokens_textgenerationwebui').prop('checked', isEnabled);
468-
468+ $('#send_banned_tokens_label').find('.menu_button').toggleClass('toggleEnabled', isEnabled).prop('title', title);
469-async function disableBannedStringsKillSwitch() {
469+ settings.send_banned_tokens = isEnabled;
470- $('#send_banned_tokens_textgenerationwebui').prop('checked', false);
471- $('#send_banned_tokens_label').find('.menu_button').removeClass('toggleEnabled').prop('title', t`Banned tokens/strings are NOT being sent in the request.`);
472- settings.send_banned_tokens = false;
473470 saveSettingsDebounced();
474471 return '';
475472}
476-
477473/**
478474 * Calculates logit bias object from the logit bias list.
479475 * @returns {object} Logit bias object
@@ -618,11 +614,10 @@ function sortAphroditeItemsByOrder(orderArray) {
618614jQuery(function () {
619615 $('#send_banned_tokens_textgenerationwebui').on('change', function () {
620616 const checked = !!$(this).prop('checked');
621- if (checked) {
617+ toggleBannedStringsKillSwitch(checked,
622- enableBannedStringsKillSwitch();
618+ checked
623- } else {
619+ ? t`Banned tokens/strings are being sent in the request.`
624- disableBannedStringsKillSwitch();
620+ : t`Banned tokens/strings are NOT being sent in the request.`);
625- }
626621 });
627622
628623 $('#koboldcpp_order').sortable({