From 72cb095dec42c49949f0aa5e3bbcd6a66228efe1 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 20 May 2024 23:26:56 +0200 Subject: [PATCH] Finished config - Added clearer logic - Added clearer UI --- src/index.html | 4 +- src/views/cleaner/cleaner.css | 3 ++ src/views/cleaner/cleaner.html | 74 ++++++++++++++++++--------- src/views/cleaner/cleaner.js | 92 ++++++++++++++++++++++++++-------- src/views/config/config.html | 3 +- src/views/config/config.js | 38 ++++++++++---- 6 files changed, 157 insertions(+), 57 deletions(-) diff --git a/src/index.html b/src/index.html index d2139b7..3621578 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,5 @@ - + Cooperate Cleaner @@ -14,7 +14,7 @@ -
+
+
+ Loading... +
+ + - - - - \ No newline at end of file + diff --git a/src/views/cleaner/cleaner.js b/src/views/cleaner/cleaner.js index 37ca850..6051237 100644 --- a/src/views/cleaner/cleaner.js +++ b/src/views/cleaner/cleaner.js @@ -1,23 +1,75 @@ -$(document).ready(function() { - console.log("Initialization of cleaner.js finished."); - init(); -}); +(function() { + let config; -function init() { - $(document).keydown(function(event) { - if (event.altKey) { - if (event.keyCode === 13) { - event.preventDefault(); - clean(); + $(document).ready(function() { + console.log("Initialization of cleaner.js finished."); + config = JSON.parse(window.localStorage.getItem("config")); + console.log(config); + init(); + }); + + function init() { + $(document).keydown(function(event) { + if (event.altKey) { + if (event.keyCode === 13) { + event.preventDefault(); + clean(); + } } - } - }); - $("#cleaner-clean-btn").click(function() { - console.log("Clean button clicked"); - clean(); - }); -} + }); + $("#cleaner-clean-btn").click(function() { + console.log("Clean button clicked"); + clean(); + }); -function clean() { - console.log("Cleaning...") -} \ No newline at end of file + initQuickSettings(); + } + + function initQuickSettings() { + const filterList = $("#filter-list"); + filterList.empty(); // Clear any existing list items + + config.rules.forEach(rule => { + const listItem = $(` +
  • +
    + + +
    +
  • + `); + filterList.append(listItem); + }); + + $(".form-check-input").change(function() { + const rule = config.rules.find(r => r.strToReplace === $(this).attr("id")); + if (rule) { + rule.enabled = $(this).is(":checked"); + //window.localStorage.setItem("config", JSON.stringify(config)); + } + }); + } + + function clean() { + console.log("Cleaning..."); + + // Read the input from the textarea + let outputText = $("#input-textarea").val(); + + // Process each rule + config.rules.forEach(rule => { + if (rule.enabled) { + const searchValue = rule.ignoreCase ? new RegExp(rule.strToReplace, 'gi') : new RegExp(rule.strToReplace, 'g'); + outputText = outputText.replace(searchValue, rule.replaceStr); + } + }); + + // Output the processed text to the output textarea + $("#output-textarea").val(outputText); + + // Display the output container + $("#output-container-div").removeClass("visually-hidden"); + } +})(); \ No newline at end of file diff --git a/src/views/config/config.html b/src/views/config/config.html index 7301c16..7cac645 100644 --- a/src/views/config/config.html +++ b/src/views/config/config.html @@ -36,7 +36,8 @@ # String to Replace Replace With - Enabled by default + Filter enabled + Ignore case Action diff --git a/src/views/config/config.js b/src/views/config/config.js index 8be2429..789923a 100644 --- a/src/views/config/config.js +++ b/src/views/config/config.js @@ -1,10 +1,18 @@ var ruleRowTemplate = '' + - '

    [INDEX]

    ' + + '

    [INDEX]

    ' + ' ' + ' ' + ' ' + ' ' + + ' ' + + ' ' + + '