Yes; you can just use localStorage
. (Or the file system if you need access to the actual preferences file.)
For example:
function getPreferredFontSize() {
const savedPreference = localStorage.getItem("preferred-font-size");
return (savedPreference === undefined) ? 10 : Number(savedPreference);
}
function setPreferredFontSize(size) {
localStorage.setItem("preferred-font-size", size.toString());
}
Then, whenever your panel is shown, you can read the preferences and then save them out when they are modified.
If you’re going to have a lot of preferences, it may make more sense to have a preference object and then serialize that to local storage with JSON.stringify
(and you can reload that with JSON.parse
) so that you aren’t saving a lot of small keys (loading one large object is faster than, say, 500 small ones) and avoiding a lot of repetitive boilerplate. But for a few checkboxes, the above method works just fine.