Use saved settings for more properties

87ff99709f9f02f10fe21aadaee6359969ceecbb

d-ber <davide.bertalero@studenti.unimi.it>

1 files changed, +8 -88Showing whitespace changes
public/scripts/power-user.js+8 -88
@@ -302,8 +302,6 @@ export let context_presets = [];
302302
303const storage_keys = {303const storage_keys = {
304 chat_display: 'TavernAI_chat_display',304 chat_display: 'TavernAI_chat_display',
305 chat_width: 'chat_width',
306 font_scale: 'TavernAI_font_scale',
307305
308 main_text_color: 'TavernAI_main_text_color',306 main_text_color: 'TavernAI_main_text_color',
309 italics_text_color: 'TavernAI_italics_text_color',307 italics_text_color: 'TavernAI_italics_text_color',
@@ -313,7 +311,6 @@ const storage_keys = {
313 chat_tint_color: 'TavernAI_chat_tint_color',311 chat_tint_color: 'TavernAI_chat_tint_color',
314 user_mes_blur_tint_color: 'TavernAI_user_mes_blur_tint_color',312 user_mes_blur_tint_color: 'TavernAI_user_mes_blur_tint_color',
315 bot_mes_blur_tint_color: 'TavernAI_bot_mes_blur_tint_color',313 bot_mes_blur_tint_color: 'TavernAI_bot_mes_blur_tint_color',
316 blur_strength: 'TavernAI_blur_strength',
317 shadow_color: 'TavernAI_shadow_color',314 shadow_color: 'TavernAI_shadow_color',
318 shadow_width: 'TavernAI_shadow_width',315 shadow_width: 'TavernAI_shadow_width',
319 border_color: 'TavernAI_border_color',316 border_color: 'TavernAI_border_color',
@@ -321,17 +318,9 @@ const storage_keys = {
321 custom_css: 'TavernAI_custom_css',318 custom_css: 'TavernAI_custom_css',
322319
323 waifuMode: 'TavernAI_waifuMode',320 waifuMode: 'TavernAI_waifuMode',
324 movingUI: 'TavernAI_movingUI',
325321
326 timer_enabled: 'TimerEnabled',
327 timestamps_enabled: 'TimestampsEnabled',
328 timestamp_model_icon: 'TimestampModelIcon',322 timestamp_model_icon: 'TimestampModelIcon',
329 mesIDDisplay_enabled: 'mesIDDisplayEnabled',
330 hideChatAvatars_enabled: 'hideChatAvatarsEnabled',
331 message_token_count_enabled: 'MessageTokenCountEnabled',323 message_token_count_enabled: 'MessageTokenCountEnabled',
332 expand_message_actions: 'ExpandMessageActions',
333 enableZenSliders: 'enableZenSliders',
334 enableLabMode: 'enableLabMode',
335 reduced_motion: 'reduced_motion',324 reduced_motion: 'reduced_motion',
336 compact_input_area: 'compact_input_area',325 compact_input_area: 'compact_input_area',
337 auto_connect_legacy: 'AutoConnectEnabled',326 auto_connect_legacy: 'AutoConnectEnabled',
@@ -460,15 +449,11 @@ function switchHotswap() {
460}449}
461450
462function switchTimer() {451function switchTimer() {
463 const value = localStorage.getItem(storage_keys.timer_enabled);
464 power_user.timer_enabled = value === null ? true : value == 'true';
465 $('body').toggleClass('no-timer', !power_user.timer_enabled);452 $('body').toggleClass('no-timer', !power_user.timer_enabled);
466 $('#messageTimerEnabled').prop('checked', power_user.timer_enabled);453 $('#messageTimerEnabled').prop('checked', power_user.timer_enabled);
467}454}
468455
469function switchTimestamps() {456function switchTimestamps() {
470 const value = localStorage.getItem(storage_keys.timestamps_enabled);
471 power_user.timestamps_enabled = value === null ? true : value == 'true';
472 $('body').toggleClass('no-timestamps', !power_user.timestamps_enabled);457 $('body').toggleClass('no-timestamps', !power_user.timestamps_enabled);
473 $('#messageTimestampsEnabled').prop('checked', power_user.timestamps_enabled);458 $('#messageTimestampsEnabled').prop('checked', power_user.timestamps_enabled);
474}459}
@@ -488,30 +473,16 @@ function switchTokenCount() {
488}473}
489474
490function switchMesIDDisplay() {475function switchMesIDDisplay() {
491 const value = localStorage.getItem(storage_keys.mesIDDisplay_enabled);
492 power_user.mesIDDisplay_enabled = value === null ? true : value == 'true';
493 /* console.log(`
494 localstorage value:${value},
495 poweruser before:${before},
496 poweruser after:${power_user.mesIDDisplay_enabled}`) */
497 $('body').toggleClass('no-mesIDDisplay', !power_user.mesIDDisplay_enabled);476 $('body').toggleClass('no-mesIDDisplay', !power_user.mesIDDisplay_enabled);
498 $('#mesIDDisplayEnabled').prop('checked', power_user.mesIDDisplay_enabled);477 $('#mesIDDisplayEnabled').prop('checked', power_user.mesIDDisplay_enabled);
499}478}
500479
501function switchHideChatAvatars() {480function switchHideChatAvatars() {
502 const value = localStorage.getItem(storage_keys.hideChatAvatars_enabled);
503 power_user.hideChatAvatars_enabled = value === null ? false : value == 'true';
504 /*console.log(`
505 localstorage value:${value},
506 poweruser after:${power_user.hideChatAvatars_enabled}`)
507 */
508 $('body').toggleClass('hideChatAvatars', power_user.hideChatAvatars_enabled);481 $('body').toggleClass('hideChatAvatars', power_user.hideChatAvatars_enabled);
509 $('#hideChatAvatarsEnabled').prop('checked', power_user.hideChatAvatars_enabled);482 $('#hideChatAvatarsEnabled').prop('checked', power_user.hideChatAvatars_enabled);
510}483}
511484
512function switchMessageActions() {485function switchMessageActions() {
513 const value = localStorage.getItem(storage_keys.expand_message_actions);
514 power_user.expand_message_actions = value === null ? false : value == 'true';
515 $('body').toggleClass('expandMessageActions', power_user.expand_message_actions);486 $('body').toggleClass('expandMessageActions', power_user.expand_message_actions);
516 $('#expandMessageActions').prop('checked', power_user.expand_message_actions);487 $('#expandMessageActions').prop('checked', power_user.expand_message_actions);
517 $('.extraMesButtons, .extraMesButtonsHint').removeAttr('style');488 $('.extraMesButtons, .extraMesButtonsHint').removeAttr('style');
@@ -545,8 +516,6 @@ async function switchLabMode() {
545 }516 }
546 */517 */
547 await delay(100);518 await delay(100);
548 const value = localStorage.getItem(storage_keys.enableLabMode);
549 power_user.enableLabMode = value === null ? false : value == 'true';
550 $('body').toggleClass('enableLabMode', power_user.enableLabMode);519 $('body').toggleClass('enableLabMode', power_user.enableLabMode);
551 $('#enableLabMode').prop('checked', power_user.enableLabMode);520 $('#enableLabMode').prop('checked', power_user.enableLabMode);
552521
@@ -593,8 +562,6 @@ async function switchLabMode() {
593562
594async function switchZenSliders() {563async function switchZenSliders() {
595 await delay(100);564 await delay(100);
596 const value = localStorage.getItem(storage_keys.enableZenSliders);
597 power_user.enableZenSliders = value === null ? false : value == 'true';
598 $('body').toggleClass('enableZenSliders', power_user.enableZenSliders);565 $('body').toggleClass('enableZenSliders', power_user.enableZenSliders);
599 $('#enableZenSliders').prop('checked', power_user.enableZenSliders);566 $('#enableZenSliders').prop('checked', power_user.enableZenSliders);
600567
@@ -1015,8 +982,6 @@ function switchMovingUI() {
1015 $('.drawer-content.maximized').each(function () {982 $('.drawer-content.maximized').each(function () {
1016 $(this).find('.inline-drawer-maximize').trigger('click');983 $(this).find('.inline-drawer-maximize').trigger('click');
1017 });984 });
1018 const movingUI = localStorage.getItem(storage_keys.movingUI);
1019 power_user.movingUI = movingUI === null ? false : movingUI == 'true';
1020 $('body').toggleClass('movingUI', power_user.movingUI);985 $('body').toggleClass('movingUI', power_user.movingUI);
1021 if (power_user.movingUI === true) {986 if (power_user.movingUI === true) {
1022 initMovingUI();987 initMovingUI();
@@ -1083,8 +1048,6 @@ function applyChatDisplay() {
1083}1048}
10841049
1085function applyChatWidth(type) {1050function applyChatWidth(type) {
1086 power_user.chat_width = Number(localStorage.getItem(storage_keys.chat_width) ?? 50);
1087
1088 if (type === 'forced') {1051 if (type === 'forced') {
1089 let r = document.documentElement;1052 let r = document.documentElement;
1090 r.style.setProperty('--sheldWidth', `${power_user.chat_width}vw`);1053 r.style.setProperty('--sheldWidth', `${power_user.chat_width}vw`);
@@ -1161,12 +1124,9 @@ async function applyCustomCSS() {
1161}1124}
11621125
1163async function applyBlurStrength() {1126async function applyBlurStrength() {
1164 power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 1);
1165 document.documentElement.style.setProperty('--blurStrength', power_user.blur_strength);1127 document.documentElement.style.setProperty('--blurStrength', power_user.blur_strength);
1166 $('#blur_strength_counter').val(power_user.blur_strength);1128 $('#blur_strength_counter').val(power_user.blur_strength);
1167 $('#blur_strength').val(power_user.blur_strength);1129 $('#blur_strength').val(power_user.blur_strength);
1168
1169
1170}1130}
11711131
1172async function applyShadowWidth() {1132async function applyShadowWidth() {
@@ -1178,8 +1138,6 @@ async function applyShadowWidth() {
1178}1138}
11791139
1180async function applyFontScale(type) {1140async function applyFontScale(type) {
1181
1182 power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
1183 //this is to allow forced setting on page load, theme swap, etc1141 //this is to allow forced setting on page load, theme swap, etc
1184 if (type === 'forced') {1142 if (type === 'forced') {
1185 document.documentElement.style.setProperty('--fontScale', power_user.font_scale);1143 document.documentElement.style.setProperty('--fontScale', power_user.font_scale);
@@ -1215,7 +1173,6 @@ async function applyTheme(name) {
1215 {1173 {
1216 key: 'blur_strength',1174 key: 'blur_strength',
1217 action: async () => {1175 action: async () => {
1218 localStorage.setItem(storage_keys.blur_strength, power_user.blur_strength);
1219 await applyBlurStrength();1176 await applyBlurStrength();
1220 },1177 },
1221 },1178 },
@@ -1236,7 +1193,6 @@ async function applyTheme(name) {
1236 {1193 {
1237 key: 'font_scale',1194 key: 'font_scale',
1238 action: async () => {1195 action: async () => {
1239 localStorage.setItem(storage_keys.font_scale, power_user.font_scale);
1240 await applyFontScale('forced');1196 await applyFontScale('forced');
1241 },1197 },
1242 },1198 },
@@ -1279,22 +1235,19 @@ async function applyTheme(name) {
1279 if (!power_user.chat_width) {1235 if (!power_user.chat_width) {
1280 power_user.chat_width = 50;1236 power_user.chat_width = 50;
1281 }1237 }
12821238 saveSettingsDebounced();
1283 localStorage.setItem(storage_keys.chat_width, String(power_user.chat_width));
1284 applyChatWidth('forced');1239 applyChatWidth('forced');
1285 },1240 },
1286 },1241 },
1287 {1242 {
1288 key: 'timer_enabled',1243 key: 'timer_enabled',
1289 action: async () => {1244 action: async () => {
1290 localStorage.setItem(storage_keys.timer_enabled, Boolean(power_user.timer_enabled));
1291 switchTimer();1245 switchTimer();
1292 },1246 },
1293 },1247 },
1294 {1248 {
1295 key: 'timestamps_enabled',1249 key: 'timestamps_enabled',
1296 action: async () => {1250 action: async () => {
1297 localStorage.setItem(storage_keys.timestamps_enabled, Boolean(power_user.timestamps_enabled));
1298 switchTimestamps();1251 switchTimestamps();
1299 },1252 },
1300 },1253 },
@@ -1315,35 +1268,30 @@ async function applyTheme(name) {
1315 {1268 {
1316 key: 'mesIDDisplay_enabled',1269 key: 'mesIDDisplay_enabled',
1317 action: async () => {1270 action: async () => {
1318 localStorage.setItem(storage_keys.mesIDDisplay_enabled, Boolean(power_user.mesIDDisplay_enabled));
1319 switchMesIDDisplay();1271 switchMesIDDisplay();
1320 },1272 },
1321 },1273 },
1322 {1274 {
1323 key: 'hideChatAvatars_enabled',1275 key: 'hideChatAvatars_enabled',
1324 action: async () => {1276 action: async () => {
1325 localStorage.setItem(storage_keys.hideChatAvatars_enabled, Boolean(power_user.hideChatAvatars_enabled));
1326 switchHideChatAvatars();1277 switchHideChatAvatars();
1327 },1278 },
1328 },1279 },
1329 {1280 {
1330 key: 'expand_message_actions',1281 key: 'expand_message_actions',
1331 action: async () => {1282 action: async () => {
1332 localStorage.setItem(storage_keys.expand_message_actions, Boolean(power_user.expand_message_actions));
1333 switchMessageActions();1283 switchMessageActions();
1334 },1284 },
1335 },1285 },
1336 {1286 {
1337 key: 'enableZenSliders',1287 key: 'enableZenSliders',
1338 action: async () => {1288 action: async () => {
1339 localStorage.setItem(storage_keys.enableZenSliders, Boolean(power_user.enableZenSliders));
1340 switchMessageActions();1289 switchMessageActions();
1341 },1290 },
1342 },1291 },
1343 {1292 {
1344 key: 'enableLabMode',1293 key: 'enableLabMode',
1345 action: async () => {1294 action: async () => {
1346 localStorage.setItem(storage_keys.enableLabMode, Boolean(power_user.enableLabMode));
1347 switchMessageActions();1295 switchMessageActions();
1348 },1296 },
1349 },1297 },
@@ -1517,14 +1465,6 @@ async function loadPowerUserSettings(settings, data) {
1517 }1465 }
15181466
1519 // These are still local storage1467 // These are still local storage
1520 const movingUI = localStorage.getItem(storage_keys.movingUI);
1521 const timer = localStorage.getItem(storage_keys.timer_enabled);
1522 const timestamps = localStorage.getItem(storage_keys.timestamps_enabled);
1523 const mesIDDisplay = localStorage.getItem(storage_keys.mesIDDisplay_enabled);
1524 const hideChatAvatars = localStorage.getItem(storage_keys.hideChatAvatars_enabled);
1525 const expandMessageActions = localStorage.getItem(storage_keys.expand_message_actions);
1526 const enableZenSliders = localStorage.getItem(storage_keys.enableZenSliders);
1527 const enableLabMode = localStorage.getItem(storage_keys.enableLabMode);
1528 const autoLoadChat = localStorage.getItem(storage_keys.auto_load_chat_legacy);1468 const autoLoadChat = localStorage.getItem(storage_keys.auto_load_chat_legacy);
1529 const autoConnect = localStorage.getItem(storage_keys.auto_connect_legacy);1469 const autoConnect = localStorage.getItem(storage_keys.auto_connect_legacy);
15301470
@@ -1538,18 +1478,6 @@ async function loadPowerUserSettings(settings, data) {
1538 localStorage.removeItem(storage_keys.auto_connect_legacy);1478 localStorage.removeItem(storage_keys.auto_connect_legacy);
1539 }1479 }
15401480
1541 power_user.movingUI = movingUI === null ? false : movingUI == 'true';
1542 power_user.timer_enabled = timer === null ? true : timer == 'true';
1543 power_user.timestamps_enabled = timestamps === null ? true : timestamps == 'true';
1544 power_user.mesIDDisplay_enabled = mesIDDisplay === null ? true : mesIDDisplay == 'true';
1545 power_user.hideChatAvatars_enabled = hideChatAvatars === null ? true : hideChatAvatars == 'true';
1546 power_user.expand_message_actions = expandMessageActions === null ? true : expandMessageActions == 'true';
1547 power_user.enableZenSliders = enableZenSliders === null ? false : enableZenSliders == 'true';
1548 power_user.enableLabMode = enableLabMode === null ? false : enableLabMode == 'true';
1549 power_user.chat_width = Number(localStorage.getItem(storage_keys.chat_width) ?? 50);
1550 power_user.font_scale = Number(localStorage.getItem(storage_keys.font_scale) ?? 1);
1551 power_user.blur_strength = Number(localStorage.getItem(storage_keys.blur_strength) ?? 10);
1552
1553 if (power_user.chat_display === '') {1481 if (power_user.chat_display === '') {
1554 power_user.chat_display = chat_styles.DEFAULT;1482 power_user.chat_display = chat_styles.DEFAULT;
1555 }1483 }
@@ -1558,10 +1486,6 @@ async function loadPowerUserSettings(settings, data) {
1558 power_user.waifuMode = false;1486 power_user.waifuMode = false;
1559 }1487 }
15601488
1561 if (power_user.chat_width === '') {
1562 power_user.chat_width = 50;
1563 }
1564
1565 if (power_user.tokenizer === tokenizers.LEGACY) {1489 if (power_user.tokenizer === tokenizers.LEGACY) {
1566 power_user.tokenizer = tokenizers.GPT2;1490 power_user.tokenizer = tokenizers.GPT2;
1567 }1491 }
@@ -3297,7 +3221,6 @@ $(document).ready(() => {
32973221
3298 $('#movingUImode').change(function () {3222 $('#movingUImode').change(function () {
3299 power_user.movingUI = $(this).prop('checked');3223 power_user.movingUI = $(this).prop('checked');
3300 localStorage.setItem(storage_keys.movingUI, power_user.movingUI);
3301 switchMovingUI();3224 switchMovingUI();
3302 saveSettingsDebounced();3225 saveSettingsDebounced();
3303 });3226 });
@@ -3329,8 +3252,8 @@ $(document).ready(() => {
3329 $('#chat_width_slider').on('input', function (e, data) {3252 $('#chat_width_slider').on('input', function (e, data) {
3330 const applyMode = data?.forced ? 'forced' : 'normal';3253 const applyMode = data?.forced ? 'forced' : 'normal';
3331 power_user.chat_width = Number(e.target.value);3254 power_user.chat_width = Number(e.target.value);
3332 localStorage.setItem(storage_keys.chat_width, power_user.chat_width);
3333 applyChatWidth(applyMode);3255 applyChatWidth(applyMode);
3256 saveSettingsDebounced();
3334 setHotswapsDebounced();3257 setHotswapsDebounced();
3335 });3258 });
33363259
@@ -3360,7 +3283,6 @@ $(document).ready(() => {
3360 const applyMode = data?.forced ? 'forced' : 'normal';3283 const applyMode = data?.forced ? 'forced' : 'normal';
3361 power_user.font_scale = Number(e.target.value);3284 power_user.font_scale = Number(e.target.value);
3362 $('#font_scale_counter').val(power_user.font_scale);3285 $('#font_scale_counter').val(power_user.font_scale);
3363 localStorage.setItem(storage_keys.font_scale, power_user.font_scale);
3364 await applyFontScale(applyMode);3286 await applyFontScale(applyMode);
3365 saveSettingsDebounced();3287 saveSettingsDebounced();
3366 });3288 });
@@ -3368,7 +3290,6 @@ $(document).ready(() => {
3368 $('input[name="blur_strength"]').on('input', async function (e) {3290 $('input[name="blur_strength"]').on('input', async function (e) {
3369 power_user.blur_strength = Number(e.target.value);3291 power_user.blur_strength = Number(e.target.value);
3370 $('#blur_strength_counter').val(power_user.blur_strength);3292 $('#blur_strength_counter').val(power_user.blur_strength);
3371 localStorage.setItem(storage_keys.blur_strength, power_user.blur_strength);
3372 await applyBlurStrength();3293 await applyBlurStrength();
3373 saveSettingsDebounced();3294 saveSettingsDebounced();
3374 });3295 });
@@ -3617,14 +3538,14 @@ $(document).ready(() => {
3617 $('#messageTimerEnabled').on('input', function () {3538 $('#messageTimerEnabled').on('input', function () {
3618 const value = !!$(this).prop('checked');3539 const value = !!$(this).prop('checked');
3619 power_user.timer_enabled = value;3540 power_user.timer_enabled = value;
3620 localStorage.setItem(storage_keys.timer_enabled, Boolean(power_user.timer_enabled));3541 saveSettingsDebounced();
3621 switchTimer();3542 switchTimer();
3622 });3543 });
36233544
3624 $('#messageTimestampsEnabled').on('input', function () {3545 $('#messageTimestampsEnabled').on('input', function () {
3625 const value = !!$(this).prop('checked');3546 const value = !!$(this).prop('checked');
3626 power_user.timestamps_enabled = value;3547 power_user.timestamps_enabled = value;
3627 localStorage.setItem(storage_keys.timestamps_enabled, Boolean(power_user.timestamps_enabled));3548 saveSettingsDebounced();
3628 switchTimestamps();3549 switchTimestamps();
3629 });3550 });
36303551
@@ -3632,6 +3553,7 @@ $(document).ready(() => {
3632 const value = !!$(this).prop('checked');3553 const value = !!$(this).prop('checked');
3633 power_user.timestamp_model_icon = value;3554 power_user.timestamp_model_icon = value;
3634 localStorage.setItem(storage_keys.timestamp_model_icon, Boolean(power_user.timestamp_model_icon));3555 localStorage.setItem(storage_keys.timestamp_model_icon, Boolean(power_user.timestamp_model_icon));
3556 saveSettingsDebounced();
3635 switchIcons();3557 switchIcons();
3636 });3558 });
36373559
@@ -3645,7 +3567,7 @@ $(document).ready(() => {
3645 $('#expandMessageActions').on('input', function () {3567 $('#expandMessageActions').on('input', function () {
3646 const value = !!$(this).prop('checked');3568 const value = !!$(this).prop('checked');
3647 power_user.expand_message_actions = value;3569 power_user.expand_message_actions = value;
3648 localStorage.setItem(storage_keys.expand_message_actions, Boolean(power_user.expand_message_actions));3570 saveSettingsDebounced();
3649 switchMessageActions();3571 switchMessageActions();
3650 });3572 });
36513573
@@ -3658,7 +3580,6 @@ $(document).ready(() => {
3658 return;3580 return;
3659 }3581 }
3660 power_user.enableZenSliders = value;3582 power_user.enableZenSliders = value;
3661 localStorage.setItem(storage_keys.enableZenSliders, Boolean(power_user.enableZenSliders));
3662 saveSettingsDebounced();3583 saveSettingsDebounced();
3663 switchZenSliders();3584 switchZenSliders();
3664 });3585 });
@@ -3673,7 +3594,6 @@ $(document).ready(() => {
3673 }3594 }
36743595
3675 power_user.enableLabMode = value;3596 power_user.enableLabMode = value;
3676 localStorage.setItem(storage_keys.enableLabMode, Boolean(power_user.enableLabMode));
3677 saveSettingsDebounced();3597 saveSettingsDebounced();
3678 switchLabMode();3598 switchLabMode();
3679 });3599 });
@@ -3681,14 +3601,14 @@ $(document).ready(() => {
3681 $('#mesIDDisplayEnabled').on('input', function () {3601 $('#mesIDDisplayEnabled').on('input', function () {
3682 const value = !!$(this).prop('checked');3602 const value = !!$(this).prop('checked');
3683 power_user.mesIDDisplay_enabled = value;3603 power_user.mesIDDisplay_enabled = value;
3684 localStorage.setItem(storage_keys.mesIDDisplay_enabled, Boolean(power_user.mesIDDisplay_enabled));3604 saveSettingsDebounced();
3685 switchMesIDDisplay();3605 switchMesIDDisplay();
3686 });3606 });
36873607
3688 $('#hideChatAvatarsEnabled').on('input', function () {3608 $('#hideChatAvatarsEnabled').on('input', function () {
3689 const value = !!$(this).prop('checked');3609 const value = !!$(this).prop('checked');
3690 power_user.hideChatAvatars_enabled = value;3610 power_user.hideChatAvatars_enabled = value;
3691 localStorage.setItem(storage_keys.hideChatAvatars_enabled, Boolean(power_user.hideChatAvatars_enabled));3611 saveSettingsDebounced();
3692 switchHideChatAvatars();3612 switchHideChatAvatars();
3693 });3613 });
36943614