0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-28 02:42:39 +00:00

Change JSON file to JS getter function

This commit is contained in:
G.Ambatte
2025-09-11 21:02:56 +12:00
parent 2663d86627
commit a11fa72261
3 changed files with 39 additions and 37 deletions

View File

@@ -1,29 +1,19 @@
import localStorageKeyMap from './localStorageKeyMap.json' with { type: 'json' };
const addDynamicKeys = function(keyObject){
if(global?.account?.username){
const username = global.account.username;
keyObject[`HOMEBREWERY-DEFAULT-SAVE-LOCATION-${username}`] = `HB_editor_defaultSave_${username}`;
}
return keyObject;
};
import getLocalStorageMap from './localStorageKeyMap.js';
const updateLocalStorage = function(){
// Return if no window and thus no local storage
if(typeof window === 'undefined') return;
// Return if the local storage key map has no content
const localStorageKeyMap = getLocalStorageMap();
if(Object.keys(localStorageKeyMap).length == 0) return;
const storage = window.localStorage;
const storageKeyMap = addDynamicKeys(localStorageKeyMap);
Object.keys(storageKeyMap).forEach((key)=>{
Object.keys(localStorageKeyMap).forEach((key)=>{
if(storage[key]){
const data = storage.getItem(key);
if(!storage[storageKeyMap[key]]) storage.setItem(storageKeyMap[key], data);
if(!storage[localStorageKeyMap[key]]) storage.setItem(localStorageKeyMap[key], data);
// storage.removeItem(key);
}
});