123456789101112131415161718192021222324252627282930 |
- setup.editorSave = (passage,newContent) => {
- const escapedChars = {
- '&' : '&',
- '<' : '<',
- '>' : '>',
- '"' : '"',
- "'" : ''',
- '`' : '`'
- };
- let sanitizedNewContent = newContent;
- for(const [toBeEscaped, asEscaped] of Object.entries(escapedChars))
- sanitizedNewContent = sanitizedNewContent.replaceAll(toBeEscaped,asEscaped);
- const localStorageModsKey = "SweetCube.Modifications";
- const updateObject = {};
- updateObject[passage] = sanitizedNewContent;
- const currentModificationsString = localStorage.getItem(localStorageModsKey) ?? "{}";
- const currentModifications = JSON.parse(currentModificationsString);
- const newModifications = Object.assign({},currentModifications,updateObject);
- const newModificationsString = JSON.stringify(newModifications);
- localStorage.setItem(localStorageModsKey, newModificationsString);
- location.reload();
- }
|