let useLocalStorage = true; // Save settings to local storage. Suppressed if "use local storage" is false. function saveSettings() { if (useLocalStorage) { // Find all storeable UI elements, store a key of "element id:property name" mapped to the value of that // property. For a checkbox, that's the "checked" property. $(".storeable-checkbox").each(function() { localStorage.setItem("#" + $(this)[0].id + ":checked", JSON.stringify($(this)[0].checked)); }); $(".storeable-select").each(function() { localStorage.setItem("#" + $(this)[0].id + ":value", JSON.stringify($(this)[0].value)); }); $(".storeable-text").each(function() { localStorage.setItem("#" + $(this)[0].id + ":value", JSON.stringify($(this)[0].value)); }); } } // Load settings from local storage and set up the filter selectors. Suppressed if "use local storage" is false. function loadSettings() { if (useLocalStorage) { // Find all local storage entries and push their data to the corresponding UI element Object.keys(localStorage).forEach(function(key) { if (key.startsWith("#") && key.includes(":")) { // Split the key back into an element ID and a property var split = key.split(":"); $(split[0]).prop(split[1], JSON.parse(localStorage.getItem(key))); } }); } }