diff --git a/src/lib/toggle.css b/src/lib/toggle.css index 69b27a5..138db8d 100644 --- a/src/lib/toggle.css +++ b/src/lib/toggle.css @@ -48,17 +48,17 @@ .toggle-switch input[type="checkbox"]:checked + .toggle-switch-handle { transform: translateX(45px); - box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), 0 0 0 3px #05c46b; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2), 0 0 0 3px #198754; } .toggle-switch input[type="checkbox"]:checked + .toggle-switch-background { - background-color: #05c46b; - box-shadow: inset 0 0 0 2px #04b360; + background-color: #198754; + box-shadow: inset 0 0 0 2px #198754; } .toggle-switch input[type="checkbox"]:checked + .toggle-switch:before { content: "On"; - color: #05c46b; + color: #198754; right: -15px; } diff --git a/src/views/config/config.html b/src/views/config/config.html index 9228be2..7301c16 100644 --- a/src/views/config/config.html +++ b/src/views/config/config.html @@ -1,5 +1,9 @@
- +
@@ -7,8 +11,8 @@

Create and manage filtering rules

-
- +
@@ -31,30 +41,26 @@ - - - - - - - - - +

1

- - - -
+
+
+
+ Saving config... +
+

Saving...

+
+ +
+ +
\ No newline at end of file diff --git a/src/views/config/config.js b/src/views/config/config.js index 50b0b62..8be2429 100644 --- a/src/views/config/config.js +++ b/src/views/config/config.js @@ -19,28 +19,89 @@ var ruleRowTemplate = '' + ' ' + ' ' + ' '; +var configJson = {}; $("document").ready(function() { + loadConfig(); + $("#add-rule-btn").click(function() { appendRow(generateRowTemplate("", "", true)); }); + + $(document).on("click", ".rule-trash-btn", function() { + $(this).closest("tr").remove(); + updateRowIndexes(); + buildAndSaveConfig(); + }); + bindChangeEvents(); }); function appendRow(rowTemplate) { - $(".table").append(rowTemplate); - $(".rule-trash-btn").click(function() { - $(this).closest("tr").remove(); - }); + $(".table tbody").append(rowTemplate); + bindChangeEvents(); + updateRowIndexes(); } - function generateRowTemplate(str, outputStr, enabled) { var row = ruleRowTemplate; - row = row.replaceAll("[INDEX]", $(".table tr").length); + row = row.replaceAll("[INDEX]", $(".table tbody tr").length + 1); row = row.replace("[STR-TO-REPLACE]", str); row = row.replace("[REPLACE-STR]", outputStr); if (!enabled) { row = row.replace("checked", ""); } return row; +} + +function updateRowIndexes() { + $(".table tbody tr").each(function(index) { + $(this).attr("id", "rule-" + (index + 1)); + $(this).find("td:first p").text(index + 1); + }); +} + +function buildAndSaveConfig() { + // Show saving status + $("#saving-status").show(); + $("#saved-status").hide(); + + var rules = []; + $(".table tbody tr").each(function(index) { + var rule = {}; + rule["strToReplace"] = $(this).find(".rule-input-str-input").val(); + rule["replaceStr"] = $(this).find(".rule-output-str-input").val(); + rule["enabledByDefault"] = $(this).find(".rule-enabled-by-default-toggle").is(":checked"); + rules.push(rule); + }); + configJson["rules"] = rules; + console.log(configJson); + window.localStorage.setItem("config", JSON.stringify(configJson)); + + // Simulate a delay for saving process + setTimeout(function() { + $("#saving-status").hide(); + $("#saved-status").show(); + }, 200); +} + +function loadConfig() { + var config = window.localStorage.getItem("config"); + if (config) { + configJson = JSON.parse(config); + configJson["rules"].forEach(function(rule) { + appendRow(generateRowTemplate(rule["strToReplace"], rule["replaceStr"], rule["enabledByDefault"])); + }); + } + $("#saving-status").hide(); + $("#saved-status").show(); + bindChangeEvents(); +} + +function bindChangeEvents() { + $(".rule-input-str-input, .rule-output-str-input").off("input").on("input", function() { + buildAndSaveConfig(); + }); + $(".rule-enabled-by-default-toggle").off("change").on("change", function() { + buildAndSaveConfig(); + }); } \ No newline at end of file