From 340c03cedf5f113621d2df110a1eabcb151f78c1 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:21:13 +0200 Subject: [PATCH] Make user input saving account-specific --- public/scripts/RossAscends-mods.js | 7 +++++-- public/scripts/user.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/public/scripts/RossAscends-mods.js b/public/scripts/RossAscends-mods.js index c2a5e2774..236955596 100644 --- a/public/scripts/RossAscends-mods.js +++ b/public/scripts/RossAscends-mods.js @@ -41,6 +41,7 @@ import { debounce_timeout } from './constants.js'; import { Popup } from './popup.js'; import { accountStorage } from './util/AccountStorage.js'; +import { getCurrentUserHandle } from './user.js'; var RPanelPin = document.getElementById('rm_button_panel_pin'); var LPanelPin = document.getElementById('lm_button_panel_pin'); @@ -428,13 +429,15 @@ function OpenNavPanels() { } } +const getUserInputKey = () => getCurrentUserHandle() + '_userInput'; + function restoreUserInput() { if (!power_user.restore_user_input) { console.debug('restoreUserInput disabled'); return; } - const userInput = localStorage.getItem('userInput'); + const userInput = localStorage.getItem(getUserInputKey()); if (userInput) { $('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true })); } @@ -442,7 +445,7 @@ function restoreUserInput() { function saveUserInput() { const userInput = String($('#send_textarea').val()); - localStorage.setItem('userInput', userInput); + localStorage.setItem(getUserInputKey(), userInput); console.debug('User Input -- ', userInput); } const saveUserInputDebounced = debounce(saveUserInput); diff --git a/public/scripts/user.js b/public/scripts/user.js index 5db961019..4aa61967b 100644 --- a/public/scripts/user.js +++ b/public/scripts/user.js @@ -43,6 +43,14 @@ export function isAdmin() { return Boolean(currentUser.admin); } +/** + * Gets the handle string of the current user. + * @returns {string} User handle + */ +export function getCurrentUserHandle() { + return currentUser?.handle || 'default-user'; +} + /** * Get the current user. * @returns {Promise}