import export works again || animation is weird
This commit is contained in:
parent
f94b99d357
commit
0a9472f44f
4 changed files with 153 additions and 125 deletions
|
@ -1,23 +1,36 @@
|
|||
// settingsUtils.ts
|
||||
// settingsManager.ts
|
||||
|
||||
// Export the current settings as a JSON file
|
||||
export const exportSettings = (settings: any) => {
|
||||
const blob = new Blob([JSON.stringify(settings)], { type: 'application/json' });
|
||||
const link = document.createElement('a');
|
||||
link.href = URL.createObjectURL(blob);
|
||||
link.download = 'settings.json';
|
||||
link.click();
|
||||
};
|
||||
|
||||
// Import settings from a JSON file
|
||||
export const importSettings = (file: File, applySettings: (settings: any) => void) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
const content = e.target?.result as string;
|
||||
const importedSettings = JSON.parse(content);
|
||||
applySettings(importedSettings);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
};
|
||||
// Method to export localStorage to a JSON object
|
||||
export function exportSettings(): string {
|
||||
const settings: { [key: string]: any } = {};
|
||||
|
||||
|
||||
// Loop through all keys in localStorage and add them to the settings object
|
||||
for (let i = 0; i < localStorage.length; i++) {
|
||||
const key = localStorage.key(i);
|
||||
if (key) {
|
||||
settings[key] = localStorage.getItem(key);
|
||||
}
|
||||
}
|
||||
|
||||
// Convert settings object to JSON string
|
||||
return JSON.stringify(settings, null, 2);
|
||||
}
|
||||
|
||||
// Method to import settings from a JSON object, clearing old localStorage
|
||||
export function importSettings(jsonData: string): void {
|
||||
try {
|
||||
const parsedSettings = JSON.parse(jsonData);
|
||||
|
||||
// Clear the current localStorage
|
||||
localStorage.clear();
|
||||
|
||||
// Loop through parsed settings and save them in localStorage
|
||||
Object.keys(parsedSettings).forEach((key) => {
|
||||
localStorage.setItem(key, parsedSettings[key]);
|
||||
});
|
||||
|
||||
console.log("Settings imported successfully!");
|
||||
} catch (error) {
|
||||
console.error("Invalid JSON data:", error);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue