From 7e116f8b1fa48cc48d5f6f6d35b507f0f9c46d2f Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sat, 21 Oct 2023 20:55:51 +0300 Subject: [PATCH] Move setting search to built-in functionality --- public/css/st-tailwind.css | 6 +++ public/index.html | 1 + .../extensions/settingsearch/manifest.json | 11 ----- .../extensions/settingsearch/style.css | 5 -- .../index.js => setting-search.js} | 47 +++++++++---------- 5 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 public/scripts/extensions/settingsearch/manifest.json delete mode 100644 public/scripts/extensions/settingsearch/style.css rename public/scripts/{extensions/settingsearch/index.js => setting-search.js} (63%) diff --git a/public/css/st-tailwind.css b/public/css/st-tailwind.css index 37dc2f27d..dca40662a 100644 --- a/public/css/st-tailwind.css +++ b/public/css/st-tailwind.css @@ -6,6 +6,12 @@ color: var(--fullred); } +.highlighted { + color: black; + background-color: yellow; + text-shadow: none !important; +} + .m-t-0 { margin-top: 0; } diff --git a/public/index.html b/public/index.html index 4b08cce31..2bcb304fd 100644 --- a/public/index.html +++ b/public/index.html @@ -86,6 +86,7 @@ + SillyTavern diff --git a/public/scripts/extensions/settingsearch/manifest.json b/public/scripts/extensions/settingsearch/manifest.json deleted file mode 100644 index fd743c535..000000000 --- a/public/scripts/extensions/settingsearch/manifest.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "display_name": "Settings Search", - "loading_order": 15, - "requires": [], - "optional": [], - "js": "index.js", - "css": "style.css", - "author": "RossAscends", - "version": "1.0.0", - "homePage": "https://github.com/SillyTavern/SillyTavern" -} \ No newline at end of file diff --git a/public/scripts/extensions/settingsearch/style.css b/public/scripts/extensions/settingsearch/style.css deleted file mode 100644 index 100ed2a7c..000000000 --- a/public/scripts/extensions/settingsearch/style.css +++ /dev/null @@ -1,5 +0,0 @@ -.highlighted { - color: black; - background-color: yellow; - text-shadow: none !important; -} \ No newline at end of file diff --git a/public/scripts/extensions/settingsearch/index.js b/public/scripts/setting-search.js similarity index 63% rename from public/scripts/extensions/settingsearch/index.js rename to public/scripts/setting-search.js index fcf916bf3..50d5f2a0e 100644 --- a/public/scripts/extensions/settingsearch/index.js +++ b/public/scripts/setting-search.js @@ -1,29 +1,29 @@ -export { MODULE_NAME }; - -const MODULE_NAME = 'settingsSearch'; -async function addSettingsSearchHTML() { - - const html = ` -
-
- -
-
` - - $("#user-settings-block").prepend(html); -} - +/** + * Search for settings that match the search string and highlight them. + */ async function searchSettings() { removeHighlighting(); // Remove previous highlights - let searchString = $("#settingsSearch").val(); - let searchableText = $("#user-settings-block-content"); // Get the HTML block + const searchString = String($("#settingsSearch").val()); + const searchableText = $("#user-settings-block-content"); // Get the HTML block if (searchString.trim() !== "") { highlightMatchingElements(searchableText[0], searchString); // Highlight matching elements } } + +/** + * Check if the element is a child of a header element + * @param {HTMLElement | Text | Document | Comment} element Settings block HTML element + * @returns {boolean} True if the element is a child of a header element, false otherwise + */ function isParentHeader(element) { return $(element).closest('h4, h3').length > 0; } + +/** + * Recursively highlight elements that match the search string + * @param {HTMLElement | Text | Document | Comment} element Settings block HTML element + * @param {string} searchString Search string + */ function highlightMatchingElements(element, searchString) { $(element).contents().each(function () { const isTextNode = this.nodeType === Node.TEXT_NODE; @@ -41,17 +41,14 @@ function highlightMatchingElements(element, searchString) { } }); } + +/** + * Remove highlighting from previously highlighted elements. + */ function removeHighlighting() { $(".highlighted").removeClass("highlighted"); // Remove CSS class from previously highlighted elements } + jQuery(() => { - //addSettingsSearchHTML(); $('#settingsSearch').on('input change', searchSettings); }); - - - - - - -