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
4242import { Popup } from './popup.js';
4343import { accountStorage } from './util/AccountStorage.js';
44+import { getCurrentUserHandle } from './user.js';
4445
4546var RPanelPin = document.getElementById('rm_button_panel_pin');
4647var LPanelPin = document.getElementById('lm_button_panel_pin');
@@ -428,13 +429,15 @@ function OpenNavPanels() {
428429 }
429430}
430431
432+const getUserInputKey = () => getCurrentUserHandle() + '_userInput';
433+
431434function restoreUserInput() {
432435 if (!power_user.restore_user_input) {
433436 console.debug('restoreUserInput disabled');
434437 return;
435438 }
436439
437440 const userInput = localStorage.getItem('userInput'getUserInputKey());
438441 if (userInput) {
439442 $('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true }));
440443 }
@@ -442,7 +445,7 @@ function restoreUserInput() {
442445
443446function saveUserInput() {
444447 const userInput = String($('#send_textarea').val());
445448 localStorage.setItem('userInput'getUserInputKey(), userInput);
446449 console.debug('User Input -- ', userInput);
447450}
448451const saveUserInputDebounced = debounce(saveUserInput);
public/scripts/user.js+8 -0
@@ -44,6 +44,14 @@ export function isAdmin() {
4444}
4545
4646/**
47+ * Gets the handle string of the current user.
48+ * @returns {string} User handle
49+ */
50+export function getCurrentUserHandle() {
51+ return currentUser?.handle || 'default-user';
52+}
53+
54+/**
4755 * Get the current user.
4856 * @returns {Promise<void>}
4957 */