forked from React-Group/interstellar_ai
Compare commits
No commits in common. "15d852c11d598c6af8cf6b84f93c63592383d511" and "0aa7116fd3d9681e2e82ece23bdb8ca6b020403d" have entirely different histories.
15d852c11d
...
0aa7116fd3
1 changed files with 23 additions and 22 deletions
|
@ -2,34 +2,35 @@
|
||||||
|
|
||||||
// Method to export localStorage to a JSON object
|
// Method to export localStorage to a JSON object
|
||||||
export function exportSettings(): string {
|
export function exportSettings(): string {
|
||||||
const settings: { [key: string]: any } = {};
|
const settings: { [key: string]: any } = {};
|
||||||
|
|
||||||
// Loop through all keys in localStorage and add them to the settings object
|
// Loop through all keys in localStorage and add them to the settings object
|
||||||
for (let i = 0; i < localStorage.length; i++) {
|
for (let i = 0; i < localStorage.length; i++) {
|
||||||
const key = localStorage.key(i);
|
const key = localStorage.key(i);
|
||||||
if (key) {
|
if (key) {
|
||||||
if (key !== "accountName" && key !== "accountPassword" && key !== "accountEmail") {
|
settings[key] = localStorage.getItem(key);
|
||||||
settings[key] = localStorage.getItem(key);
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Convert settings object to JSON string
|
// Convert settings object to JSON string
|
||||||
return JSON.stringify(settings, null, 2);
|
return JSON.stringify(settings, null, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Method to import settings from a JSON object, clearing old localStorage
|
// Method to import settings from a JSON object, clearing old localStorage
|
||||||
export function importSettings(jsonData: string): void {
|
export function importSettings(jsonData: string): void {
|
||||||
try {
|
try {
|
||||||
const parsedSettings = JSON.parse(jsonData);
|
const parsedSettings = JSON.parse(jsonData);
|
||||||
|
|
||||||
// Loop through parsed settings and save them in localStorage
|
// Clear the current localStorage
|
||||||
Object.keys(parsedSettings).forEach((key) => {
|
localStorage.clear();
|
||||||
localStorage.setItem(key, parsedSettings[key]);
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log("Settings imported successfully!");
|
// Loop through parsed settings and save them in localStorage
|
||||||
} catch (error) {
|
Object.keys(parsedSettings).forEach((key) => {
|
||||||
console.error("Invalid JSON data:", error);
|
localStorage.setItem(key, parsedSettings[key]);
|
||||||
}
|
});
|
||||||
|
|
||||||
|
console.log("Settings imported successfully!");
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Invalid JSON data:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue