var options = JSON.parse(localStorage.getItem('options')); if (options == null) options = {}; var defaultOptions = {}; function setOption(key, value) { options[key] = value; if (isLoggedIn) { authConnection.send(JSON.stringify({type:'3', options: JSON.stringify(options)})); } else { localStorage.setItem('options', JSON.stringify(options)); } } function getOption(key) { return key in options ? options[key] : defaultOptions[key]; } function createOption(properties) { defaultOptions[properties.id] = properties.default; var categoryID = "option_category_" + properties.category.toLowerCase().replace(/ /g,"_"); if (!$("#" + categoryID).length) { $("#optionsMenu").append("

" + properties.category + "

"); } var container = $("#" + categoryID); if (properties.type == 'range') { container.append("

"); $("#" + properties.id).val(getOption(properties.id)); $("#" + properties.id).on("input", function() { setOption(properties.id, $(this).val()); if (properties.callback != null) properties.callback($(this).val()); }); } else if (properties.type == 'checkbox') { container.append("

"); $("#" + properties.id).prop("checked", getOption(properties.id)); $("#" + properties.id).change(function() { setOption(properties.id, $(this).is(":checked")); if (properties.callback != null) properties.callback($(this).is(":checked")); }); } }