Make user input saving account-specific

340c03cedf5f113621d2df110a1eabcb151f78c1

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

2 files changed, +13 -2Showing whitespace changes
public/scripts/RossAscends-mods.js+5 -2
@@ -41,6 +41,7 @@ import { debounce_timeout } from './constants.js';
4141
42import { Popup } from './popup.js';42import { Popup } from './popup.js';
43import { accountStorage } from './util/AccountStorage.js';43import { accountStorage } from './util/AccountStorage.js';
44import { getCurrentUserHandle } from './user.js';
4445
45var RPanelPin = document.getElementById('rm_button_panel_pin');46var RPanelPin = document.getElementById('rm_button_panel_pin');
46var LPanelPin = document.getElementById('lm_button_panel_pin');47var LPanelPin = document.getElementById('lm_button_panel_pin');
@@ -428,13 +429,15 @@ function OpenNavPanels() {
428 }429 }
429}430}
430431
432const getUserInputKey = () => getCurrentUserHandle() + '_userInput';
433
431function restoreUserInput() {434function restoreUserInput() {
432 if (!power_user.restore_user_input) {435 if (!power_user.restore_user_input) {
433 console.debug('restoreUserInput disabled');436 console.debug('restoreUserInput disabled');
434 return;437 return;
435 }438 }
436439
437 const userInput = localStorage.getItem('userInput');440 const userInput = localStorage.getItem(getUserInputKey());
438 if (userInput) {441 if (userInput) {
439 $('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true }));442 $('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true }));
440 }443 }
@@ -442,7 +445,7 @@ function restoreUserInput() {
442445
443function saveUserInput() {446function saveUserInput() {
444 const userInput = String($('#send_textarea').val());447 const userInput = String($('#send_textarea').val());
445 localStorage.setItem('userInput', userInput);448 localStorage.setItem(getUserInputKey(), userInput);
446 console.debug('User Input -- ', userInput);449 console.debug('User Input -- ', userInput);
447}450}
448const saveUserInputDebounced = debounce(saveUserInput);451const saveUserInputDebounced = debounce(saveUserInput);
public/scripts/user.js+8 -0
@@ -44,6 +44,14 @@ export function isAdmin() {
44}44}
4545
46/**46/**
47 * Gets the handle string of the current user.
48 * @returns {string} User handle
49 */
50export function getCurrentUserHandle() {
51 return currentUser?.handle || 'default-user';
52}
53
54/**
47 * Get the current user.55 * Get the current user.
48 * @returns {Promise<void>}56 * @returns {Promise<void>}
49 */57 */